Example #1
0
        def resolve_requirement(requirement: Requirement):
            dist = best.get(requirement.key)
            if dist is None:
                # Find the best distribution and add it to the map
                dist = self.by_key.get(requirement.key)
                if dist is None or (dist not in requirement
                                    and replace_conflicting):
                    ws = self
                    with lock:
                        if env[0] is None:
                            if dist is None:
                                env[0] = Environment(self.entries)
                            else:
                                # Use an empty environment and workingset to avoid
                                # any further conflicts with the conflicting
                                # distribution
                                env[0] = Environment([])
                                ws = WorkingSet([])
                    dist = best[requirement.key] = env[0].best_match(
                        requirement,
                        ws,
                        installer,
                        replace_conflicting=replace_conflicting,
                    )
                    if dist is None:
                        requirers = required_by.get(requirement, None)
                        raise DistributionNotFound(requirement, requirers)
                resolved.append(dist)

            if dist not in requirement:
                # Oops, the "best" so far conflicts with a dependency
                dependent_requirement = required_by[requirement]
                raise VersionConflict(
                    dist, requirement).with_context(dependent_requirement)

            with lock:
                # push the new requirements onto the stack
                new_requirements = [
                    requirement
                    for requirement in dist.requires(requirement.extras)[::-1]
                    if requirement.key not in self.excludes
                ]
                req_stack.extend(new_requirements)

                # Register the new requirements needed by requirement
                for new_requirement in new_requirements:
                    required_by[new_requirement].add(requirement.project_name)
                    requirement_extras[new_requirement] = requirement.extras

                processed[requirement] = True
Example #2
0
  def __init__(self, egg_glob):
    """
      Construct an Egg equivalence class.

      egg_glob: A glob.glob() compatible egg pattern, e.g.:
        - Mako-0.4.0-py2.6.egg
        - ZooKeeper-0.4-*.egg
        - ZooKeeper*
        - *.egg

      All eggs in the pattern must be the same package/version, but may
      differ on platform.  This is how we support creating "fat" pex
      binaries, by packaging the same egg but with native code compiled for
      several architectures, e.g. linux-x86_64 and macosx-10.6-x86_64.
    """
    # architecture inspecific platform so we can do fat pexes
    self._env = Environment(search_path = glob.glob(egg_glob), platform = None)
    pkgs = [pkg for pkg in self._env]
    if len(pkgs) != 1:
      raise PythonEgg.AmbiguousEggNest(egg_glob, self._env)
    self.name = pkgs[0]

    # all eggs should either be versioned or all unversioned
    # similarly, if they all have versions, they should all be the same
    vers_defined = set(pkg.has_version() for pkg in self._env[self.name])
    vers = set([pkg.version for pkg in self._env[self.name] if pkg.has_version()])
    if len(vers) > 1 or len(vers_defined) != 1:
      raise PythonEgg.AmbiguousEggVersions(egg_glob)

    self.eggs = [egg.location for egg in self._env[self.name]]
def search(apps_paths=None, installed_apps=None):
    """
    Searches in the given apps directories for Django apps with the entry point
    ``'django.apps'`` and adds them to the python path, if necesary. 
    
    Returns a tuple with all installed and reusable applications.
    """
    if Environment is not None and apps_paths is not None:
        # find every "distributions" in the given paths for reusable apps and
        # add them to the "working_set", effectively setting PYTHONPATH
        distributions, errors = working_set.find_plugins(
            Environment(apps_paths))
        for dist in distributions:
            working_set.add(dist)
        for dist, e in errors.iteritems():
            if isinstance(e, DistributionNotFound):
                raise ReusableAppsError('"%s": ("%s" not found)', dist, e)
            elif isinstance(e, VersionConflict):
                raise ReusableAppsError('"%s": (version conflict "%s")', dist,
                                        e)
            elif isinstance(e, UnknownExtra):
                raise ReusableAppsError('"%s": (unknown extra "%s")', dist, e)
            elif isinstance(e, ImportError):
                raise ReusableAppsError('"%s": (can\'t import "%s")', dist, e)
            else:
                raise ReusableAppsError('"%s": (error "%s")', dist, e)

        # look for entry points in all distributions of the current working set
        # (on the PYTHONPATH) and add matching modules to INSTALLED_APPS
        for entry in working_set.iter_entry_points('django.apps'):
            app_name = entry.module_name
            if app_name not in installed_apps and app_name not in REUSEABLE_APPS:
                REUSEABLE_APPS.append(entry.module_name)
        return installed_apps + tuple(REUSEABLE_APPS)
