Exemple #1
0
def add_libs(name):
    if name in MANDATORY and name not in LOADED:
        path = libs.util.add_path(DIRECTORY[name])
        if path:
            site.addsitedir(path)
            LOADED[name] = path
            return path
def add_vendor_packages(vendor_folder):
    """
    Adds our vendor packages folder to sys.path so that third-party
    packages can be imported.
    """
    import site
    import os.path
    import sys

    # Use site.addsitedir() because it appropriately reads .pth
    # files for namespaced packages. Unfortunately, there's not an
    # option to choose where addsitedir() puts its paths in sys.path
    # so we have to do a little bit of magic to make it play along.

    # We're going to grab the current sys.path and split it up into
    # the first entry and then the rest. Essentially turning
    # ['.', '/site-packages/x', 'site-packages/y']
    # into
    # ['.'] and ['/site-packages/x', 'site-packages/y']
    # The reason for this is we want '.' to remain at the top of the
    # list but we want our vendor files to override everything else.
    sys.path, remainder = sys.path[:1], sys.path[1:]

    # Now we call addsitedir which will append our vendor directories
    # to sys.path (which was truncated by the last step.)
    site.addsitedir(os.path.join(os.path.dirname(__file__), vendor_folder))

    # Finally, we'll add the paths we removed back.
    sys.path.extend(remainder)
    def _addPluginDir(self, directory):
        added = False
        if isMapClientPluginsDir(directory):
            site.addsitedir(directory)
            added = True

        return added
Exemple #4
0
def bootstrap():
    """Actually bootstrap our shiv environment."""

    # get a handle of the currently executing zip file
    archive = current_zipfile()

    # create an environment object (a combination of env vars and json metadata)
    env = Environment.from_json(archive.read("environment.json").decode())

    # get a site-packages directory (from env var or via build id)
    site_packages = cache_path(archive, env.root, env.build_id) / "site-packages"

    # determine if first run or forcing extract
    if not site_packages.exists() or env.force_extract:
        extract_site_packages(archive, site_packages.parent)

    # stdlib blessed way of extending path
    site.addsitedir(site_packages)

    # do entry point import and call
    if env.entry_point is not None and env.interpreter is None:
        mod = import_string(env.entry_point)
        try:
            mod()
        except TypeError as e:
            # catch "<module> is not callable", which is thrown when the entry point's
            # callable shares a name with it's parent module
            # e.g. "from foo.bar import bar; bar()"
            getattr(mod, env.entry_point.replace(":", ".").split(".")[1])()
    else:
        # drop into interactive mode
        execute_interpreter()
Exemple #5
0
def setupenv():

    # Remember original sys.path.
    prev_sys_path = list(sys.path)

    # we add currently directory to path and change to it
    mydir = os.path.dirname(os.path.abspath(__file__))

    pwd = os.path.join(mydir, os.path.join('..', '..', '..', 'env'))
    os.chdir(pwd)
    sys.path = [pwd, os.path.join(mydir, '..', '..')] + sys.path

    # find the site-packages within the local virtualenv
    for python_dir in os.listdir('lib'):
        site_packages_dir = os.path.join('lib', python_dir, 'site-packages')
        if os.path.exists(site_packages_dir):
            site.addsitedir(os.path.abspath(site_packages_dir))

    # Reorder sys.path so new directories at the front.
    new_sys_path = []
    for item in list(sys.path):
        if item not in prev_sys_path:
            new_sys_path.append(item)
            sys.path.remove(item)
    sys.path[:0] = new_sys_path
def add_virtualenv_path(venv):
    """Add virtualenv's site-packages to `sys.path`."""
    venv = os.path.abspath(venv)
    path = os.path.join(
        venv, 'lib', 'python%d.%d' % sys.version_info[:2], 'site-packages')
    sys.path.insert(0, path)
    site.addsitedir(path)
def main():
    with open(CONFFILE) as conffile:
        conf = yaml.safe_load(conffile)
    site.addsitedir(conf["confdir"])
    import settings_admin

    # KittyStore
    dbspec = re.match("""
        postgres://
        (?P<user>[a-z]+)
        :
        (?P<password>[^@]+)
        @
        (?P<host>[^/]+)
        /
        (?P<database>[^/?]+)
        """, settings_admin.KITTYSTORE_URL, re.X)
    give_rights(dbspec.group("host"),
                dbspec.group("user"),
                dbspec.group("password"),
                dbspec.group("database")
                )

    # HyperKitty
    give_rights(
        settings_admin.DATABASES["default"]["HOST"],
        settings_admin.DATABASES["default"]["USER"],
        settings_admin.DATABASES["default"]["PASSWORD"],
        settings_admin.DATABASES["default"]["NAME"],
    )
Exemple #8
0
    def enter_virtualenv(cls):
        cls.old_os_path = os.environ['PATH']
        os.environ['PATH'] = cls.env_dir + os.pathsep + cls.old_os_path

        base = os.path.abspath(cls.env_dir)
        site_packages = os.path.join(base, 'lib', 'python%s' % sys.version[:3], 'site-packages')
        cls.prev_sys_path = list(sys.path)

        cls.past_prefix = sys.prefix
        cls.past_real_prefix = getattr(sys, 'real_prefix', None)

        site.addsitedir(site_packages)
        sys.real_prefix = sys.prefix
        sys.prefix = base

        # Move the added items to the front of the path:
        new_sys_path = []
        for item in list(sys.path):
            if item not in cls.prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
        sys.path[:0] = new_sys_path

        return  (os.path.join(cls.bin_dir, 'pip'),
                os.path.join(cls.bin_dir, 'python'),
                os.path.join(cls.bin_dir, 'activate'),
                site_packages)
def path_appendine_sdk():

    if not os.environ.get('DJANGO_SETTINGS_MODULE'):
        os.environ.update({'DJANGO_SETTINGS_MODULE': 'settings'})

    if not on_appengine_remote:
        # add SQLlite to allowed modules
        from google.appengine.tools import dev_appserver_import_hook
        #from google.appengine import dist27
        #dist27.MODULE_OVERRIDES = []
        dev_appserver_import_hook.HardenedModulesHook._WHITE_LIST_C_MODULES.extend(
            ('parser', '_ssl', '_io', '_sqlite3', 'os', '_os', 'tempfile'))

        dev_appserver_import_hook.HardenedModulesHook._MODULE_OVERRIDES['os'] = os.__dict__
        dev_appserver_import_hook.HardenedModulesHook._PY27_ALLOWED_MODULES.append('os')
        dev_appserver_import_hook.HardenedModulesHook._HardenedModulesHook__PY27_OPTIONAL_ALLOWED_MODULES = {}
        dev_appserver_import_hook.FakeFile.NOT_ALLOWED_DIRS = set([])
        dev_appserver_import_hook.FakeFile.IsFileAccessible = staticmethod(
            lambda *args, **kwargs: True
        )
    else:

        # loogging exceptions hook
        from .utils import log_traceback
        signals.got_request_exception.connect(log_traceback)

        # add production site
        import site
        site.addsitedir(os.path.join(PROJECT_DIR, 'appengine_libs'))
