示例#1
0
文件: external.py 项目: kinow/rose
def _launch(name, event_handler=None, run_fg=False, *args, **kwargs):
    popen = RosePopener(event_handler)
    command = popen.get_cmd(name, *args)
    kwargs['stdin'] = sys.stdin
    if run_fg:
        return popen.run(*command, **kwargs)
    popen.run_bg(*command, **kwargs)
示例#2
0
    def __init__(self, prefix, popen=None, prompt_func=None):
        self.prefix = prefix
        root = self._get_conf_value("ws")
        if root is None:
            raise UndefinedRosiePrefixWS(self.prefix)
        if not root.endswith("/"):
            root += "/"
        self.root = root
        urlparse_res = urlparse(self.root)
        self.scheme = urlparse_res[0]
        self.host = urlparse_res[1]
        self.password_orig = None
        self.username_orig = None
        self.password = None
        self.username = None
        if popen is None:
            popen = RosePopener()
        self.popen = popen
        self.prompt_func = prompt_func
        for password_store_name in self.PASSWORD_STORE_NAMES:
            password_store_cls = globals()[password_store_name]
            if password_store_cls.usable():
                self.password_store = password_store_cls()
                break
        else:
            self.password_store = None

        self.requests_kwargs = {}
        self._init_https_params()