Example #4
0
def add_plugin_dir(plugin_dir):
    """
    Find available plugins
    """
    if not os.path.isdir(plugin_dir):
        LOG.debug("Adding plugin directory: %r", plugin_dir)
        env = Environment([plugin_dir])
        dists, errors = working_set.find_plugins(env)
        for dist in dists:
            LOG.debug("Adding distribution: %r", dist)
            working_set.add(dist)

        if errors:
            for dist, error in list(errors.items()):
                errmsg = None
                if isinstance(error, DistributionNotFound):
                    req, = error.args
                    errmsg = "%r not found" % req.project_name
                elif isinstance(error, VersionConflict):
                    dist, req = error.args
                    errmsg = "Version Conflict. Requested %s Found %s" % (req,
                                                                          dist)
                else:
                    errmsg = repr(error)
                LOG.error("Failed to load %s: %r", dist, errmsg)
        PLUGIN_DIRECTORIES.append(plugin_dir)
Example #5
0
 def __init__(self):
     """ Create the factory """
     self.lock = Lock()
     self.env = Environment()
     self.loop = get_event_loop()
     self.figmentators_by_type = {}
     self.settings = FigmentatorFactorySettings()
Example #6
0
    def fetch_dist(self, requirement):
        """Fetch an egg needed for building.
        Use pip/wheel to fetch/build a wheel."""
        get_distribution("pip")
        get_distribution("wheel")
        # Ignore environment markers; if supplied, it is required.
        requirement = Requirement.parse(str(requirement))
        requirement.marker = None
        # Take easy_install options into account, but do not override relevant
        # pip environment variables (like PIP_INDEX_URL or PIP_QUIET); they'll
        # take precedence.
        if "PIP_QUIET" in environ or "PIP_VERBOSE" in environ:
            quiet = False
        else:
            quiet = True
        index_url = None
        find_links = []
        environment = Environment()
        for dist in find_distributions(self.dist_dir):
            if dist in requirement and environment.can_add(dist):
                return dist
        with TemporaryDirectory() as tmpdir:
            cmd = [
                executable,
                "-m",
                "pip",
                "--disable-pip-version-check",
                "wheel",
                "--no-deps",
                "-w",
                tmpdir,
            ]
            if quiet:
                cmd.append("--quiet")
            if index_url is not None:
                cmd.extend(("--index-url", index_url))
            if find_links is not None:
                for link in find_links:
                    cmd.extend(("--find-links", link))
            # If requirement is a PEP 508 direct URL, directly pass
            # the URL to pip, as `req @ url` does not work on the
            # command line.
            if requirement.url:
                cmd.append(requirement.url)
            else:
                cmd.append(str(requirement))
            check_call(cmd)
            with ZipFile(glob(path.join(tmpdir, "*.whl"))[0], "r") as zf:
                zf.extractall(self.dist_dir)

            pattern = re_compile(translate(f'{requirement.project_name.replace("-","_")}-*.dist-info'), IGNORECASE)
            dist_path = [path.join(self.dist_dir, x) for x in listdir(self.dist_dir) if path.isdir(path.join(self.dist_dir, x)) and match(pattern, x)][0]

            root = path.dirname(dist_path)
            return Distribution.from_location(
                root,
                path.basename(dist_path),
                PathMetadata(root, dist_path),
                precedence=BINARY_DIST,
            )
