new subcmd getconfig to query config with pass special handling
authorJF Ding <jian-feng.ding@intel.com>
Mon, 28 Nov 2011 08:11:22 +0000 (16:11 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Mon, 28 Nov 2011 08:11:22 +0000 (16:11 +0800)
tizenpkg/conf.py
tools/tizenpkg

index 13c24bc..d3de982 100644 (file)
@@ -259,16 +259,16 @@ hudson_passx = $hudson_passx
         return False
 
     def _check_passwd(self):
-        plainpass = self.get('hudson_pass')
+        plainpass = self._get('hudson_pass')
         if not plainpass:
             # None or ''
             return
 
         msger.warning('plaintext password in config file will be replaced by encoded one')
-        self.set('hudson_passx', base64.b64encode(plainpass.encode('bz2')), replace_opt='hudson_pass')
+        self.set('hudson_pass', base64.b64encode(plainpass.encode('bz2')))
         self.update()
 
-    def get(self, opt, section='general'):
+    def _get(self, opt, section='general'):
         try:
             return self.cfgparser.get(section, opt)
         except NoOptionError:
@@ -277,7 +277,21 @@ hudson_passx = $hudson_passx
             else:
                 return None
 
+    def get(self, opt, section='general'):
+        if opt == 'hudson_pass':
+            opt = 'hudson_passx'
+            val = self._get(opt, section)
+            if val:
+                return base64.b64decode(val).decode('bz2')
+            else:
+                return val
+        else:
+            return self._get(opt, section)
+
     def set(self, opt, val, section='general', replace_opt=None):
+        if opt == 'hudson_pass':
+            opt = 'hudson_passx'
+            replace_opt = 'hudson_pass'
         return self.cfgparser.set(section, opt, val, replace_opt)
 
     def update(self):
index 2f6b662..16e064e 100755 (executable)
@@ -113,6 +113,30 @@ class TizenPkg(cmdln.Cmdln):
         from tizenpkg import cmd_import as cmd
         cmd.do(opts, args)
 
+    @cmdln.alias("cfg")
+    @cmdln.option('-s', '--section', metavar='SECTION', default='general',
+                  help='specify the section inside config file, default as "general"')
+    def do_getconfig(self, subcmd, opts, *args):
+        """${cmd_name}: query values of config file
+
+        Usage:
+            tizenpkg getconfig <opt1> [<opt2> ...]
+
+        ${cmd_option_list}
+        """
+
+        if not args:
+            raise errors.Usage('argument(s) expected')
+
+        for arg in args:
+            val = configmgr.get(arg, section=opts.section)
+            if val:
+                msger.verbose('The value of opt "%s" in [%s] is:' % (arg, opts.section))
+                msger.raw(val)
+            else:
+                msger.verbose('No value for opt key "%s" in [%s]' % (arg, opts.section))
+                msger.raw('') # we need a blank line
+
 if __name__ == '__main__':
     try:
         mic = TizenPkg()