示例#3
0
def main():
    """Implement "rose suite-hook" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options(
        "mail_cc", "mail", "retrieve_job_logs", "shutdown")
    opts, args = opt_parser.parse_args()
    for key in ["mail_cc"]:
        values = []
        if getattr(opts, key):
            for value in getattr(opts, key):
                values.extend(value.split(","))
        setattr(opts, key, values)
    report = Reporter(opts.verbosity - opts.quietness - 1)  # Reduced default
    popen = RosePopener(event_handler=report)
    suite_engine_proc = SuiteEngineProcessor.get_processor(
        event_handler=report, popen=popen)
    args = suite_engine_proc.process_suite_hook_args(*args, **vars(opts))
    hook = RoseSuiteHook(event_handler=report,
                         popen=popen,
                         suite_engine_proc=suite_engine_proc)
    hook(*args,
         should_mail=opts.mail,
         mail_cc_list=opts.mail_cc,
         should_shutdown=opts.shutdown,
         should_retrieve_job_logs=opts.retrieve_job_logs)
示例#4
0
文件: vc.py 项目: kaday/rose
 def __init__(self,
              event_handler=None,
              popen=None,
              fs_util=None,
              force_mode=False):
     if event_handler is None:
         event_handler = self._dummy
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler)
     self.popen = popen
     if fs_util is None:
         fs_util = FileSystemUtil(event_handler)
     self.fs_util = fs_util
     self.force_mode = force_mode
     self._work_dir = None
     atexit.register(self._delete_work_dir)
     self.subversion_servers_conf = None
     subversion_servers_conf = os.getenv("ROSIE_SUBVERSION_SERVERS_CONF")
     if subversion_servers_conf:
         self.subversion_servers_conf = subversion_servers_conf
     else:
         subversion_servers_conf = os.path.expanduser(
             self.SUBVERSION_SERVERS_CONF)
         if os.path.exists(subversion_servers_conf):
             self.subversion_servers_conf = subversion_servers_conf
示例#5
0
 def __init__(self, prefixes=None, prompt_func=None, popen=None,
              event_handler=None):
     if not event_handler:
         event_handler = Reporter()
     if not popen:
         popen = RosePopener(event_handler=event_handler)
     self.event_handler = event_handler
     self.popen = popen
     self.prompt_func = prompt_func
     self.prefixes = []
     self.auth_managers = {}
     conf = ResourceLocator.default().get_conf()
     conf_rosie_id = conf.get(["rosie-id"], no_ignore=True)
     if conf_rosie_id is not None:
         for key, node in conf_rosie_id.value.items():
             if node.is_ignored() or not key.startswith("prefix-ws."):
                 continue
             prefix = key.replace("prefix-ws.", "")
             self.auth_managers[prefix] = RosieWSClientAuthManager(
                 prefix, popen=self.popen, prompt_func=self.prompt_func)
     if not prefixes:
         prefixes_str = conf_rosie_id.get_value(["prefixes-ws-default"])
         if prefixes_str:
             prefixes = shlex.split(prefixes_str)
         else:
             prefixes = sorted(self.auth_managers.keys())
     self.set_prefixes(prefixes)
示例#6
0
 def __init__(self, event_handler=None, popen=None):
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler=event_handler)
     self.popen = popen
     self.scorers = {}
     self.local_host_strs = None
示例#7
0
 def __init__(self, event_handler=None, popen=None, suite_engine_proc=None):
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler)
     self.popen = popen
     if suite_engine_proc is None:
         suite_engine_proc = SuiteEngineProcessor.get_processor(
             event_handler=event_handler, popen=popen)
     self.suite_engine_proc = suite_engine_proc
示例#8
0
 def __init__(self, event_handler=None, popen=None, fs_util=None, **kwargs):
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler)
     self.popen = popen
     if fs_util is None:
         fs_util = FileSystemUtil(event_handler)
     self.fs_util = fs_util
     self.date_time_oper = RoseDateTimeOperator()
示例#9
0
 def __init__(self, event_handler=None, popen=None):
     if event_handler is None:
         event_handler = Reporter()
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(self.event_handler)
     self.popen = popen
     path = os.path.dirname(os.path.dirname(sys.modules["rosie"].__file__))
     self.usertools_manager = SchemeHandlersManager(
         [path], "rosie.usertools", ["verify_users"])
示例#10
0
 def __init__(self, event_handler=None):
     self.event_handler = event_handler
     self.popen = RosePopener(self.event_handler)
     self.fs_util = FileSystemUtil(self.event_handler)
     self.config_pm = ConfigProcessorsManager(self.event_handler,
                                              self.popen, self.fs_util)
     self.host_selector = HostSelector(self.event_handler, self.popen)
     self.suite_engine_proc = SuiteEngineProcessor.get_processor(
         event_handler=self.event_handler,
         popen=self.popen,
         fs_util=self.fs_util)
示例#11
0
 def __init__(self, event_handler=None, popen=None, fs_util=None):
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler)
     self.popen = popen
     if fs_util is None:
         fs_util = FileSystemUtil(event_handler)
     self.fs_util = fs_util
     path = os.path.dirname(os.path.dirname(sys.modules["rose"].__file__))
     SchemeHandlersManager.__init__(self, [path], "rose.config_processors",
                                    ["process"])
示例#12
0
 def __init__(self, event_handler=None, popen=None, fs_util=None):
     if event_handler is None:
         event_handler = self._dummy
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler)
     self.popen = popen
     if fs_util is None:
         fs_util = FileSystemUtil(event_handler)
     self.fs_util = fs_util
     self.post_commit_hook = RosieSvnPostCommitHook(
         event_handler=event_handler, popen=popen)
示例#13
0
 def __init__(self, event_handler=None, popen=None, fs_util=None):
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler)
     self.popen = popen
     if fs_util is None:
         fs_util = FileSystemUtil(event_handler)
     self.fs_util = fs_util
     path = os.path.dirname(os.path.dirname(sys.modules["rose"].__file__))
     SchemeHandlersManager.__init__(
         self, [path], ns="rose.loc_handlers", attrs=["parse", "pull"],
         can_handle="can_pull")
示例#14
0
 def __init__(self, event_handler=None, popen=None, fs_util=None,
              host_selector=None, **_):
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler)
     self.popen = popen
     if fs_util is None:
         fs_util = FileSystemUtil(event_handler)
     self.fs_util = fs_util
     if host_selector is None:
         host_selector = HostSelector(event_handler, popen)
     self.host_selector = host_selector
     self.date_time_oper = RoseDateTimeOperator()
示例#15
0
 def __init__(self, opts, reporter=None, popen=None, fs_util=None):
     self.opts = opts
     if reporter is None:
         self.reporter = Reporter(opts.verbosity - opts.quietness)
     else:
         self.reporter = reporter
     if popen is None:
         self.popen = RosePopener(event_handler=self.reporter)
     else:
         self.popen = popen
     if fs_util is None:
         self.fs_util = FileSystemUtil(event_handler=self.reporter)
     else:
         self.fs_util = fs_util
示例#16
0
def write_source_vc_info(run_source_dir, output=None, popen=None):
    """Write version control information of sources used in run time.

    run_source_dir -- The source directory we are interested in.
    output -- An open file handle or a string containing a writable path.
              If not specified, use sys.stdout.
    popen -- A rose.popen.RosePopener instance for running vc commands.
             If not specified, use a new local instance.

    """
    if popen is None:
        popen = RosePopener()
    if output is None:
        handle = sys.stdout
    elif hasattr(output, "write"):
        handle = output
    else:
        handle = open(output, "wb")
    handle.write("%s\n" % run_source_dir)
    environ = dict(os.environ)
    environ["LANG"] = "C"
    for vcs, args_list in [
            ("svn", [
                ["info", "--non-interactive"],
                ["status", "--non-interactive"],
                ["diff", "--internal-diff", "--non-interactive"]]),
            ("git", [["describe"], ["status"], ["diff"]])]:
        if not popen.which(vcs):
            continue
        cwd = os.getcwd()
        os.chdir(run_source_dir)
        try:
            for args in args_list:
                cmd = [vcs] + args
                ret_code, out, _ = popen.run(*cmd, env=environ)
                if out:
                    handle.write("#" * 80 + "\n")
                    handle.write(("# %s\n" % popen.list_to_shell_str(cmd)))
                    handle.write("#" * 80 + "\n")
                    handle.write(out)
                if ret_code:  # If cmd fails once, it will likely fail again
                    break
        finally:
            os.chdir(cwd)
示例#17
0
 def __init__(self, event_handler=None, popen=None, config_pm=None,
              fs_util=None, suite_engine_proc=None):
     if not self.CONF_NAME:
         self.CONF_NAME = self.NAME
     self.event_handler = event_handler
     if popen is None:
         popen = RosePopener(event_handler)
     self.popen = popen
     if fs_util is None:
         fs_util = FileSystemUtil(event_handler)
     self.fs_util = fs_util
     if config_pm is None:
         config_pm = ConfigProcessorsManager(event_handler, popen, fs_util)
     self.config_pm = config_pm
     if suite_engine_proc is None:
         suite_engine_proc = SuiteEngineProcessor.get_processor(
             event_handler=event_handler, popen=popen, fs_util=fs_util)
     self.suite_engine_proc = suite_engine_proc
     self.conf_tree_loader = ConfigTreeLoader()
示例#18
0
    def __init__(self,
                 prefix,
                 popen=None,
                 prompt_func=None,
                 event_handler=None):
        self.prefix = prefix
        root = self._get_conf_value("ws")
        if root is None:
            raise UndefinedRosiePrefixWS(self.prefix)
        if not root.endswith("/"):
            root += "/"
        self.root = root
        urlparse_res = urlparse(self.root)
        self.scheme = urlparse_res[0]
        self.host = urlparse_res[1]
        self.password_orig = None
        self.username_orig = None
        self.password = None
        self.username = None
        if popen is None:
            popen = RosePopener()
        self.popen = popen
        self.prompt_func = prompt_func
        if event_handler is None:
            self.event_handler = Reporter()
        else:
            self.event_handler = event_handler
        res_loc = ResourceLocator.default()
        password_stores_str = res_loc.default().get_conf().get_value(
            keys=["rosie-id", "prefix-password-store." + self.prefix],
            default=self.PASSWORD_STORES_STR)
        for password_store_name in shlex.split(password_stores_str):
            password_store_cls = self.PASSWORD_STORE_CLASSES.get(
                password_store_name)
            if password_store_cls is not None and password_store_cls.usable():
                self.password_store = password_store_cls()
                break
        else:
            self.password_store = None

        self.requests_kwargs = {}
        self._init_https_params()
示例#19
0
def main():
    """Implement the "rose host-select" command."""
    opt_parser = RoseOptionParser()
    opt_parser.add_my_options("choice", "rank_method", "thresholds", "timeout")
    opts, args = opt_parser.parse_args()
    report = Reporter(opts.verbosity - opts.quietness)
    popen = RosePopener(event_handler=report)
    select = HostSelector(event_handler=report, popen=popen)
    try:
        host_score_list = select(names=args,
                                 rank_method=opts.rank_method,
                                 thresholds=opts.thresholds,
                                 ssh_cmd_timeout=opts.timeout)
    except (NoHostError, NoHostSelectError) as exc:
        report(exc)
        if opts.debug_mode:
            traceback.print_exc(exc)
        sys.exit(1)
    opts.choice = int(opts.choice)
    report(choice(host_score_list[0:opts.choice])[0] + "\n", level=0)
示例#20
0
 def __init__(self,
              config,
              opts,
              args,
              method_paths,
              reporter=None,
              popen=None):
     if reporter is None:
         self.reporter = Reporter(opts.verbosity - opts.quietness)
     else:
         self.reporter = reporter
     if popen is None:
         self.popen = RosePopener(event_handler=self.reporter)
     else:
         self.popen = popen
     self.opts = opts
     self.args = args
     self.config = config
     self.load_tasks()
     modules = []
     for path in method_paths:
         for filename in glob.glob(path + "/*.py"):
             modules.append(filename)
     self.load_user_comparison_modules(modules)
示例#21
0
def write_source_vc_info(run_source_dir, output=None, popen=None):
    """Write version control information of sources used in run time.

    run_source_dir -- The source directory we are interested in.
    output -- An open file handle or a string containing a writable path.
              If not specified, use sys.stdout.
    popen -- A rose.popen.RosePopener instance for running vc commands.
             If not specified, use a new local instance.

    """
    if popen is None:
        popen = RosePopener()
    if output is None:
        handle = sys.stdout
    elif hasattr(output, "write"):
        handle = output
    else:
        handle = open(output, "wb")
    for vcs, cmds in [("svn", ["info", "status", "diff"]),
                      ("git", ["describe", "status", "diff"])]:
        if not popen.which(vcs):
            continue
        cwd = os.getcwd()
        os.chdir(run_source_dir)
        try:
            for cmd in cmds:
                rc, out, err = popen.run(vcs, cmd)
                if out:
                    handle.write("#" * 80 + "\n")
                    handle.write(("# %s %s\n" % (vcs, cmd)).upper())
                    handle.write("#" * 80 + "\n")
                    handle.write(out)
                if rc: # If cmd fails once, chances are, it will fail again
                    break
        finally:
            os.chdir(cwd)
示例#22
0
 def __init__(self, event_handler=None):
     self.event_handler = event_handler
     self.popen = RosePopener(self.event_handler)
     self.suite_engine_proc = SuiteEngineProcessor.get_processor(
         event_handler=self.event_handler, popen=self.popen)