Exemple #10
0
  def _activate(self):
    self.update_candidate_distributions(self.load_internal_cache(self._pex, self._pex_info))

    if not self._pex_info.zip_safe and os.path.isfile(self._pex):
      self.update_module_paths(self.force_local(self._pex, self._pex_info))

    # TODO(wickman)  Implement dynamic fetchers if pex_info requirements specify dynamic=True
    # or a non-empty repository.
    all_reqs = [Requirement.parse(req) for req, _, _ in self._pex_info.requirements]

    working_set = WorkingSet([])

    with TRACER.timed('Resolving %s' %
        ' '.join(map(str, all_reqs)) if all_reqs else 'empty dependency list'):
      try:
        resolved = working_set.resolve(all_reqs, env=self)
      except DistributionNotFound as e:
        TRACER.log('Failed to resolve a requirement: %s' % e)
        TRACER.log('Current working set:')
        for dist in working_set:
          TRACER.log('  - %s' % dist)
        raise

    for dist in resolved:
      with TRACER.timed('Activating %s' % dist):
        working_set.add(dist)

        if os.path.isdir(dist.location):
          with TRACER.timed('Adding sitedir'):
            site.addsitedir(dist.location)

        dist.activate()

    return working_set
Exemple #11
0
def setup_vendor_path():
    """Sets up path and vendor/ stuff"""
    global _has_setup_vendor_path

    if _has_setup_vendor_path:
        return

    # Adjust the python path and put local packages in front.
    prev_sys_path = list(sys.path)

    # Make root application importable without the need for
    # python setup.py install|develop
    sys.path.append(ROOT)

    # FIXME: This is vendor/-specific. When we ditch vendor/ we can
    # ditch this.

    # Check for ~/.virtualenvs/fjordvagrant/. If that doesn't exist, then
    # launch all the vendor/ stuff.
    possible_venv = os.path.expanduser('~/.virtualenvs/fjordvagrant/')
    if not os.path.exists(possible_venv):
        os.environ['USING_VENDOR'] = '1'
        site.addsitedir(path('vendor'))

        # Move the new items to the front of sys.path. (via virtualenv)
        new_sys_path = []
        for item in list(sys.path):
            if item not in prev_sys_path:
                new_sys_path.append(item)
                sys.path.remove(item)
        sys.path[:0] = new_sys_path

    _has_setup_vendor_path = True
Exemple #12
0
def compress_dataset_files(dataset_data, ext_python_modules_home, max_threads, log):
    log.info("\n== Compressing corrected reads (with gzip)")
    to_compress = []
    for reads_library in dataset_data:
        for key, value in reads_library.items():
            if key.endswith('reads'):
                compressed_reads_filenames = []
                for reads_file in value:
                    if not os.path.isfile(reads_file):
                        support.error('something went wrong and file with corrected reads (' + reads_file + ') is missing!', log)
                    to_compress.append(reads_file)
                    compressed_reads_filenames.append(reads_file + ".gz")
                reads_library[key] = compressed_reads_filenames
    if len(to_compress):
        pigz_path = support.which('pigz')
        if pigz_path:
            for reads_file in to_compress:
                support.sys_call([pigz_path, '-f', '-7', '-p', str(max_threads), reads_file], log)
        else:
            addsitedir(ext_python_modules_home)
            if sys.version.startswith('2.'):
                from joblib2 import Parallel, delayed
            elif sys.version.startswith('3.'):
                from joblib3 import Parallel, delayed
            n_jobs = min(len(to_compress), max_threads)
            outputs = Parallel(n_jobs=n_jobs)(delayed(support.sys_call)(['gzip', '-f', '-7', reads_file]) for reads_file in to_compress)
            for output in outputs:
                if output:
                    log.info(output)
    def __init__(self, idldir, idlfile='rosbridge.idl'):
        self.ignore_unbound_type = rospy.get_param('~ignore_unbound',True)
        self.idldir  = idldir
        self.idlfile = idlfile
        site.addsitedir(self.idldir)

        self.generated = []
        self.idltext = ''
        self.basictab = {
            'int8'   : 'char',
            'uint8'  : 'octet',
            'int16'  : 'short',
            'uint16' : 'unsigned short',
            'int32'  : 'long',
            'uint32' : 'unsigned long',
            'int64'  : 'long',          # ??
            'uint64' : 'unsigned long', # ??
            'float32': 'float',
            'float64': 'double',
            'string' : 'string',
            'bool'   : 'boolean',
            'char'   : 'char',          # deplicated
            'byte'   : 'octet',         # deplicated
            'time'   : 'RTC::Time',     # builtin
            'duration' : 'RTC::Time'}   # builtin
        self.dummyslot = 'dummy_padding_' # for empty message

        self.topicinfo = {} # topicname: msgtype, msgclass
        self.msg2obj = {}   # msgname: -> (rostype, rtmtype)

        return None
Exemple #14
0
def check_wpt_lint_errors():
    wpt_working_dir = os.path.abspath(os.path.join(".", "tests", "wpt", "web-platform-tests"))
    site.addsitedir(wpt_working_dir)
    from tools.lint import lint
    returncode = lint.main()
    if returncode:
        yield ("WPT Lint Tool", "", "lint error(s) in Web Platform Tests: exit status {0}".format(returncode))
Exemple #15
0
def setup(root=None, settings_module_name=None):
    """
    Simple setup snippet that makes easy to create
    fast sandbox to try new things.

    :param root: the root of your project
    :param settings_module_name: name of settings module eg:
         "project.setting"

    Usage:
    >>> import manage
    >>> manage.setup()
    >>> # from now on paths are setup, and django is configured
    >>> # you can use it in separate "sandbox" script just to check
    >>> # things really quick
    """
    from django.utils.importlib import import_module
    from django.core.management import setup_environ

    root = os.path.dirname(os.path.abspath(root or __file__))
    path = lambda *a: os.path.join(root, *a)
    settings_module_name = settings_module_name or 'settings'

    # 1) try to import module
    settings = import_module(settings_module_name)

    # 2) setup pythonpath
    if os.path.exists(path('lib')):
        site.addsitedir(path('lib'))

    # 2) cofigure django
    setup_environ(settings)

    return settings
Exemple #16
0
def add_virtualenv_path(venv):
    """Add virtualenv's site-packages to `sys.path`."""
    venv = os.path.abspath(venv)
    paths = glob.glob( os.path.join(
        venv, 'lib', 'python*', 'site-packages') )
    for path in paths:
        site.addsitedir(path)
Exemple #17
0
    def handle(self, *args, **options):
        from thepian.conf import import_structure

        structure = import_structure(os.getcwd())
        try:
            import django
        except ImportError:
            if structure.DEVELOPING:
                site.addsitedir(structure.LIB_DIR)
        import django
        from django.core.management.commands.makemessages import make_messages, handle_extensions

        if len(args) != 0:
            raise CommandError("Command doesn't accept any arguments")

        locale = options.get("locale")
        domain = options.get("domain")
        verbosity = int(options.get("verbosity"))
        process_all = options.get("all")
        extensions = options.get("extensions") or ["html"]

        if domain == "djangojs":
            extensions = []
        else:
            extensions = handle_extensions(extensions)

        if ".js" in extensions:
            raise CommandError("JavaScript files should be examined by using the special 'djangojs' domain only.")

        # old_cwd = os.getcwd()
        # os.chdir(os.path.dirname(django.__file__))
        make_messages(locale, domain, verbosity, process_all, extensions)