Example #7
0
    def build_tables(self):
        """Test essential imports and show versions."""
        caption = "Module Import Status"
        cols = "Module", "Description", "Status"
        rows = []

        # This strange bit is needed because the ndscheduler package
        # is poorly implemented, and writes to stdout when it is loaded.
        stdout = sys.stdout
        sys.stdout = open(devnull, "w")
        for name, description in self.MODULES:
            try:
                import_module(name)
                status = Reporter.Cell("OK", classes="success center")
            except Exception as e:
                status = Reporter.Cell(str(e), classes="failure center")
            rows.append((name, description, status))

        # Restore sanity to the world.
        sys.stdout = stdout
        tables = [Reporter.Table(rows, columns=cols, caption=caption)]
        caption = "Module Versions"
        cols = "Module", "Version"
        rows = [("Python", str(sys.version))]
        env = Environment()
        for key in sorted(env, key=str.lower):
            for package in env[key]:
                rows.append(str(package).split())
        tables.append(Reporter.Table(rows, columns=cols, caption=caption))
        return tables
Example #8
0
def plugins_iter(plugin_dir, ep_name):
    """
    @type plugin_dir : C{str}
    @param plugin_dir : The fqname of the plugin directory

    @type ep_name : C{str}
    @param ep_name : The name of the Entry Point to be loaded
    
    @yield: The loaded Entry Point (C{obj})
    """

    working_set.add_entry(plugin_dir)
    pkg_env = Environment([plugin_dir])
    
    for env_name in pkg_env:
        egg = pkg_env[env_name][0]
        LOG.debug("Activating egg: %s"%(egg))
        egg.activate()
        for name in egg.get_entry_map(ep_name):
            entry_point = egg.get_entry_info(ep_name, name)
            LOG.debug("Loading entry point: %s"%(entry_point))
            cls = entry_point.load()
            yield cls
    for entry_point in working_set.iter_entry_points(ep_name):
        LOG.debug("Loading entry point: %s"%(entry_point))
        cls = entry_point.load()
        yield cls
Example #9
0
    def __init__(self):
        self._caller = ''
        self._requirements = []
        self._locations = []
        self._environment = Environment()
        self._missing_distribs = []

        stack = list(
            filter(
                lambda s: inspect.getframeinfo(s[0]).code_context is not None
                and inspect.getframeinfo(s[0]).function == '<module>',
                inspect.stack()))

        try:
            self._caller = os.path.realpath(inspect.getfile(stack[-1][0]))
        except IndexError as e:
            pass

        self._req_file = self.caller.replace('.py', '.req')

        try:
            with open(self.req_file) as fp:
                self._requirements = [
                    Requirement.parse(req) for req in fp.readlines()
                ]
        except FileNotFoundError as e:
            pass

        self.search()
Example #10
0
 def __init__(self, groups=plugin_groups.keys(), search_path=None):
     super(PkgResourcesFactory, self).__init__()
     self._have_new_types = True
     self._groups = copy.copy(groups)
     self._search_path = search_path
     self.env = Environment(search_path)
     self.tree_analyser = PythonSourceTreeAnalyser()
Example #11
0
def add_plugin_dir(plugin_dir):
    if os.path.isdir(plugin_dir):
        return None
    LOGGER.debug("Adding plugin directory: %r", plugin_dir)
    env = Environment([plugin_dir])
    dists, errors = working_set.find_plugins(env)
    for dist in dists:
        LOGGER.debug("Adding distribution: %r", dist)
        working_set.add(dist)

    if errors:
        for dist, error in list(errors.items()):
            errmsg = None
            if isinstance(error, DistributionNotFound):
                req, = error.args
                errmsg = "%r not found" % req.project_name
            elif isinstance(error, VersionConflict):
                dist, req = error.args
                errmsg = "Version Conflict. Requested %s Found %s" % (req,
                                                                      dist)
            else:
                # FIXME: Are there other types of failures?
                errmsg = repr(error)
            LOGGER.error("Failed to load %s: %r", dist, errmsg)
    global plugin_directories
    plugin_directories.append(plugin_dir)
Example #12
0
def update_all():
    """ Update all packages """

    env = Environment()

    for project_name in env._distmap.keys():
        print("Update %s" % (project_name))
        alea_install_U(project_name)
Example #13
0
def _create_easy_install_mock(dist, available_dists=[]):
    easy_install_mock = Mock(install_dir="foo", index_url="",
                             distribution=dist)
    easy_install_mock.return_value = easy_install_mock
    easy_install_mock.local_index = Environment()
    for dist in available_dists:
        easy_install_mock.local_index.add(dist)
    return easy_install_mock
