Esempio n. 1
0
def parse_args(arguments,
               apply_conf=APPLY_CONF,
               version=None,
               tlog=None,
               doc=None):
    """Parse command-line options."""
    ctx = {}
    caller_fqn = inspect.stack()[1][1]
    ctx['caller_fqn'] = caller_fqn
    caller = os0.nakedname(os.path.basename(caller_fqn))
    ctx['caller'] = caller
    if os.isatty(0):
        ctx['run_daemon'] = False
    else:
        ctx['run_daemon'] = True
    ctx['run_tty'] = os.isatty(0)
    if tlog:
        ctx['tlog'] = tlog
    else:
        ctx['tlog'] = "/var/log/" + caller + ".log"
    # running autotest
    if version is None:
        ctx['_run_autotest'] = True
    parser = create_parser(version, doc, ctx)
    ctx['_parser'] = parser
    opt_obj = parser.parse_args(arguments)
    ctx['_opt_obj'] = opt_obj
    if apply_conf:
        if hasattr(opt_obj, 'conf_fn'):
            ctx['conf_fn'] = opt_obj.conf_fn
        ctx = read_config(ctx)
        opt_obj = parser.parse_args(arguments)
    ctx = create_params_dict(ctx)
    return ctx
Esempio n. 2
0
 def test_03(self, ctx):
     if not ctx.get('dry_run', False):
         wchar_string = u"- Unicode string àèìòù"
         os0.wlog(wchar_string)
         # if wlog fails follow statemente is not executed
     sts = self.Z.test_result(ctx, "Check for unicode support", True, True)
     if not ctx.get('dry_run', False):
         x = unichr(0x3b1) + unichr(0x3b2) + unichr(0x3b3)
         os0.wlog("- Greek letters", x)
     sts = self.Z.test_result(ctx, "- Greek letters", True, True)
     res = None
     ustr = None
     bstr = None
     if not ctx.get('dry_run', False):
         res = os0.str2bool('true', None)
     sts = self.Z.test_result(ctx, "str2bool(true)", True, res)
     if not ctx.get('dry_run', False):
         res = os0.str2bool('0', None)
     sts = self.Z.test_result(ctx, "str2bool(0)", False, res)
     if not ctx.get('dry_run', False):
         res = os0.str2bool(False, None)
     sts = self.Z.test_result(ctx, "str2bool(0)", False, res)
     if not ctx.get('dry_run', False):
         res = os0.str2bool('invalid', False)
     sts = self.Z.test_result(ctx, "str2bool(0)", False, res)
     if not ctx.get('dry_run', False):
         res = os0.nakedname('myfile')
     sts = self.Z.test_result(ctx, "nakedname(myfile)", 'myfile', res)
     if not ctx.get('dry_run', False):
         res = os0.nakedname('myfile.py')
     sts = self.Z.test_result(ctx, "nakedname(myfile.py)", 'myfile', res)
     if not ctx.get('dry_run', False):
         bstr = 'text àèìòù'
         ustr = u"text àèìòù"
         res = os0.u(bstr)
     sts = self.Z.test_result(ctx, "unicode(string)", ustr, res)
     sts = self.Z.test_result(ctx, "unicode(string)", ustr, os0.u(ustr))
     if not ctx.get('dry_run', False):
         bstr = 'text àèìòù'
         ustr = u"text àèìòù"
         res = os0.b(ustr)
     sts = self.Z.test_result(ctx, "bstring(string)", bstr, res)
     sts = self.Z.test_result(ctx, "bstring(string)", os0.b(bstr), res)
     return sts
Esempio n. 3
0
 def get_this_fqn(self):
     i = 1
     valid = False
     while not valid:
         this_fqn = os.path.abspath(inspect.stack()[i][1])
         this = os0.nakedname(os.path.basename(this_fqn))
         if this in ("__init__", "pdb", "cmd", "z0testlib", "z0lib"):
             i += 1
         else:
             valid = True
     return this_fqn
Esempio n. 4
0
 def parseoptargs(self, arguments,
                  apply_conf=APPLY_CONF, version=None, tlog=None, doc=None):
     """Parse command-line options.
     @param arguments list of arguments; should argv from command line
     @param version   software version to displya with -V option
                      in bash version reports __version__ variable of script
     """
     ctx = {}
     this_fqn = self.get_this_fqn()
     ctx['this_fqn'] = this_fqn
     this = os0.nakedname(os.path.basename(this_fqn))
     ctx['this'] = this
     if os.isatty(0):
         ctx['run_daemon'] = False
     else:                                               # pragma: no cover
         ctx['run_daemon'] = True
     ctx['run_tty'] = os.isatty(0)
     if tlog:
         ctx['tlog'] = tlog
     else:
         ctx['tlog'] = this + '.log'
     # running autotest
     if version is None:
         ctx['_run_autotest'] = True
     ctx['_parser'] = self.parser
     opt_obj = self.parser.parse_args(arguments)
     ctx['_opt_obj'] = opt_obj
     if apply_conf:
         if hasattr(opt_obj, 'conf_fn'):
             ctx['conf_fn'] = opt_obj.conf_fn
         ctx = self.read_config(ctx)
         opt_obj = self.parser.parse_args(arguments)
     ctx = self.create_params_dict(ctx)
     p = 'opt_verbose'
     if p in ctx and ctx[p] is None:
         if os.environ.get('VERBOSE_MODE', '') in ('0', '1'):
             ctx[p] = int(os.environ['VERBOSE_MODE'])
         elif os.isatty(0):
             ctx[p] = 1
         else:
             ctx[p] = 0
     # elif p in ctx and ctx[p] == -1:
     #     ctx[0] = 0
     return ctx
Esempio n. 5
0
def read_config(opt_obj, parser, conf_fn=None):
    """Read both user configuration and local configuration."""
    if conf_fn is None or not conf_fn:
        if CONF_FN:
            conf_fn = CONF_FN
        else:
            conf_fn = os0.nakedname(os.path.basename(__file__)) + ".conf"
    conf_obj = ConfigParser.SafeConfigParser(default_conf())
    if ODOO_CONF:
        if os.path.isfile(ODOO_CONF):
            conf_fns = (ODOO_CONF, conf_fn)
        elif os.path.isfile(OE_CONF):
            conf_fns = (OE_CONF, conf_fn)
        else:
            conf_fns = conf_fn
    else:
        conf_fns = conf_fn
    conf_fns = conf_obj.read(conf_fns)
    return conf_obj, conf_fns
Esempio n. 6
0
def _import_file_model(ctx, o_model, csv_fn):
    """Get model name of import file"""
    model, hide_cid = _get_model_bone(ctx, o_model)
    if model is None:
        model = os0.nakedname(csv_fn).replace('-', '.').replace('_', '.')
    return model, hide_cid