Exemple #18
0
def _site_packages():
    import site, sys, os
    paths = []
    prefixes = [sys.prefix]
    if sys.exec_prefix != sys.prefix:
        prefixes.append(sys.exec_prefix)
    for prefix in prefixes:
	if prefix == sys.prefix:
	    paths.append(os.path.join("/Library/Python", sys.version[:3], "site-packages"))
	    paths.append(os.path.join(sys.prefix, "Extras", "lib", "python"))
	else:
	    paths.append(os.path.join(prefix, 'lib', 'python' + sys.version[:3],
		'site-packages'))
    if os.path.join('.framework', '') in os.path.join(sys.prefix, ''):
        home = os.environ.get('HOME')
        if home:
            paths.append(os.path.join(home, 'Library', 'Python',
                sys.version[:3], 'site-packages'))

    # Work around for a misfeature in setuptools: easy_install.pth places
    # site-packages way to early on sys.path and that breaks py2app bundles.
    # NOTE: this is hacks into an undocumented feature of setuptools and
    # might stop to work without warning.
    sys.__egginsert = len(sys.path)

    for path in paths:
        site.addsitedir(path)
def _site_packages(prefix, real_prefix, global_site_packages):
    import site, sys, os
    paths = []
    prefixes = [sys.prefix]

    paths.append(os.path.join(prefix, 'lib', 'python' + sys.version[:3],
        'site-packages'))
    if os.path.join('.framework', '') in os.path.join(prefix, ''):
        home = os.environ.get('HOME')
        if home:
            paths.append(os.path.join(home, 'Library', 'Python',
                sys.version[:3], 'site-packages'))


    # Work around for a misfeature in setuptools: easy_install.pth places
    # site-packages way to early on sys.path and that breaks py2app bundles.
    # NOTE: this is hacks into an undocumented feature of setuptools and
    # might stop to work without warning.
    sys.__egginsert = len(sys.path)

    for path in paths:
        site.addsitedir(path)


    # Ensure that the global site packages get placed on sys.path after
    # the site packages from the virtual environment (this functionality
    # is also in virtualenv)
    sys.__egginsert = len(sys.path)

    if global_site_packages:
        site.addsitedir(os.path.join(real_prefix, 'lib', 'python' + sys.version[:3],
            'site-packages'))
def add(path, index=1):
  """Insert site dir or virtualenv at a given index in sys.path.

  Args:
    path: relative path to a site dir or virtualenv.
    index: sys.path position to insert the site dir.

  Raises:
    ValueError: path doesn't exist.
  """
  venv_path = os.path.join(path, 'lib', PYTHON_VERSION, 'site-packages')
  if os.path.isdir(venv_path):
    site_dir = venv_path
  elif os.path.isdir(path):
    site_dir = path
  else:
    raise ValueError('virtualenv: cannot access %s: '
                     'No such virtualenv or site directory' % path)



  sys_path = sys.path[:]
  del sys.path[index:]
  site.addsitedir(site_dir)
  sys.path.extend(sys_path[index:])
Exemple #21
0
	def addsitedir(d):
		try:
			d = os.path.normpath(d)
			d = os.path.abspath(d)
		except OSError: return
		if os.path.exists(d):
			site.addsitedir(d)
Exemple #22
0
def init_virtualenv():
    """Add a virtualenv to sys.path so the user can import modules from it.
    This isn't perfect: it doesn't use the Python interpreter with which the
    virtualenv was built, and it ignores the --no-site-packages option. A
    warning will appear suggesting the user installs IPython in the
    virtualenv, but for many cases, it probably works well enough.
    
    Adapted from code snippets online.
    
    http://blog.ufsoft.org/2009/1/29/ipython-and-virtualenv
    """
    if 'VIRTUAL_ENV' not in os.environ:
        # Not in a virtualenv
        return
    
    if sys.executable.startswith(os.environ['VIRTUAL_ENV']):
        # Running properly in the virtualenv, don't need to do anything
        return
    
    print ("Attempting to work in a virtualenv. If you encounter problems, please "
         "install lpct inside the virtualenv.")
    if sys.platform == "win32":
        virtual_env = os.path.join(os.environ['VIRTUAL_ENV'], 'Lib', 'site-packages') 
    else:
        virtual_env = os.path.join(os.environ['VIRTUAL_ENV'], 'lib',
                   'python%d.%d' % sys.version_info[:2], 'site-packages')
    
    import site
    sys.path.insert(0, virtual_env)
    site.addsitedir(virtual_env)
Exemple #23
0
def _activate_env_from_path(env_path):
    """ Fix when `activate_this.py` does not exist.

        For Python 3.3 and newer, a new command-line tool `pyvenv` create venv
        will not provide 'activate_this.py'.
    """
    prev_sys_path = list(sys.path)

    if sys.platform == 'win32':
        site_packages_paths = [os.path.join(env_path, 'Lib', 'site-packages')]
    else:
        lib_path = os.path.join(env_path, 'lib')
        site_packages_paths = [os.path.join(lib_path, lib, 'site-packages')
                               for lib in os.listdir(lib_path)]
    for site_packages_path in site_packages_paths:
        site.addsitedir(site_packages_path)

    sys.real_prefix = sys.prefix
    sys.prefix = env_path
    sys.exec_prefix = env_path

    # Move the added items to the front of the path:
    new_sys_path = []
    for item in list(sys.path):
        if item not in prev_sys_path:
            new_sys_path.append(item)
            sys.path.remove(item)
    sys.path[:0] = new_sys_path
Exemple #24
0
def application(environ, start_response):
    """
    Grap Environement vars and return class Django WSGI application.
    """
    if 'VIRTUALENV_PATH' in environ.keys():
        os.environ['VIRTUALENV_PATH'] = environ['VIRTUALENV_PATH']

    if 'DJANGO_SETTINGS_MODULE' in environ.keys():
        os.environ['DJANGO_SETTINGS_MODULE'] = \
            environ['DJANGO_SETTINGS_MODULE']

    ROOT = os.path.dirname(__file__)
    VIRTUALENV_PATH = os.environ['VIRTUALENV_PATH']

    version = 'python%s' % sys.version[0:3]

    site_packages = os.path.join(
        VIRTUALENV_PATH, 'lib', version, 'site-packages')
    site.addsitedir(site_packages)

    sys.path.append(ROOT)

    activate_this = os.path.join(
        VIRTUALENV_PATH, 'bin', 'activate_this.py')
    activate_env = os.path.expanduser(activate_this)
    execfile(activate_env, dict(__file__=activate_env))

    from django.core.wsgi import get_wsgi_application
    _wsgi_application = get_wsgi_application()
    return _wsgi_application(environ, start_response)