Example #14
0
 def test_liscence_distro():
     """
     Ensure the LISCENCE is in the distribution.
     """
     spag = Environment().__getitem__('spag')[0]
     assert spag.has_metadata('LICENSE.txt')
     pkg_license_output = spag.get_metadata('LICENSE.txt')
     git_license_output = ''
     with open('LICENSE.txt') as fd:
         git_license_output = fd.read()
     assert git_license_output == pkg_license_output
Example #15
0
  def checker_pex(self, interpreter):
    # TODO(John Sirois): Formalize in pants.base?
    pants_dev_mode = os.environ.get('PANTS_DEV')

    if pants_dev_mode:
      checker_id = self.checker_target.transitive_invalidation_hash()
    else:
      checker_id = hash_all([self._CHECKER_REQ])

    pex_path = os.path.join(self.workdir, 'checker', checker_id, str(interpreter.identity))

    if not os.path.exists(pex_path):
      with self.context.new_workunit(name='build-checker'):
        with safe_concurrent_creation(pex_path) as chroot:
          pex_builder = PexBuilderWrapper.Factory.create(
            builder=PEXBuilder(path=chroot, interpreter=interpreter),
            log=self.context.log)

          # Constraining is required to guard against the case where the user
          # has a pexrc file set.
          pex_builder.add_interpreter_constraint(str(interpreter.identity.requirement))

          if pants_dev_mode:
            pex_builder.add_sources_from(self.checker_target)
            req_libs = [tgt for tgt in self.checker_target.closure()
                        if isinstance(tgt, PythonRequirementLibrary)]

            pex_builder.add_requirement_libs_from(req_libs=req_libs)
          else:
            try:
              # The checker is already on sys.path, eg: embedded in pants.pex.
              platform = Platform.current()
              platform_name = platform.platform
              env = Environment(search_path=sys.path,
                                platform=platform_name,
                                python=interpreter.version_string)
              working_set = WorkingSet(entries=sys.path)
              for dist in working_set.resolve([Requirement.parse(self._CHECKER_REQ)], env=env):
                pex_builder.add_direct_requirements(dist.requires())
                # NB: We add the dist location instead of the dist itself to make sure its a
                # distribution style pex knows how to package.
                pex_builder.add_dist_location(dist.location)
              pex_builder.add_direct_requirements([self._CHECKER_REQ])
            except (DistributionNotFound, PEXBuilder.InvalidDistribution):
              # We need to resolve the checker from a local or remote distribution repo.
              pex_builder.add_resolved_requirements(
                [PythonRequirement(self._CHECKER_REQ)])

          pex_builder.set_entry_point(self._CHECKER_ENTRYPOINT)
          pex_builder.freeze()

    return PEX(pex_path, interpreter=interpreter)
Example #16
0
def main():
    failed = []

    print('Getting environment')
    env = Environment()

    for pkgname in env:
        print('Checking %s' % pkgname)
        if pkgname in PROJECTS['bad']:
            print('\tMarked as BAD. FAIL')
            failed.append(pkgname)
            continue
        elif pkgname in PROJECTS['good']:
            print('\tMarked as GOOD. PASS')
            continue

        for pkg in env[pkgname]:
            had_conclusive_result = False
            print('\tChecking version %s' % pkg.version)
            for check in CHECKS:
                print('\t\tRunning check: %s...' % check.__name__)
                res = check(pkg)
                if res is True:
                    print('\t\tPASS')
                    had_conclusive_result = True
                    break
                elif res is False:
                    print('\t\tFAIL')
                    had_conclusive_result = True
                    failed.append(pkg)
                    break
                elif res is None:
                    print('\t\t\tINCONCLUSIVE')
                    continue
                else:
                    print('\t\t\tINVALID RESULT: %s' % res)
                    failed.append(pkg)
                    break

            if not had_conclusive_result:
                failed.append(pkg)
                print('\t\tNO CONCLUSIVE RESULTS. FAIL')

    print()
    if failed:
        print('At least one package failed.')
        for fail in failed:
            print('\tFailure: %s' % fail)
        sys.exit(1)
    else:
        print('All packages passed license check')
