當前位置: 首頁>>代碼示例>>Python>>正文


Python popen.RosePopener類代碼示例

本文整理匯總了Python中rose.popen.RosePopener的典型用法代碼示例。如果您正苦於以下問題:Python RosePopener類的具體用法?Python RosePopener怎麽用?Python RosePopener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RosePopener類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _launch

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)
開發者ID:dpmatthews,項目名稱:rose,代碼行數:7,代碼來源:external.py

示例2: process

    def process(self):
        """Process STEM options into 'rose suite-run' options."""

        # Generate options for source trees
        repos = {}
        if not self.opts.source:
            self.opts.source = ['.']
        self.opts.project = list()

        for i, url in enumerate(self.opts.source):
            project, url, base, rev = self._ascertain_project(url)
            self.opts.source[i] = url
            self.opts.project.append(project)
            if project in repos:
                repos[project].append(url)
            else:
                repos[project] = [ url ]
                self._add_define_option('SOURCE_' + project.upper() + '_REV', 
                                        '"' + rev + '"')
                self._add_define_option('SOURCE_' + project.upper() + '_BASE', 
                                        '"' + base + '"')
            self.reporter(SourceTreeAddedAsBranchEvent(url))
        for project, branches in repos.iteritems():
            var = 'SOURCE_' + project.upper()
            branchstring = RosePopener.list_to_shell_str(branches)
            self._add_define_option(var, '"' + branchstring + '"')

        # Generate the variable containing tasks to run
        if self.opts.group:
            if not self.opts.defines:
                self.opts.defines = []
            expanded_groups = []
            for i in self.opts.group:
                expanded_groups.extend(i.split(','))
            self.opts.defines.append(SUITE_RC_PREFIX + 'RUN_NAMES=' +
                                     str(expanded_groups))

        # Load the config file and return any automatic-options
        auto_opts = self._read_site_config_and_return_options()
        if auto_opts:
            automatic_options = auto_opts.split()
            for option in automatic_options:
                elements = option.split("=")
                if len(elements) == 2:
                    self._add_define_option(elements[0], 
                                      '"' + elements[1] + '"')

        # Change into the suite directory
        if self.opts.conf_dir:
            self.reporter(SuiteSelectionEvent(self.opts.conf_dir))
        else:
            thissuite = self._this_suite()
            self.fs_util.chdir(thissuite)
            self.reporter(SuiteSelectionEvent(thissuite))

        # Create a default name for the suite; allow override by user
        if not self.opts.name:
            self.opts.name = self._generate_name()

        return self.opts
開發者ID:csimag,項目名稱:rose,代碼行數:60,代碼來源:stem.py

示例3: write_source_vc_info

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")
    msg = "%s\n" % run_source_dir
    _write_safely(msg, handle)
    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:
                    _write_safely(("#" * 80 + "\n"), handle)
                    _write_safely(("# %s\n" % popen.list_to_shell_str(cmd)),
                                  handle)
                    _write_safely(("#" * 80 + "\n"), handle)
                    _write_safely(out, handle)
                if ret_code:  # If cmd fails once, it will likely fail again
                    break
        finally:
            os.chdir(cwd)
開發者ID:benfitzpatrick,項目名稱:rose,代碼行數:46,代碼來源:run_source_vc.py

示例4: write_source_vc_info

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")
    environ = dict(os.environ)
    environ["LANG"] = "C"
    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, env=environ)
                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)
開發者ID:ScottWales,項目名稱:rose,代碼行數:38,代碼來源:run_source_vc.py

示例5: __init__

 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
開發者ID:harry-shepherd,項目名稱:rose,代碼行數:14,代碼來源:stem.py

示例6: process

    def process(self):
        """Process STEM options into 'rose suite-run' options."""

        # Generate options for source trees
        repos = {}
        if not self.opts.source:
            self.opts.source = ['.']
        self.opts.project = list()

        for i, url in enumerate(self.opts.source):
            project, url, base, rev = self._ascertain_project(url)
            self.opts.source[i] = url
            self.opts.project.append(project)
            if project in repos:
                repos[project].append(url)
            else:
                repos[project] = [ url ]
                self._add_define_option('SOURCE_' + project.upper() + '_REV', 
                                        '"' + rev + '"')
                self._add_define_option('SOURCE_' + project.upper() + '_BASE', 
                                        '"' + base + '"')
            self.reporter(SourceTreeAddedAsBranchEvent(url))
        for project, branches in repos.iteritems():
            var = 'SOURCE_' + project.upper()
            branchstring = RosePopener.list_to_shell_str(branches)
            self._add_define_option(var, '"' + branchstring + '"')

        # Generate the variable containing tasks to run
        if self.opts.group:
            if not self.opts.defines:
                self.opts.defines = []
            self.opts.defines.append(SUITE_RC_PREFIX + 'RUN_NAMES=' +
                                     str(self.opts.group))

        # Change into the suite directory
        if self.opts.conf_dir:
            self.fs_util.chdir(self.opts.conf_dir)
            self.reporter(SuiteSelectionEvent(self.opts.conf_dir))
        else:
            thissuite = self._this_suite()
            self.fs_util.chdir(thissuite)
            self.opts.conf_dir = thissuite
            self.reporter(SuiteSelectionEvent(thissuite))

        # Create a default name for the suite; allow override by user
        if not self.opts.name:
            self.opts.name = self._generate_name()

        return self.opts