Exemple #25
0
def prependsitedir(projdir, *args):
    """
        like sys.addsitedir() but gives the added directory preference
        over system directories.  The paths will be normalized for dots and
        slash direction before being added to the path.

        projdir: the path you want to add to sys.path.  If its a
            a file, the parent directory will be added

        *args: additional directories relative to the projdir to add
            to sys.path.
    """
    # let the user be lazy and send a file, we will convert to parent directory
    # of file
    if path.isfile(projdir):
        projdir = path.dirname(projdir)

    projdir = path.abspath(projdir)

    # any args are considered paths that need to be joined to the
    # projdir to get to the correct directory.
    libpaths = []
    for lpath in args:
        libpaths.append(path.join(projdir, path.normpath(lpath)))

    # add the path to sys.path with preference over everything that currently
    # exists in sys.path
    syspath_orig = set(sys.path)
    site.addsitedir(projdir)
    for lpath in libpaths:
        site.addsitedir(lpath)
    syspath_after = set(sys.path)
    new_paths = list(syspath_after.difference(syspath_orig))
    sys.path = new_paths + sys.path
Exemple #26
0
def run_corrector(configs_dir, execution_home, cfg,
                ext_python_modules_home, log, to_correct, result):
    addsitedir(ext_python_modules_home)
    if sys.version.startswith('2.'):
        import pyyaml2 as pyyaml
    elif sys.version.startswith('3.'):
        import pyyaml3 as pyyaml

    dst_configs = os.path.join(cfg.output_dir, "configs")
    if os.path.exists(dst_configs):
        shutil.rmtree(dst_configs)
    dir_util.copy_tree(os.path.join(configs_dir, "corrector"), dst_configs, preserve_times=False)
    cfg_file_name = os.path.join(dst_configs, "corrector.info")

    cfg.tmp_dir = support.get_tmp_dir(prefix="corrector_")

    prepare_config_corr(cfg_file_name, cfg, ext_python_modules_home)
    binary_name = "corrector"

    command = [os.path.join(execution_home, binary_name),
               os.path.abspath(cfg_file_name), os.path.abspath(to_correct)]

    log.info("\n== Running contig polishing tool: " + ' '.join(command) + "\n")


    log.info("\n== Dataset description file was created: " + cfg_file_name + "\n")

    support.sys_call(command, log)
    if not os.path.isfile(result):
        support.error("Mismatch correction finished abnormally: " + result + " not found!")
    if os.path.isdir(cfg.tmp_dir):
        shutil.rmtree(cfg.tmp_dir)
Exemple #27
0
def add_vendor_lib():
    """
    Add the vendored dependencies to sys.path.

    Uses ``site.addsitedir`` so that pth files, if any, in the vendor lib will
    be processed.

    Places new path entries at the beginning of sys.path so system-installed
    libs can't shadow them and cause hard-to-debug problems.

    """
    old_sys_path = set(sys.path)

    vendor_dir = os.path.join(
        os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
        "vendor",
        )

    site.addsitedir(vendor_dir)

    new_sys_path = []
    for item in sys.path:
        if item not in old_sys_path:
            new_sys_path.append(item)
            sys.path.remove(item)

    sys.path[:0] = new_sys_path
Exemple #28
0
    def autoRegisterComponent (self, when, componentFile):
        # bool return
        
        # Check if we actually need to do anything
        modtime = componentFile.lastModifiedTime
        loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager)
        if not loader_mgr.hasFileChanged(componentFile, None, modtime):
            return 1

        if self.num_modules_this_register == 0:
            # New components may have just installed new Python
            # modules into the main python directory (including new .pth files)
            # So we ask Python to re-process our site directory.
            # Note that the pyloader does the equivalent when loading.
            try:
                from xpcom import _xpcom
                import site
                NS_XPCOM_CURRENT_PROCESS_DIR="XCurProcD"
                dirname = _xpcom.GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR)
                dirname.append("python")
                site.addsitedir(dirname.path)
            except:
                print "PyXPCOM loader failed to process site directory before component registration"
                traceback.print_exc()

        self.num_modules_this_register += 1

        # auto-register via the module.
        m = self._getCOMModuleForLocation(componentFile)
        m.registerSelf(components.manager, componentFile, None, self._reg_component_type_)
        loader_mgr = components.manager.queryInterface(components.interfaces.nsIComponentLoaderManager)
        loader_mgr.saveFileInfo(componentFile, None, modtime)
        return 1
Exemple #29
0
def _configure_syspath():
    """Add the vendored libraries into `sys.path`."""
    # Note: These paths will be inserted into `sys.path` in reverse order (LIFO)
    # So the last path on this list will be inserted as the first path on `sys.path`
    # right after the current working dir.
    # For example: [ cwd, pathN, ..., path1, path0, <rest_of_sys.path> ]

    paths_to_insert = [
        _get_lib_location(app.LIB_FOLDER),
        _get_lib_location(app.EXT_FOLDER)
    ]

    if sys.version_info[0] == 2:
        # Add Python 2-only vendored libraries
        paths_to_insert.extend([
            _get_lib_location(app.LIB2_FOLDER),
            _get_lib_location(app.EXT2_FOLDER)
        ])
    elif sys.version_info[0] == 3:
        # Add Python 3-only vendored libraries
        paths_to_insert.extend([
            _get_lib_location(app.LIB3_FOLDER),
            _get_lib_location(app.EXT3_FOLDER)
        ])

    # Insert paths into `sys.path` and handle `.pth` files
    # Inspired by: https://bugs.python.org/issue7744
    for dirpath in paths_to_insert:
        # Clear `sys.path`
        sys.path, remainder = sys.path[:1], sys.path[1:]
        # Add directory as a site-packages directory and handle `.pth` files
        site.addsitedir(dirpath)
        # Restore rest of `sys.path`
        sys.path.extend(remainder)
Exemple #30
0
def django_execute_from_command_line(argv=None):
    """
    A simple method that runs a ManagementUtility.
    """
    from os.path import realpath
    script_file_name=realpath((argv or sys.argv)[0])
    try:
        project_directory = find_basedir(os.getcwd())[1]
    except:
        #TODO exlude project based commands
        from os.path import dirname
        project_directory = dirname(dirname(script_file_name))
        
    from thepian.conf import structure, use_structure, use_default_structure
    structure.SCRIPT_PATH = script_file_name
    try:
        from os.path import join
        sys.path.insert(0,join(project_directory,"conf")) #TODO too simplistic, use real project tree
        import structure as conf_structure
        use_structure(conf_structure)
        site.addsitedir(structure.PYTHON_DIR)
    except ImportError:
        use_default_structure()

    structure.COMMAND_VARIABLE_PREFIX = "MAESTRO" 
    settings_module = determine_settings_module(argv or sys.argv)
    from thepian.conf import use_settings, settings
    use_settings(settings_module)

    import django.conf
    django.conf.settings.configure(**settings.__dict__)
    import django.core.management
    django.core.management.execute_from_command_line(argv)
Exemple #31
0
import argparse, os, tempfile
from collections import defaultdict

import matplotlib.pyplot as plt
import numpy as np
from scipy.misc import imresize, imsave, imread
from scipy.ndimage.filters import gaussian_filter

import os

os.environ['GLOG_minloglevel'] = '2'  # suprress Caffe verbose prints

import settings
import site

site.addsitedir(settings.caffe_root)
pycaffe_root = settings.caffe_root  # substitute your path here
sys.path.insert(0, pycaffe_root)
import caffe
import scipy.ndimage as nd
import scipy.misc
import scipy.io
import patchShow