Example #17
0
 def run(self):
     self.run_command('build_tests')
     this_dir = os.path.normpath(
         os.path.abspath(os.path.dirname(__file__)))
     lib_dirs = glob.glob(os.path.join(this_dir, 'build', 'lib*'))
     test_dir = os.path.join(this_dir, 'build', 'tests')
     env = Environment(search_path=lib_dirs)
     distributions = env["nose"]
     assert len(distributions) == 1, (
         "Incorrect number of distributions found")
     dist = distributions[0]
     dist.activate()
     sys.path.insert(0, test_dir)
     setuptools.command.test.test.run(self)
Example #18
0
def clean_version():
    """ Keep only most recent version of each package """

    env = Environment()

    for project_name in env._distmap.keys():

        installed_version = [d.version for d in env[project_name]]
        if (installed_version):
            max_version = max(installed_version, key=parse_version)

            for dist in env[project_name]:
                if parse_version(dist.version) < parse_version(max_version):
                    remove_egg(project_name, dist)
Example #19
0
def main():
    """ Run the application. """

    # Find all additional eggs.
    environment = Environment(EGG_PATH)

    distributions, errors = working_set.find_plugins(environment)
    if len(errors) > 0:
        raise SystemError('cannot add eggs %s' % errors)

    logger.debug('added eggs %s' % distributions)

    # Add them to the working set.
    map(working_set.add, distributions)

    # Create and run the application.
    return run()
Example #20
0
    def finalize_options(self):
        if self.version:
            print 'distribute %s' % get_distribution('distribute').version
            sys.exit()

        py_version = sys.version.split()[0]

        self.config_vars = {
            'dist_name': self.distribution.get_name(),
            'dist_version': self.distribution.get_version(),
            'dist_fullname': self.distribution.get_fullname(),
            'py_version': py_version,
            'py_version_short': py_version[0:3],
            'py_version_nodot': py_version[0] + py_version[2],
        }

        self._expand('install_dir')

        normpath = map(normalize_path, sys.path)

        self.index_url = self.index_url or "http://pypi.python.org/simple"

        hosts = ['*']
        if self.package_index is None:
            self.package_index = self.create_index(
                self.index_url,
                hosts=hosts,
            )
        self.local_index = Environment(sys.path)

        if self.find_links is not None:
            if isinstance(self.find_links, basestring):
                self.find_links = self.find_links.split()
        else:
            self.find_links = []

        self.package_index.add_find_links(self.find_links)

        if not self.args:
            raise DistutilsArgError(
                "No urls, filenames, or requirements specified (see --help)")

        self.outputs = []
Example #21
0
    def _load_eggs(self, search_path):
        # Redefine where to search entry point.
        distributions, errors = working_set.find_plugins(
            Environment(search_path)
        )
        if errors:
            logger.warn('could not load %s', errors)
        map(working_set.add, distributions)

        # Load each entry point one by one
        for entry in working_set.iter_entry_points('rdiffweb.plugins'):
            # Get unicode plugin name
            module_name = entry.name
            if isinstance(module_name, bytes):
                module_name = module_name.decode('ascii')
            # Plugin is enabled. Load it.
            logger.debug('loading module plugin [%s] from [%r]', module_name, entry.module_name)
            try:
                yield (module_name, entry.load(), entry.dist)
            except:
                logger.error('fail to load module plugin [%s] from [%r]', module_name, entry.module_name, exc_info=1)
Example #22
0
def list_extensions() -> List[ExtensionInfo]:
    """
    List all installed Chaos Toolkit extensions in the current environment.

    Notice, for now we can only list extensions that start with `chaostoolkit-`
    in their package name.

    This is not as powerful and solid as we want it to be. The trick is that we
    can't rely on any metadata inside extensions to tell us they exist and
    what functionnality they provide either. Python has the concept of trove
    classifiers on packages but we can't extend them yet so they are of no use
    to us.

    In a future version, we will provide a mechanism from packages to support
    a better detection.
    """
    infos = []
    distros = Environment()
    seen = []
    for key in distros:
        for dist in distros[key]:
            if dist.has_metadata('PKG-INFO'):
                m = dist.get_metadata('PKG-INFO')
                info = message_from_string(m)
                name = info["Name"]
                if name == "chaostoolkit-lib":
                    continue
                if name in seen:
                    continue
                seen.append(name)
                if name.startswith("chaostoolkit-"):
                    ext = ExtensionInfo(name=name,
                                        version=info["Version"],
                                        summary=info["Summary"],
                                        license=info["License"],
                                        author=info["Author"],
                                        url=info["Home-page"])
                    infos.append(ext)
    return infos