開發者ID:jmancell,項目名稱:rose,代碼行數:49,代碼來源:stem.py

示例7: __init__

 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)
開發者ID:jonseddon,項目名稱:rose,代碼行數:18,代碼來源:rose_ana.py

示例8: Analyse

class Analyse(object):

    """A comparison engine for Rose."""

    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)

    def analyse(self):
        """Perform comparisons given a list of tasks."""
        rc = 0
        for task in self.tasks:

            if self.check_extract(task):
                # Internal AnalysisEngine extract+comparison test

                # Extract data from results and from kgoX
                task = self.do_extract(task, "result")

                for i in range(task.numkgofiles):
                    var = "kgo" + str(i + 1)
                    task = self.do_extract(task, var)

                task = self.do_comparison(task)
            else:
                # External program(s) doing test

                # Command to run
                command = task.extract

                result = re.search(r"\$file", command)
                # If the command contains $file, it is run separately for both
                # the KGO and the result files
                if result:
                    # Replace $file token with resultfile or kgofile
                    resultcommand = self._expand_tokens(command, task,
                                                        "result")
                    kgocommand = self._expand_tokens(command, task, "kgo1")

                    # Run the command on the resultfile
                    task.resultdata = self._run_command(resultcommand)

                    # Run the command on the KGO file
                    task.kgo1data = self._run_command(kgocommand)
                else:
                    # The command works on both files at the same time
                    # Replace tokens $kgofile and $resultfile for actual values
                    command = self._expand_tokens(command, task)

                    # Run the command
                    task.resultdata = self._run_command(command)

                # Run the comparison
                task = self.do_comparison(task)

            self.reporter(TaskCompletionEvent(task),
                          prefix="[%s]" % (task.userstatus))
            if task.numericstatus != PASS:
                rc += 1
        return rc, self.tasks

    def check_extract(self, task):
        """Check if an extract name is present in a user method."""
        for module_name, class_name, method, help in self.user_methods:
            if task.extract == class_name:
                return True
        return False

    def do_comparison(self, task):
        """Run the comparison."""
        for module_name, class_name, method, help in self.user_methods:
            comparison_name = ".".join([module_name, class_name])
            if task.comparison == class_name:
                for module in self.modules:
                    if module.__name__ == module_name:
                        comparison_inst = getattr(module, class_name)()
                        comparison_meth = getattr(comparison_inst, "run")(task)
        return task

    def do_extract(self, task, var):
        """Extract the specified data."""
        for module_name, class_name, method, help in self.user_methods:
            extract_name = ".".join([module_name, class_name])
            if task.extract == class_name:
#.........這裏部分代碼省略.........
開發者ID:harry-shepherd,項目名稱:rose,代碼行數:101,代碼來源:rose_ana.py

示例9: StemRunner

class StemRunner(object):

    """Set up options for running a STEM job through Rose."""

    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

    def _add_define_option(self, var, val):
        """Add a define option passed to the SuiteRunner."""

        if self.opts.defines:
            self.opts.defines.append(SUITE_RC_PREFIX + var + '=' + val)
        else:
            self.opts.defines = [SUITE_RC_PREFIX + var + '=' + val]
        self.reporter(ConfigVariableSetEvent(var, val))
        return

    def _get_base_dir(self, item):
        """Given a source tree return the following from 'fcm loc-layout':
           * url
           * sub_tree
           * peg_rev
           * root
           * project
        """

        rc, output, stderr = self.popen.run('fcm', 'loc-layout', item)
        if rc != 0:
            raise ProjectNotFoundException(item, stderr)

        ret = {}
        for line in output.splitlines():
            if ":" not in line:
                continue
            key, value = line.split(":", 1)
            if key:
                if value:
                    ret[key] = value.strip()

        return ret

    def _get_project_from_url(self, source_dict):
        """Run 'fcm keyword-print' to work out the project name."""

        repo = source_dict['root']
        if source_dict['project']:
            repo += '/' + source_dict['project']

        rc, kpoutput, stderr = self.popen.run('fcm', 'kp', source_dict['url'])

        project = None
        for line in kpoutput.splitlines():
            if line.rstrip().endswith(repo):
                kpresult = re.search(r'^location{primary}\[(.*)\]', line)
                if kpresult:
                    project = kpresult.group(1)
                    break
        return project

    def _deduce_mirror(self, source_dict, project):
        """Deduce the mirror location of this source tree."""

        # Root location for project
        proj_root = source_dict['root'] + '/' + source_dict['project']

        # Swap project to mirror
        project = re.sub(r'\.x$', r'.xm', project)
        mirror_repo = "fcm:" + project

        # Generate mirror location
        mirror = re.sub(proj_root, mirror_repo, source_dict['url'])

        # Add forwards slash after .xm if missing
        if '.xm/' not in mirror:
            mirror = re.sub(r'\.xm', r'.xm/', mirror)
        return mirror

    def _ascertain_project(self, item):
        """Set the project name and top-level from 'fcm loc-layout'.
        Returns:
            * project name
            * top-level location of the source tree with revision number
            * top-level location of the source tree without revision number
            * revision number
        """

        project = None
        try:
#.........這裏部分代碼省略.........
開發者ID:harry-shepherd,項目名稱:rose,代碼行數:101,代碼來源:stem.py

示例10: _launch

def _launch(name, event_handler=None, *args, **kwargs):
    popen = RosePopener(event_handler)
    command = popen.get_cmd(name, *args)
    return popen.run_bg(*command, **kwargs)
開發者ID:jmancell,項目名稱:rose,代碼行數:4,代碼來源:external.py

示例11: StemRunner

class StemRunner(object):

    """Set up options for running a STEM job through Rose."""

    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

    def _add_define_option(self, var, val):
        """Add a define option passed to the SuiteRunner."""

        if self.opts.defines:
            self.opts.defines.append(SUITE_RC_PREFIX + var + '=' + val )
        else:
            self.opts.defines= [ SUITE_RC_PREFIX + var + '=' + val ]
        self.reporter(ConfigVariableSetEvent(var, val))
        return

    def _ascertain_project(self, item):
        """Set the project name and top-level from 'fcm loc-layout'"""

        project = ''
        if re.search(r'^\.', item):
            item = os.path.abspath(os.path.join(os.getcwd(), item))
        result = re.search(r'\[(\w+)\]', item)
        if result:
            project = result.group(1)
            item = re.sub(r'\[\w+\]', r'', item)
            return project, item

        rc, output, stderr = self.popen.run('fcm', 'loc-layout', item)
        if rc != 0:
            raise ProjectNotFoundException(item, stderr)
        result = re.search(r'url:\s*(file|svn|https|http|svn\+ssh)(://.*)',
                           output)

        # Generate a unique name for this project based on fcm kp
        if result:
            urlstring = result.group(1) + result.group(2)
            rc, kpoutput, stderr = self.popen.run('fcm', 'kp', urlstring)
            kpresult = re.search(r'location{primary}\[(.*)\]\s*=', kpoutput)
            if kpresult:
                project = kpresult.group(1)
        if not project:
            raise ProjectNotFoundException(item)

        result = re.search(r'peg_rev:\s*(.*)', output)
        if '@' in item and result:
            revision = '@' + result.group(1)
            base = re.sub(r'@.*', r'', item)
        else:
            revision = ''
            base = item

        # If we're in a subdirectory of the source tree, find it and
        # remove it leaving the top-level location
        result = re.search(r'target:\s*(.*)', output)
        target=''
        if result:
            target = result.group(1)
            subtree=''
            result2 = re.search(r'sub_tree:\s*(.*)', output)
            if result2:
                subtree = result2.group(1)
                item = re.sub(subtree, r'', target)

        # Remove trailing forwards-slash
        item = re.sub(r'/$',r'',item)
        return project, item, base, revision

    def _generate_name(self):
        """Generate a suite name from the name of the first source tree."""
        dummy, basedir, dummy2, dummy3 = self._ascertain_project(os.getcwd())
        name = os.path.basename(basedir)
        return name

    def _this_suite(self):
        """Find the location of the suite in the first source tree."""

        # Get base of first source
        basedir = ''
        if self.opts.source:
            basedir = self.opts.source[0]
        else:
            dummy, basedir, dum2, dum3 = self._ascertain_project(os.getcwd())

        suitedir = os.path.join(basedir, DEFAULT_TEST_DIR)
        suitefile = os.path.join(suitedir, "rose-suite.conf")

#.........這裏部分代碼省略.........
開發者ID:jmancell,項目名稱:rose,代碼行數:101,代碼來源:stem.py

示例12: except

    'auto_cli_doc',
    'cylc_lang',
    'minicylc',
    'practical',
    'rose_lang',
    'rose_domain',
    'script_include',
    'sub_lang'
]

# Select best available SVG image converter.
for svg_converter, extension in [
        ('rsvg', 'sphinxcontrib.rsvgconverter'),
        ('inkscape', 'sphinxcontrib.inkscapeconverter')]:
    try:
        assert RosePopener.which(svg_converter)
        __import__(extension)
    except (AssertionError, ImportError):
        # converter or extension not available
        pass
    else:
        extensions.append(extension)
        break
else:
    # no extensions or converters available, fall-back to default
    # vector graphics will be converted to bitmaps in all documents
    extensions.append('sphinx.ext.imgconverter')

# Slide (hieroglyph) settings.
slide_theme = 'single-level'
slide_link_to_html = True
開發者ID:benfitzpatrick,項目名稱:rose,代碼行數:31,代碼來源:conf.py


注:本文中的rose.popen.RosePopener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。