import math
from numpy.linalg import norm

fc_layers = ["fc6", "fc7", "fc8", "loss3/classifier", "fc1000", "prob"]
conv_layers = ["conv1", "conv2", "conv3", "conv4", "conv5"]

matfile = scipy.io.loadmat('ilsvrc_2012_mean.mat')
Exemple #32
0
#!/usr/bin/env python
import os
import site
import sys


ROOT = os.path.dirname(os.path.abspath(__file__))
path = lambda *a: os.path.join(ROOT, *a)

prev_sys_path = list(sys.path)

site.addsitedir(path('apps'))
site.addsitedir(path('lib'))
site.addsitedir(path('vendor'))

# Move the new items to the front of sys.path.
new_sys_path = []
for item in list(sys.path):
    if item not in prev_sys_path:
        new_sys_path.append(item)
        sys.path.remove(item)
sys.path[:0] = new_sys_path

# Now we can import from third-party libraries.
from django.core.management import execute_manager, setup_environ

try:
    import settings_local as settings
except ImportError:
    try:
        import settings # Assumed to be in the same directory.
Exemple #33
0
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site

site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *


def main():
    PDFNet.Initialize()

    # Relative path to the folder containing the test files.
    input_path = "../../TestFiles/"
    output_path = "../../TestFiles/Output/"

    # The following sample illustrates how to read/write a PDF document from/to
    # a memory buffer.  This is useful for applications that work with dynamic PDF
    # documents that don't need to be saved/read from a disk.

    # Read a PDF document in a memory buffer.
    file = MappedFile(input_path + "tiger.pdf")
    file_sz = file.FileSize()

    file_reader = FilterReader(file)

    mem = file_reader.Read(file_sz)
    doc = PDFDoc(bytearray(mem), file_sz)
Exemple #34
0
import subprocess
import sysconfig
from copy import copy

# Need to make sure to not import 'site' if someone specified ``-S`` at the
# command-line.  Detect this by just making sure 'site' has not been imported
# already.
if "site" in sys.modules:
    import site
else:
    raise unittest.SkipTest("importation of site.py suppressed")

if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
    # need to add user site directory for tests
    os.makedirs(site.USER_SITE)
    site.addsitedir(site.USER_SITE)

class HelperFunctionsTests(unittest.TestCase):
    """Tests for helper functions.

    The setting of the encoding (set using sys.setdefaultencoding) used by
    the Unicode implementation is not tested.

    """

    def setUp(self):
        """Save a copy of sys.path"""
        self.sys_path = sys.path[:]
        self.old_base = site.USER_BASE
        self.old_site = site.USER_SITE
        self.old_prefixes = site.PREFIXES
Exemple #35
0
import unittest
import struct
import site
import sys
site.addsitedir('./src')  # Always appends to end
site.addsitedir('./modules')  # Always appends to end
site.addsitedir('./emu')  # Always appends to end
from scheduler import *


class TestScheduler(unittest.TestCase):
    def setUp(self):
        pass

    def test_a(self):
        self.assertEqual(0, 0)


if __name__ == '__main__':
    unittest.main()
Exemple #36
0
 it under the terms of the GNU Lesser General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 pycotools is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Lesser General Public License for more details.
 You should have received a copy of the GNU Lesser General Public License
 along with pycotools.  If not, see <http://www.gnu.org/licenses/>.
Author:
    Ciaran Welsh
Date:
    19-08-2017
 '''
import site
site.addsitedir('/home/b3053674/Documents/pycotools')
# site.addsitedir('C:\Users\Ciaran\Documents\pycotools')

import pycotools
import test_models
import unittest
import glob
import os
import shutil 
import pandas
from pycotools.Tests import _test_base
from lxml import etree


class DeterministicTimeCourseTests(_test_base._BaseTest):
    def setUp(self):
Exemple #37
0
from manual.biped.mirrorTemplateJoints import *
from manual.biped.bipedRig import *
from manual.biped.extraJoint import *
from manual.biped.extraRig import *
from manual.biped.addLocalSpacetoHandSub import *
from manual.biped.poleVec_fix import *
from manual.biped.addRigCommand import *

from util.zeroOut import *
from util.controller import *
from util.undoCommand import undo

import json
import sys
import site
site.addsitedir('/dexter/Cache_DATA/CRT/RiggingRnD/Quadruped/script')
import tuple as TP
reload(TP)

from Qt import QtGui, QtCore, QtWidgets, load_ui
from Qt.QtGui import *
from Qt.QtCore import *
from Qt.QtWidgets import *

import xml.etree.ElementTree as xml
from cStringIO import StringIO

basePath = os.path.abspath(__file__ + '/../')
#print basePath
uiFile = os.path.join(basePath, 'bumbleBee.ui')
#print uiFile
Exemple #38
0
"""
WSGI config for kasse project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""

import os
import sys
import site

prev_sys_path = list(sys.path)
site.addsitedir(
    '/home/rav/enkasseienfestforening.dk/venv/lib/python3.4/site-packages')
sys.path.append('/home/rav/enkasseienfestforening.dk/kasse')
# reorder sys.path so new directories from the addsitedir show up first
new_sys_path = [p for p in sys.path if p not in prev_sys_path]
for item in new_sys_path:
    sys.path.remove(item)
sys.path[:0] = new_sys_path

from django.core.wsgi import get_wsgi_application  # NOQA

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kasse.settings")

application = get_wsgi_application()
Exemple #39
0
import os
import sys
import site

PROJECT_ROOT = '/srv/www/royrvik.org/new-website/pwebsite/'
site_packages = os.path.join(PROJECT_ROOT,
                             '../env/lib/python2.7/site-packages')
site.addsitedir(os.path.abspath(site_packages))
sys.path.insert(0, site_packages)
sys.path.insert(0, PROJECT_ROOT)
os.environ['DJANGO_SETTINGS_MODULE'] = 'pwebsite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Exemple #40
0
def get_mdns_services():
    try:
        import zeroconf
    except ImportError:
        from site import addsitedir
        from platformio.managers.core import get_core_package_dir
        contrib_pysite_dir = get_core_package_dir("contrib-pysite")
        addsitedir(contrib_pysite_dir)
        sys.path.insert(0, contrib_pysite_dir)
        import zeroconf

    class mDNSListener(object):

        def __init__(self):
            self._zc = zeroconf.Zeroconf(
                interfaces=zeroconf.InterfaceChoice.All)
            self._found_types = []
            self._found_services = []

        def __enter__(self):
            zeroconf.ServiceBrowser(self._zc, "_services._dns-sd._udp.local.",
                                    self)
            return self

        def __exit__(self, etype, value, traceback):
            self._zc.close()

        def remove_service(self, zc, type_, name):
            pass

        def add_service(self, zc, type_, name):
            try:
                assert zeroconf.service_type_name(name)
                assert str(name)
            except (AssertionError, UnicodeError,
                    zeroconf.BadTypeInNameException):
                return
            if name not in self._found_types:
                self._found_types.append(name)
                zeroconf.ServiceBrowser(self._zc, name, self)
            if type_ in self._found_types:
                s = zc.get_service_info(type_, name)
                if s:
                    self._found_services.append(s)

        def get_services(self):
            return self._found_services

    items = []
    with mDNSListener() as mdns:
        time.sleep(3)
        for service in mdns.get_services():
            properties = None
            try:
                if service.properties:
                    json.dumps(service.properties)
                properties = service.properties
            except UnicodeDecodeError:
                pass

            items.append({
                "type": service.type,
                "name": service.name,
                "ip": ".".join([str(ord(c)) for c in service.address]),
                "port": service.port,
                "properties": properties
            })
    return items
#!/usr/bin/env python
import site
import os
import logging
import argparse
import json
import hashlib
import requests
import tempfile
from boto.s3.connection import S3Connection
from mardor.reader import MarReader
from mardor.signing import get_keysize

site.addsitedir("/home/worker/tools/lib/python")

from balrog.submitter.cli import NightlySubmitterV4, ReleaseSubmitterV4
from util.retry import retry, retriable

log = logging.getLogger(__name__)


def get_hash(content, hash_type="md5"):
    h = hashlib.new(hash_type)
    h.update(content)
    return h.hexdigest()


@retriable()
def download(url, dest, mode=None):
    log.debug("Downloading %s to %s", url, dest)
    r = requests.get(url)
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Packages the platform's RenderScript for the NDK."""
import os
import shutil
import site
import subprocess
import sys

site.addsitedir(os.path.join(os.path.dirname(__file__), '../lib'))

import build_support  # pylint: disable=import-error


def get_rs_prebuilt_path(host):
    rel_prebuilt_path = 'prebuilts/renderscript/host/{}'.format(host)
    prebuilt_path = os.path.join(build_support.android_path(),
                                 rel_prebuilt_path)
    if not os.path.isdir(prebuilt_path):
        sys.exit(
            'Could not find prebuilt RenderScript at {}'.format(prebuilt_path))
    return prebuilt_path


def main(args):
Exemple #43
0
'''
Created on my MAC Sep 13, 2015-10:42:11 PM
What I do:
    I fetch results from tie-yan's LDA
