bfbc95d866652e82eb01d746605b6d4208312f12
[platform/upstream/mic.git] / mic / kickstart / custom_commands / micrepo.py
1 #
2 # Copyright (c) 2008, 2009, 2010 Intel, Inc.
3 #
4 # Yi Yang <yi.y.yang@intel.com>
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the Free
8 # Software Foundation; version 2 of the License
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 # for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc., 59
17 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 from pykickstart.commands.repo import F14_RepoData, F14_Repo
20
21
22 class Mic_RepoData(F14_RepoData):
23     "Mic customized repo data"
24
25     def __init__(self, *args, **kw):
26         F14_RepoData.__init__(self, *args, **kw)
27         for field in ('save', 'proxyuser', 'proxypasswd', 'debuginfo',
28                       'disable', 'source', 'gpgkey', 'ssl_verify', 'priority',
29                       'nocache', 'user', 'passwd'):
30             setattr(self, field, kw.get(field))
31
32         if hasattr(self, 'proxy') and not self.proxy:
33             # TODO: remove this code, since it only for back-compatible.
34             # Some code behind only accept None but not empty string
35             # for default proxy
36             self.proxy = None
37
38     def _getArgsAsStr(self):
39         retval = F14_RepoData._getArgsAsStr(self)
40
41         for field in ('proxyuser', 'proxypasswd', 'user', 'passwd',
42                       'gpgkey', 'ssl_verify', 'priority',
43                       ):
44             if hasattr(self, field) and getattr(self, field):
45                 retval += ' --%s="%s"' % (field, getattr(self, field))
46
47         for field in ('save', 'diable', 'nocache', 'source', 'debuginfo'):
48             if hasattr(self, field) and getattr(self, field):
49                 retval += ' --%s' % field
50
51         return retval
52
53
54 class Mic_Repo(F14_Repo):
55     "Mic customized repo command"
56
57     def _getParser(self):
58         op = F14_Repo._getParser(self)
59         op.add_option('--user')
60         op.add_option('--passwd')
61         op.add_option("--proxyuser")
62         op.add_option("--proxypasswd")
63
64         op.add_option("--save", action="store_true", default=False)
65         op.add_option("--debuginfo", action="store_true", default=False)
66         op.add_option("--source", action="store_true", default=False)
67         op.add_option("--disable", action="store_true", default=False)
68         op.add_option("--nocache", action="store_true", default=False)
69
70         op.add_option("--gpgkey")
71         op.add_option("--priority", type="int")
72         op.add_option("--ssl_verify", default="yes")
73         return op