Example #23
0
def test_list_one_installed(environment: Environment):
    env = Environment(search_path=[])
    environment.return_value = env
    metadata = """Metadata-Version: 2.1
Name: chaostoolkit-some-stuff
Version: 0.1.0
Summary: Chaos Toolkit some package
Home-page: http://chaostoolkit.org
Author: chaostoolkit Team
Author-email: [email protected]
License: Apache License 2.0
"""

    env.add(
        Distribution(project_name="chaostoolkit-some-stuff",
                     version="0.1.0",
                     metadata=InMemoryMetadata({"PKG-INFO": metadata})))
    extensions = list_extensions()
    assert len(extensions) == 1

    ext = extensions[0]
    assert ext.name == "chaostoolkit-some-stuff"
    assert ext.version == "0.1.0"
Example #24
0
def initPluginEnv(options, path):

    from pkg_resources import working_set, Environment

    # if options is passed in, use prefs to determine what to bypass
    # otherwise all plugins are added to the working_set

    if options is not None:
        prefs = loadPrefs(options)
        pluginPrefs = prefs.get('plugins', None)
    else:
        prefs = None
        pluginPrefs = None

    plugin_env = Environment(path)
    plugin_eggs = []

    # remove uninstalled plugins from prefs
    if pluginPrefs is not None:
        for project_name in pluginPrefs.keys():
            if project_name not in plugin_env:
                del prefs['plugins'][project_name]
        prefs.write()

    # add active plugins and l10n eggs to working set
    for project_name in sorted(plugin_env):
        for egg in plugin_env[project_name]:
            if egg.has_metadata('resources.ini'):
                working_set.add(egg)  # possible l10n egg
            elif (pluginPrefs is None
                  or pluginPrefs.get(project_name) != 'inactive'):
                working_set.add(egg)  # possible plugin egg
                plugin_eggs.append(egg)
            break

    return plugin_env, plugin_eggs
Example #25
0
 def __init__(self, groups=_plugin_groups, search_path=None):
     super(PkgResourcesFactory, self).__init__()
     self._have_new_types = True
     self._groups = copy.copy(groups)
     self._search_path = search_path
     self.env = Environment(search_path)
Example #26
0
 def environment(self):
     return Environment([str(self.sp)])
Example #27
0
def already_satisfied(req: str) -> bool:
    requirement = Requirement(req)
    environment = Environment()
    return any(dist in requirement for dist in environment[requirement.name])