What's my input:
    TargetDocNo
    Dir of DocNo-> URL mapping
    Dir of raw results (.xx xx is block number)
What's my output:
    a file of docno \t text
     only keep target doc
@author: chenyanxiong
'''

import site
site.addsitedir('/bos/usr0/cx/PyCode/cxPyLib')
site.addsitedir('/bos/usr0/cx/PyCode/GoogleAPI')

from cxBase.WalkDirectory import WalkDir
from cxBase.Conf import cxConfC


def LoadTargetUrl(InDir, sDocNo):
    hUrlDocNo = {}
    lFName = WalkDir(InDir)
    for fname in lFName:
        for line in open(fname):
            vCol = line.strip().split('\t')
            if len(vCol) < 2:
                continue
            DocNo, Url = vCol[:2]
Exemple #44
0
import os
import site
import unittest
from unittest import TestLoader

if __name__ == '__main__':
    site.addsitedir('src')
    suite = TestLoader().discover(f'{os.path.abspath("./tests")}')
    runner = unittest.TextTestRunner(verbosity=2)
    os.chdir("tests")
    result = runner.run(suite)
    assert result.wasSuccessful()
Exemple #45
0
import sys
import os
import site

this_dir = os.path.dirname(os.path.abspath(__file__))

site.addsitedir(this_dir + '-venv-python3.7/lib/python3.7/site-packages')

# make sure this directory is in sys.path (.lower() avoids duplicate entries in windows)
if not (this_dir in sys.path or this_dir.lower() in sys.path):
    sys.path.insert(0, this_dir)

wiki_config = this_dir + '/wikiconfig_local.py'
if not os.path.exists(wiki_config):
    wiki_config = this_dir + '/wikiconfig.py'

# application is the Flask application
from moin.app import create_app
application = create_app(wiki_config)
#Embedded file name: iconrendering\_appsetup.py
"""Import this in your test packages to append packages to the sys path."""
import os
import sys
import site
pkgspath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
site.addsitedir(pkgspath)
rootpath = os.path.abspath(os.path.join(pkgspath, '..'))
if rootpath not in sys.path:
    sys.path.append(rootpath)
import binbootstrapper
binbootstrapper.update_binaries(__file__, *binbootstrapper.DLLS_GRAPHICS)
import trinity
from binbootstrapper.trinityapp import create_windowless_device


def CreateTrinityApp():
    create_windowless_device()
    trinity.device.animationTimeScale = 0.0
Exemple #47
0
import site
import os
import json
from os.path import dirname, join
import pytest
from importlib import import_module
import requests_mock
from datetime import datetime, timedelta
from pytz import timezone
from mock import patch
import unittest
from freezegun import freeze_time
import copy

site.addsitedir(join(dirname(dirname(__file__)), "functions"))

downloader = import_module("zoom-downloader")
downloader.DOWNLOAD_MESSAGES_PER_INVOCATION = 10
downloader.CLASS_SCHEDULE_TABLE = "mock-schedule-table"

LOCAL_TIME_ZONE = os.getenv("LOCAL_TIME_ZONE")
TIMESTAMP_FORMAT = os.getenv("TIMESTAMP_FORMAT")

tz = timezone(LOCAL_TIME_ZONE)
utc_now = datetime.utcnow().replace(tzinfo=timezone("UTC"))
FROZEN_TIME_UTC = datetime.strftime(utc_now, TIMESTAMP_FORMAT)
FROZEN_TIME = datetime.strftime(utc_now.astimezone(tz), TIMESTAMP_FORMAT)

SAMPLE_MESSAGE_BODY = {
    "zip_id": "abc",
    "duration": 30,
#!/usr/bin/env python

import urllib2, urllib, sys, collections, re, os, site, datetime

local_site = os.path.join(os.path.dirname(__file__), "..", "..", "..")
site.addsitedir(local_site)

from optparse import OptionParser
import simplejson as json
import pprint
from openlibrary.api import OpenLibrary

NYT_BEST_SELLERS_URL = "http://api.nytimes.com/svc/books/v2/lists"


def LOG(level, msg):
    print >> sys.stderr, "%s: %s" % (level, msg.encode('utf-8'))


def _request(request, parser=json.loads):
    request = (urllib2.Request(
        request, None, headers={"Referrer": "http://www.openlibrary.org"})
               if isinstance(request, basestring) else request)
    results = None
    conn = urllib2.urlopen(request)
    try:
        results = conn.read()
        results = unicode(results, 'utf-8')
        results = parser(results)
    except Exception, e:
        LOG("ERROR",
"""
WSGI config for loteriamovil project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
"""
import os, sys, site

# Add the site-packages of the chosen virtualenv to work with
site.addsitedir(
    '/home/ubuntu/proyects/loteriamovil/lib/python2.7/site-packages')
# cambiar aca
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/ubuntu/proyects/loteriamovil/lib/python2.7')
sys.path.append('/home/ubuntu/proyects/loteriamovil')
sys.path.append('/home/ubuntu/proyects/loteriamovil/src')

os.environ['DJANGO_SETTINGS_MODULE'] = "agencia24.settings_pwa_sc"

if os.getenv('HOME') == '/home/ubuntu':
    # Activate your virtual env
    activate_env = "/home/ubuntu/proyects/loteriamovil/bin/activate_this.py"

    execfile(activate_env, dict(__file__=activate_env))

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()
Exemple #50
0
#!/usr/bin/python
import os, sys, cgi, json, site

site.addsitedir(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../core'))

from db.mapper import Pins, Clusters

if 'QUERY_STRING' in os.environ:
    query = cgi.parse_qs(os.environ['QUERY_STRING'])
else:
    query = {}

clusters = Clusters()
pins = clusters.get_top_matches(query['pin_id'][0], 50, 0.5)
res = [{'score':str(pin[0]), 'uri':str(pin[2]), 'pin_id': str(pin[3])} for pin in pins]

print "Content-Type: text/json\n\n"
print json.dumps(res)
Exemple #51
0
def main():
    global app

    # set thread name
    threading.currentThread().setName('MAIN')

    # fix threading time bug
    time.strptime("2012", "%Y")

    # add sickrage libs path to python system path
    if not (LIBS_DIR in sys.path):
        sys.path, remainder = sys.path[:1], sys.path[1:]
        site.addsitedir(LIBS_DIR)
        sys.path.extend(remainder)

    # set system default language
    gettext.install('messages',
                    LOCALE_DIR,
                    codeset='UTF-8',
                    names=["ngettext"])

    try:
        from sickrage.core import Core

        # main app instance
        app = Core()

        # sickrage startup options
        parser = argparse.ArgumentParser(prog='sickrage')
        parser.add_argument('-v',
                            '--version',
                            action='version',
                            version='%(prog)s {}'.format(version()))
        parser.add_argument('-d',
                            '--daemon',
                            action='store_true',
                            help='Run as a daemon (*NIX ONLY)')
        parser.add_argument('-q',
                            '--quiet',
                            action='store_true',
                            help='Disables logging to CONSOLE')
        parser.add_argument(
            '-p',
            '--port',
            default=0,
            type=int,
            help='Override default/configured port to listen on')
        parser.add_argument(
            '-H',
            '--host',
            default='',
            help='Override default/configured host to listen on')
        parser.add_argument('--dev',
                            action='store_true',
                            help='Enable developer mode')
        parser.add_argument('--debug',
                            action='store_true',
                            help='Enable debugging')
        parser.add_argument(
            '--datadir',
            default=os.path.abspath(
                os.path.join(os.path.expanduser("~"), '.sickrage')),
            help=
            'Overrides data folder for database, config, cache and logs (specify full path)'
        )
        parser.add_argument(
            '--config',
            default='config.ini',
            help=
            'Overrides config filename (specify full path and filename if outside datadir path)'
        )
        parser.add_argument(
            '--pidfile',
            default='sickrage.pid',
            help=
            'Creates a PID file (specify full path and filename if outside datadir path)'
        )
        parser.add_argument('--nolaunch',
                            action='store_true',
                            help='Suppress launching web browser on startup')
        parser.add_argument('--db_type',
                            default='sqlite',
                            help='Database type: sqlite or mysql')
        parser.add_argument(
            '--db_prefix',
            default='sickrage',
            help='Database prefix you want prepended to database table names')
        parser.add_argument('--db_host',
                            default='localhost',
                            help='Database hostname (not used for sqlite)')
        parser.add_argument('--db_port',
                            default='3306',
                            help='Database port number (not used for sqlite)')
        parser.add_argument('--db_username',
                            default='sickrage',
                            help='Database username (not used for sqlite)')
        parser.add_argument('--db_password',
                            default='sickrage',
                            help='Database password (not used for sqlite)')

        # Parse startup args
        args = parser.parse_args()
        app.quiet = args.quiet
        app.web_port = int(args.port)
        app.web_host = args.host
        app.no_launch = args.nolaunch
        app.developer = args.dev
        app.db_type = args.db_type
        app.db_prefix = args.db_prefix
        app.db_host = args.db_host
        app.db_port = args.db_port
        app.db_username = args.db_username
        app.db_password = args.db_password
        app.debug = args.debug
        app.data_dir = os.path.abspath(
            os.path.realpath(os.path.expanduser(args.datadir)))
        app.cache_dir = os.path.abspath(
            os.path.realpath(os.path.join(app.data_dir, 'cache')))
        app.config_file = args.config
        daemonize = (False, args.daemon)[not sys.platform == 'win32']
        pid_file = args.pidfile

        if not os.path.isabs(app.config_file):
            app.config_file = os.path.join(app.data_dir, app.config_file)

        if not os.path.isabs(pid_file):
            pid_file = os.path.join(app.data_dir, pid_file)

        # check lib requirements
        check_requirements()

        # add sickrage module to python system path
        if not (PROG_DIR in sys.path):
            sys.path, remainder = sys.path[:1], sys.path[1:]
            site.addsitedir(PROG_DIR)
            sys.path.extend(remainder)

        # Make sure that we can create the data dir
        if not os.access(app.data_dir, os.F_OK):
            try:
                os.makedirs(app.data_dir, 0o744)
            except os.error:
                sys.exit("Unable to create data directory '" + app.data_dir +
                         "'")

        # Make sure we can write to the data dir
        if not os.access(app.data_dir, os.W_OK):
            sys.exit("Data directory must be writeable '" + app.data_dir + "'")

        # Make sure that we can create the cache dir
        if not os.access(app.cache_dir, os.F_OK):
            try:
                os.makedirs(app.cache_dir, 0o744)
            except os.error:
                sys.exit("Unable to create cache directory '" + app.cache_dir +
                         "'")

        # Make sure we can write to the cache dir
        if not os.access(app.cache_dir, os.W_OK):
            sys.exit("Cache directory must be writeable '" + app.cache_dir +
                     "'")

        # daemonize if requested
        if daemonize:
            app.no_launch = True
            app.quiet = True
            app.daemon = Daemon(pid_file, app.data_dir)
            app.daemon.daemonize()
            app.pid = app.daemon.pid

        # start app
        app.start()
    except (SystemExit, KeyboardInterrupt):
        if app:
            app.shutdown()
    except Exception as e:
        traceback.print_exc()
Exemple #52
0
from site import addsitedir

import spades_init

spades_init.init()
spades_home = spades_init.spades_home
bin_home = spades_init.bin_home
python_modules_home = spades_init.python_modules_home
ext_python_modules_home = spades_init.ext_python_modules_home
spades_version = spades_init.spades_version

import support

support.check_python_version()

addsitedir(ext_python_modules_home)
if sys.version.startswith("2."):
    import pyyaml2 as pyyaml
elif sys.version.startswith("3."):
    import pyyaml3 as pyyaml
import options_storage
options_storage.spades_version = spades_version

import options_parser
from stages.pipeline import Pipeline
import executor_local
import executor_save_yaml


def print_used_values(cfg, log):
    def print_value(cfg, section, param, pretty_param="", margin="  "):
Exemple #53
0
def add_path_first(path):
    sys.path = [path] + [
        p for p in sys.path if (not p == path and not p == (path + '/'))
    ]
    if not global_settings.web2py_runtime_gae:
        site.addsitedir(path)
Exemple #54
0
import shutil
import getopt
import re

from libs import qconfig
qconfig.check_python_version()

from libs import qutils, fastaparser, reads_analyzer
from libs.qutils import assert_file_exists

from libs.log import get_logger
logger = get_logger(qconfig.LOGGER_DEFAULT_NAME)
logger.set_up_console_handler()

from site import addsitedir
addsitedir(os.path.join(qconfig.LIBS_LOCATION, 'site_packages'))
is_combined_ref = False


def _set_up_output_dir(output_dirpath, json_outputpath, make_latest_symlink,
                       save_json):
    existing_alignments = False

    if output_dirpath:  # 'output dir was specified with -o option'
        if os.path.isdir(output_dirpath):
            existing_alignments = True
    else:  # output dir was not specified, creating our own one
        output_dirpath = os.path.join(
            os.path.abspath(qconfig.default_results_root_dirname),
            qconfig.output_dirname)
Exemple #55
0
# ##############################################################################

import gettext
import os
import os.path
import shutil
import site
import sys
import threading
import unittest

PROG_DIR = os.path.abspath(
    os.path.join(os.path.dirname(__file__), os.pardir, 'sickrage'))
if not (PROG_DIR in sys.path):
    sys.path, remainder = sys.path[:1], sys.path[1:]
    site.addsitedir(PROG_DIR)
    sys.path.extend(remainder)

LIBS_DIR = os.path.join(PROG_DIR, 'libs')
if not (LIBS_DIR in sys.path):
    sys.path, remainder = sys.path[:1], sys.path[1:]
    site.addsitedir(LIBS_DIR)
    sys.path.extend(remainder)

LOCALE_DIR = os.path.join(PROG_DIR, 'locale')
gettext.install('messages', LOCALE_DIR, codeset='UTF-8', names=["ngettext"])

import sickrage

from sickrage.core.tv import episode
from sickrage.core import Core, Config, NameCache, Logger
from distutils import sysconfig
import site

site.addsitedir(sysconfig.get_python_lib(prefix='/app'))
from __future__ import division
import h5py
import glob
from matplotlib import pyplot as plt
import site
site.addsitedir('../src')
from reproject import reproj_L1B
from matplotlib.colors import Normalize
from matplotlib import cm
import numpy as np
from mpl_toolkits.basemap import Basemap
import bitmap


def make_plot(lcc_values):
    """
      set up the basic map projection details with coastlines and meridians
      return the projection object for further plotting
    """
    proj = Basemap(**lcc_values)
    parallels = np.arange(-90, 90, 1)
    meridians = np.arange(0, 360, 2)
    proj.drawparallels(parallels, labels=[1, 0, 0, 0], fontsize=10, latmax=90)
    proj.drawmeridians(meridians, labels=[0, 0, 0, 1], fontsize=10, latmax=90)
    # draw coast & fill continents
    # map.fillcontinents(color=[0.25, 0.25, 0.25], lake_color=None) # coral
    proj.drawcoastlines(linewidth=3., linestyle='solid', color='r')
    return proj


def find_corners(lons, lats):
  read the level1b file and the cloud mask file from dump_cloudmask.py and
  produce plots of the chan31 radiance, channel 1 reflectance,
  cloud mask and landmask

  usage:

  ./plot_cloudmask.py MYD021KM.*35*.h5 MYD021KM.*35*.h5 MYD35*.35*.h5  MYD35*.40*.h5  mask_*35*.h5  mask_*40*.h5 

"""
from __future__ import division
import argparse
import h5py
import glob
from matplotlib import pyplot as plt
import site
site.addsitedir('../utilities')
from reproject import reproj_numba
import planck
import io,json
from collections import OrderedDict as od

#
# compat module redefines importlib.reload if we're
# running python3
#
from compat import cpreload as reload
reload(planck)
from planck import planckInvert
from mpl_toolkits.basemap import Basemap
from matplotlib.colors import Normalize
from matplotlib import cm
def load_venv(venv_dir):
    venv_dir = os.path.abspath(venv_dir)

    # Check if we are already inside the virtual environment
    # return (hasattr(sys, 'real_prefix')
    #         or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix))
    print("Loading virtual environment from: %s" % venv_dir)

    # Since activate_this.py is no longer available in python3's default venv support,
    # we bring its functionality into this load_env module
    # activate_this_file = venv_dir + "/bin/activate_this.py"
    # The execfile API is for Python 2. We keep here just in case you are on an
    # obscure system without Python 3
    # execfile(activate_this_file, dict(__file__=activate_this_file))
    # exec(
    #     compile(
    #         open(activate_this_file, "rb").read(), activate_this_file, 'exec'),
    #     dict(__file__=activate_this_file))
    # exec(open(activate_this_file).read(), {'__file__': activate_this_file})

    if (platform.system() == "Windows"):
        bin_dir = os.path.join(venv_dir, "Scripts")
        base = bin_dir[:-len(
            "Scripts"
        ) - 1]  # strip away the bin part from the __file__, plus the path separator
    else:
        bin_dir = os.path.join(venv_dir, "bin")
        base = bin_dir[:-len(
            "bin"
        ) - 1]  # strip away the bin part from the __file__, plus the path separator

    # prepend bin to PATH (this file is inside the bin directory)
    os.environ["PATH"] = os.pathsep.join(
        [bin_dir] + os.environ.get("PATH", "").split(os.pathsep))
    os.environ[
        "VIRTUAL_ENV"] = base  # virtual env is right above bin directory

    import site

    # add the virtual environments libraries to the host python import mechanism
    prev_length = len(sys.path)
    if (platform.system() == 'Windows'):
        for lib in ("../Lib/site-packages").split(os.pathsep):
            path = os.path.realpath(os.path.join(bin_dir, lib))
            site.addsitedir(path.decode("utf-8") if "" else path)
    else:
        for lib in ("../lib/python3." + str(sys.version_info.minor) +
                    "/site-packages").split(os.pathsep):
            path = os.path.realpath(os.path.join(bin_dir, lib))
            site.addsitedir(path.decode("utf-8") if "" else path)
    sys.path[:] = sys.path[prev_length:] + sys.path[0:prev_length]

    sys.real_prefix = sys.prefix
    sys.prefix = base

    # excluding system-wide site-packages paths as they interfere when
    # venv tensorflow version is different from system-wide tensorflow version
    sys_paths = [_p for _p in sys.path if "site-packages" in _p]
    sys_paths = [_p for _p in sys_paths if "venv-tf-py3" not in _p]
    for _p in sys_paths:
        sys.path.remove(_p)

    # ignore site-package installations in user-space
    import site
    site.ENABLE_USER_SITE = False

    return venv_dir
Exemple #60
0
#
#   Project: FlexTools
#   Module:  FTPaths
#
#   Global definitions of data paths for FLExTools
#
#   Craig Farrow
#   Mar 2012
#

import os

# Make sure FlexLibs & CDFUtils are on the path (using .pth file in ..\)

import site
site.addsitedir(os.path.join(os.path.dirname(__file__), u"..\\"))

# Create absolute paths relative to this directory (where this file resides)

MODULES_PATH = os.path.join(os.path.dirname(__file__), u"Modules")
COLLECTIONS_PATH = os.path.join(os.path.dirname(__file__), u"Collections")
CONFIG_PATH = os.path.join(os.path.dirname(__file__), "flextools.ini")