Example #28
0
def run(plugins=[], use_eggs=True, egg_path=[], image_path=[], template_path=[], startup_task="", application_name="Omnivore", debug_log=False, document_class=None):
    """Start the application
    
    :param plugins: list of user plugins
    :param use_eggs Boolean: search for setuptools plugins and plugins in local eggs?
    :param egg_path: list of user-specified paths to search for more plugins
    :param startup_task string: task factory identifier for task shown in initial window
    :param application_name string: change application name instead of default Omnivore
    """
    EnthoughtWxApp.mac_menubar_app_name = application_name
    _app = EnthoughtWxApp(redirect=False)
    if False:  # enable this to use FilterEvent
        _app.FilterEvent = _app.FilterEventMouseWheel

    # Enthought library imports.
    from envisage.api import PluginManager
    from envisage.core_plugin import CorePlugin

    # Local imports.
    from omnivore.framework.application import FrameworkApplication
    from omnivore.framework.plugin import OmnivoreTasksPlugin, OmnivoreMainPlugin
    from omnivore.file_type.plugin import FileTypePlugin
    from omnivore import get_image_path
    from omnivore.utils.jobs import get_global_job_manager

    # Include standard plugins
    core_plugins = [ CorePlugin(), OmnivoreTasksPlugin(), OmnivoreMainPlugin(), FileTypePlugin() ]
    if sys.platform == "darwin":
        from omnivore.framework.osx_plugin import OSXMenuBarPlugin
        core_plugins.append(OSXMenuBarPlugin())

    import omnivore.file_type.recognizers
    core_plugins.extend(omnivore.file_type.recognizers.plugins)

    import omnivore.plugins
    core_plugins.extend(omnivore.plugins.plugins)

    # Add the user's plugins
    core_plugins.extend(plugins)

    # Check basic command line args
    default_parser = argparse.ArgumentParser(description="Default Parser")
    default_parser.add_argument("--no-eggs", dest="use_eggs", action="store_false", default=True, help="Do not load plugins from python eggs")
    options, extra_args = default_parser.parse_known_args()

    # The default is to use the specified plugins as well as any found
    # through setuptools and any local eggs (if an egg_path is specified).
    # Egg/setuptool plugin searching is turned off by the use_eggs parameter.
    default = PluginManager(
        plugins = core_plugins,
    )
    if use_eggs and options.use_eggs:
        from pkg_resources import Environment, working_set
        from envisage.api import EggPluginManager
        from envisage.composite_plugin_manager import CompositePluginManager

        # Find all additional eggs and add them to the working set
        environment = Environment(egg_path)
        distributions, errors = working_set.find_plugins(environment)
        if len(errors) > 0:
            raise SystemError('cannot add eggs %s' % errors)
        logger = logging.getLogger()
        logger.debug('added eggs %s' % distributions)
        map(working_set.add, distributions)

        # The plugin manager specifies which eggs to include and ignores all others
        egg = EggPluginManager(
            include = [
                'omnivore.tasks',
            ]
        )

        plugin_manager = CompositePluginManager(
            plugin_managers=[default, egg]
        )
    else:
        plugin_manager = default

    # Add omnivore icons after all image paths to allow user icon themes to take
    # precidence
    from pyface.resource_manager import resource_manager
    import os
    image_paths = image_path[:]
    image_paths.append(get_image_path("icons"))
    image_paths.append(get_image_path("../omnivore8bit/icons"))
    resource_manager.extra_paths.extend(image_paths)

    from omnivore.templates import template_subdirs
    template_subdirs.extend(template_path)

    kwargs = {}
    if startup_task:
        kwargs['startup_task'] = startup_task
    if application_name:
        kwargs['name'] = application_name
    if document_class:
        kwargs['document_class'] = document_class

    # Create a debugging log
    if debug_log:
        filename = app.get_log_file_name("debug")
        handler = logging.FileHandler(filename)
        logger = logging.getLogger('')
        logger.addHandler(handler)
        logger.setLevel(logging.DEBUG)

    # Turn off omnivore log debug messages by default
    log = logging.getLogger("omnivore")
    log.setLevel(logging.INFO)

    # check for logging stuff again to pick up any new loggers loaded since
    # startup
    import omnivore.utils.wx.error_logger as error_logger
    if "-d" in extra_args:
        i = extra_args.index("-d")
        error_logger.enable_loggers(extra_args[i+1])
    app = FrameworkApplication(plugin_manager=plugin_manager, command_line_args=extra_args, **kwargs)

    app.run()

    job_manager = get_global_job_manager()
    if job_manager is not None:
        job_manager.shutdown()
Example #29
0
# -*- coding: utf-8 -*-

from base64 import b64encode
from couchdb.http import ResourceConflict
from json import dumps
from libnacl.secret import SecretBox
from logging import getLogger
from openprocurement.api.utils import context_unpack, json_view, APIResource
from pyramid.security import Allow
from pkg_resources import Environment
from itertools import chain

PKG_ENV = Environment()
PKG_VERSIONS = dict(
    chain.from_iterable([[(x.project_name, x.version) for x in PKG_ENV[i]]
                         for i in PKG_ENV]))

LOGGER = getLogger(__package__)


class Root(object):
    __name__ = None
    __parent__ = None
    __acl__ = [
        (Allow, 'g:archivarius', 'dump_resource'),
        (Allow, 'g:archivarius', 'delete_resource'),
    ]

    def __init__(self, request):
        self.request = request
        self.db = request.registry.db
Example #30
0
 def __init__(self, context, request):
     super().__init__(context, request)
     environment = self.environment = Environment()
     environment.scan()