def handler(req): global _first try: _first_lock.acquire() if _first: _first = False options = req.get_options() egg_cache = options.get("PYTHON_EGG_CACHE") if not egg_cache and options.get("TracEnv"): egg_cache = os.path.join(options.get("TracEnv"), ".egg-cache") if not egg_cache and options.get("TracEnvParentDir"): egg_cache = os.path.join(options.get("TracEnvParentDir"), ".egg-cache") if not egg_cache and req.subprocess_env.get("PYTHON_EGG_CACHE"): egg_cache = req.subprocess_env.get("PYTHON_EGG_CACHE") if egg_cache: pkg_resources.set_extraction_path(egg_cache) reload(sys.modules["trac.web"]) finally: _first_lock.release() pkg_resources.require("Trac==%s" % VERSION) gateway = ModPythonGateway(req, req.get_options()) from trac.web.main import dispatch_request gateway.run(dispatch_request) return apache.OK
def _setup_pkgresources(): import pkg_resources import os, plistlib pl = plistlib.readPlist( os.path.join(os.path.dirname(os.getenv('RESOURCEPATH')), "Info.plist")) appname = pl.get('CFBundleIdentifier') if appname is None: appname = pl['CFBundleDisplayName'] path = os.path.expanduser('~/Library/Caches/%s/python-eggs' % (appname, )) pkg_resources.set_extraction_path(path)
def _setup_pkgresources(): import pkg_resources import os, plistlib pl = plistlib.readPlist(os.path.join( os.path.dirname(os.getenv('RESOURCEPATH')), "Info.plist")) appname = pl.get('CFBundleIdentifier') if appname is None: appname = pl['CFBundleDisplayName'] path = os.path.expanduser('~/Library/Caches/%s/python-eggs'%(appname,)) pkg_resources.set_extraction_path(path)
def __init__(self, dataset_path=None, tmp_dir=None, rpc_port=None, native_transport_port=None, cassandra_yaml_options=None): self._dataset = self._parse_dataset_file_path(dataset_path) self.tmp_dir = tmp_dir or self._find_tmp_dir() self._create_tmp_dir() pkg_resources.set_extraction_path(self.tmp_dir) self._here = lambda x: pkg_resources.resource_filename('pysandraunit', x) self.rpc_port = rpc_port or _DEFAULT_RPC_PORT self.native_transport_port = native_transport_port or _DEFAULT_NATIVE_TRANSPORT_PORT self._cassandra_yaml = self._get_yaml_file(cassandra_yaml_options)
def ensure_extraction_dir(): """Set a safe extraction dir (the default is unsafe) for runfiles during bundling.""" if not is_bundled(): return global _extraction_dir_set # pylint: disable=global-statement if not _extraction_dir_set: _extraction_dir_set = True extraction_tmpdir = tempfile.mkdtemp() atexit.register( lambda: shutil.rmtree(extraction_tmpdir, ignore_errors=True)) import pkg_resources pkg_resources.set_extraction_path(extraction_tmpdir)
def _setup_pkgresources(): import os import plistlib import pkg_resources # noqa: I251 with open( os.path.join(os.path.dirname(os.getenv("RESOURCEPATH")), "Info.plist"), "rb") as fp: pl = plistlib.load(fp) appname = pl.get("CFBundleIdentifier") if appname is None: appname = pl["CFBundleDisplayName"] path = os.path.expanduser(f"~/Library/Caches/{appname}/python-eggs") pkg_resources.set_extraction_path(path)
def handler(req): global _first with _first_lock: if _first: _first = False options = req.get_options() egg_cache = options.get('PYTHON_EGG_CACHE') if not egg_cache and options.get('TracEnv'): egg_cache = os.path.join(options.get('TracEnv'), '.egg-cache') if not egg_cache and options.get('TracEnvParentDir'): egg_cache = os.path.join(options.get('TracEnvParentDir'), '.egg-cache') if not egg_cache and req.subprocess_env.get('PYTHON_EGG_CACHE'): egg_cache = req.subprocess_env.get('PYTHON_EGG_CACHE') if egg_cache: pkg_resources.set_extraction_path(egg_cache) reload(sys.modules['trac.web']) pkg_resources.require('Trac==%s' % VERSION) gateway = ModPythonGateway(req, req.get_options()) from trac.web.main import dispatch_request gateway.run(dispatch_request) return apache.OK
def installDefaultTemplates(self, symlink=False): dest = str(self.config.template_dir / 'default/templates/') + '/' src = pkg_resources.resource_filename(APP, 'default/templates/') if src != dest: dest_p = Path(dest) if dest_p.exists(): if dest_p.is_symlink(): dest_p.unlink() else: from distutils.dir_util import remove_tree remove_tree(dest) if symlink: dest_p.parent.mkdir(parents=True, exist_ok=True) dest_p.symlink_to(src) else: from distutils.dir_util import copy_tree self.config.template_dir.mkdir(parents=True, exist_ok=True) pkg_resources.set_extraction_path(self.config.template_dir) copy_tree(src, dest) return dest
def handler(req): global _first, _first_lock try: _first_lock.acquire() if _first: _first = False options = req.get_options() egg_cache = options.get('PYTHON_EGG_CACHE') if not egg_cache and options.get('TracEnv'): egg_cache = os.path.join(options.get('TracEnv'), '.egg-cache') if not egg_cache and options.get('TracEnvParentDir'): egg_cache = os.path.join(options.get('TracEnvParentDir'), '.egg-cache') if not egg_cache and req.subprocess_env.get('PYTHON_EGG_CACHE'): egg_cache = req.subprocess_env.get('PYTHON_EGG_CACHE') if egg_cache: pkg_resources.set_extraction_path(egg_cache) reload(sys.modules['trac.web']) finally: _first_lock.release() gateway = ModPythonGateway(req, req.get_options()) gateway.run(dispatch_request) return apache.OK
def extract_packages(package_names): """Extract zipfile contents to disk and add to import path""" # Set a safe extraction dir extraction_tmpdir = tempfile.mkdtemp() atexit.register(lambda: shutil.rmtree( extraction_tmpdir, ignore_errors=True)) pkg_resources.set_extraction_path(extraction_tmpdir) # Extract each package to disk dirs_to_add = [] for package_name in package_names: req = pkg_resources.Requirement.parse(package_name) extraction_dir = pkg_resources.resource_filename(req, '') dirs_to_add.append(extraction_dir) # Add extracted directories to import path ahead of their zip file # counterparts. sys.path[0:0] = dirs_to_add existing_pythonpath = os.environ.get('PYTHONPATH') if existing_pythonpath: dirs_to_add.extend(existing_pythonpath.split(':')) os.environ['PYTHONPATH'] = ':'.join(dirs_to_add)
def _setup_pkgresources(): import pkg_resources import os import plistlib if hasattr(plistlib, 'load'): with open( os.path.join(os.path.dirname(os.getenv('RESOURCEPATH')), "Info.plist"), 'rb') as fp: pl = plistlib.load(fp) else: #2.7 pl = plistlib.readPlist( os.path.join(os.path.dirname(os.getenv('RESOURCEPATH')), "Info.plist")) appname = pl.get('CFBundleIdentifier') if appname is None: appname = pl['CFBundleDisplayName'] path = os.path.expanduser('~/Library/Caches/%s/python-eggs' % (appname, )) pkg_resources.set_extraction_path(path)
def _extract_packages(package_names): """Extract zipfile contents to disk and add to import path""" # Set a safe extraction dir extraction_tmpdir = tempfile.mkdtemp() atexit.register( lambda: shutil.rmtree(extraction_tmpdir, ignore_errors=True)) pkg_resources.set_extraction_path(extraction_tmpdir) # Extract each package to disk dirs_to_add = [] for package_name in package_names: req = pkg_resources.Requirement.parse(package_name) extraction_dir = pkg_resources.resource_filename(req, '') dirs_to_add.append(extraction_dir) # Add extracted directories to import path ahead of their zip file # counterparts. sys.path[0:0] = dirs_to_add existing_pythonpath = os.environ.get('PYTHONPATH') if existing_pythonpath: dirs_to_add.extend(existing_pythonpath.split(':')) os.environ['PYTHONPATH'] = ':'.join(dirs_to_add)
def _setup_pkgresources(): import os import plistlib import pkg_resources if hasattr(plistlib, "load"): with open( os.path.join(os.path.dirname(os.getenv("RESOURCEPATH")), "Info.plist"), "rb") as fp: pl = plistlib.load(fp) else: # 2.7 pl = plistlib.readPlist( os.path.join(os.path.dirname(os.getenv("RESOURCEPATH")), "Info.plist")) appname = pl.get("CFBundleIdentifier") if appname is None: appname = pl["CFBundleDisplayName"] path = os.path.expanduser("~/Library/Caches/%s/python-eggs" % (appname, )) pkg_resources.set_extraction_path(path)
def __call__(self): # Setuptools has a few race conditions when two or more processes load eggs at exactly the same time # The following fix makes sure that each process uses a unique extraction place try: path = tempfile.mkdtemp(prefix="worker-", dir=self.scratch_dir) # If using setuptools set the temp egg cache to be in the temp dir import pkg_resources pkg_resources.set_extraction_path(path) except (ImportError, ValueError): # Ignore any failures patching setuptools. There is not much more we can do. pass # Add the session directory to sys.path so that downloaded dependencies are visible sys.path.append(self.dep_dir) # Add the current actual working dir to sys path in case we are running a private cluster sys.path.append(os.getcwd()) # Change to the proper working dir os.chdir(self.work_dir) if self.callback is not None: self.callback()
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import tempfile import pkg_resources import atexit import logging import os import sys log = logging.getLogger(__name__) try: egg_cache_dir = tempfile.mkdtemp() pkg_resources.set_extraction_path(egg_cache_dir) except ValueError: # If the path is already set the module throw an error pass @atexit.register def clean_egg_cache(): try: import shutil log.debug("Clean egg cache %s", egg_cache_dir) shutil.rmtree(egg_cache_dir) except Exception: # We don't care if we can not cleanup pass
if os.path.exists(dest): os.remove(dest) os.symlink(src, dest) print "created" out = stdout() sys.stdout = out sys.stderr = out try: parent = path.dirname(path.realpath(__file__)) createSymbolicLinks(parent) sys.path.pop(0) sys.path.insert(0, path.join(parent,"python.egg")) [ sys.path.insert(1, path.join(parent,i)) for i in listdir(parent) if i.endswith("egg") ] import pkg_resources pkg_resources.set_extraction_path(parent) os.environ["DATA_PATH"]=parent import main except Exception, err: import traceback droid.makeToast(str(err)) droid.log(str(err)) traceback.print_exc(file=out) out.f.close()
def __getattr__(self, name): #droid.log("stdout get %s" % name) return getattr(self.stdout, name) out = stdout() sys.stdout = out sys.stderr = out try: parent = path.dirname(path.realpath(__file__)) sys.path.pop(0) sys.path.insert(0, path.join(parent,"python.egg")) [ sys.path.insert(1, path.join(parent,i)) for i in listdir(parent) if i.endswith("egg") ] import pkg_resources pkg_resources.set_extraction_path(droid.environment()["appcache"]) os.environ["DATA_PATH"]=parent from airidroid import main main() except Exception, err: import traceback droid.log(str(err)) traceback.print_exc(file=out)
def main(): print('In pkg_resources test main()') try: import pkg_resources import setuptools # We can't query pkg_resources' version so query setuptools instead version = pkg_resources.parse_version(setuptools.__version__) minimum = pkg_resources.parse_version('36.6.0') if (version < minimum): print('Skipping test, pkg_resources module is too old') return except ImportError: print('Skipping test, pkg_resources module is not available') return ws = pkg_resources.working_set # Set a safe extraction dir (the default is unsafe) extraction_tmpdir = tempfile.mkdtemp() atexit.register(lambda: shutil.rmtree( extraction_tmpdir, ignore_errors=True)) pkg_resources.set_extraction_path(extraction_tmpdir) # Informational for debugging distributions = list(ws) assert distributions # Test package that doesn't exist. # I hereby promise never to release a package with this name. nonexistent_name = 'subpar-package-does-not-exist-blorg' req = pkg_resources.Requirement.parse(nonexistent_name) dist = ws.find(req) assert not dist # Package exists, has code at the top level directory portpicker_spec = 'portpicker==1.2.0' req = pkg_resources.Requirement.parse(portpicker_spec) # Extract single file fn = pkg_resources.resource_filename(req, 'data_file.txt') with open(fn) as f: actual = f.read() assert actual == 'Dummy data file for portpicker\n', actual # Extract all dirname = pkg_resources.resource_filename(req, '') expected = [ # The __init__.py file shouldn't be here, but is, as an # unfortunately side effect of Bazel runfiles behavior. # https://github.com/google/subpar/issues/51 '__init__.py', 'data_file.txt', 'portpicker-1.2.0.dist-info', 'portpicker.py', ] for fn in expected: assert os.path.exists(os.path.join(dirname, fn)), fn # Import module and check that we got the right one module = __import__(req.name) assert module.x == req.name, (module, vars(module)) # Package exists, has code in a subdir yapf_spec = 'yapf==0.19.0' req = pkg_resources.Requirement.parse(yapf_spec) # Extract single file fn = pkg_resources.resource_filename(req, 'data_file.txt') with open(fn) as f: actual = f.read() assert actual == 'Dummy data file for yapf\n', actual # Extract all dirname = pkg_resources.resource_filename(req, '') expected = [ # The __init__.py file shouldn't be here, but is, as an # unfortunately side effect of Bazel runfiles behavior. '__init__.py', 'data_file.txt', 'yapf', 'yapf-0.19.0.dist-info', ] for fn in expected: assert os.path.exists(os.path.join(dirname, fn)), fn # Import module and check that we got the right one module = __import__(req.name) assert module.x == req.name, (module, vars(module)) print("Pass")
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys, imp, os from android import API from os import path droid = API() parent = path.dirname(path.realpath(__file__)) sys.path.pop(0) sys.path.insert(0, path.join(parent,"python.zip")) sys.path.insert(1, path.join(parent,"pybluez.egg")) import pkg_resources pkg_resources.set_extraction_path(droid.environment()["appcache"]) os.environ["DATA_PATH"]=parent try: import bluetooth import main except Exception, err: from android import API from traceback import format_exc API().log(str(err)) API().log(format_exc()) import time time.sleep(10)
# # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import sys import os import tempfile import pkg_resources try: pkg_resources.set_extraction_path(tempfile.mkdtemp()) except ValueError: pass # If the path is already set the module throw an error def get_resource(resource_name): resource_path = None if hasattr(sys, "frozen") and sys.platform.startswith("darwin"): resource_name = os.path.join("../Resources", resource_name) if hasattr(sys, "frozen") and os.path.exists(resource_name): resource_path = os.path.normpath( os.path.join(os.getcwd(), resource_name)) elif not hasattr(sys, "frozen") and pkg_resources.resource_exists( "gns3", resource_name): resource_path = pkg_resources.resource_filename("gns3", resource_name)
out = stdout() sys.stdout = out sys.stderr = out try: parent = path.dirname(path.realpath(__file__)) createSymbolicLinks(parent) sys.path.pop(0) sys.path.insert(0, path.join(parent, "python.egg")) [ sys.path.insert(1, path.join(parent, i)) for i in listdir(parent) if i.endswith("egg") ] import pkg_resources pkg_resources.set_extraction_path(parent) os.environ["DATA_PATH"] = parent from airidroid import main main() except Exception, err: import traceback droid.makeToast(str(err)) droid.log(str(err)) traceback.print_exc(file=out) out.f.close()
def initialize_persistent_disk(cfg: ElasticBlastConfig, db: str, db_path: str = '') -> None: """ Initialize Persistent Disk for ElasticBLAST execution Arguments: cfg - configuration to get parameters from db - BLAST db name db_path - if custom database, path to the database files """ # ${LOGDATETIME} setup_pd start >>${ELB_LOGFILE} if not db: raise ValueError("Argument 'db' can't be empty") cluster_name = cfg.cluster.name pd_size = str(cfg.cluster.pd_size) program = cfg.blast.program job_init_pv_template = 'job-init-pv.yaml.template' taxdb_path = '' if db_path: # Custom database job_init_pv_template = 'job-init-pv-custom.yaml.template' taxdb_path = gcp_get_blastdb_latest_path() + '/taxdb.*' results_bucket = cfg.cluster.results dry_run = cfg.cluster.dry_run query_batches = os.path.join(results_bucket, ELB_QUERY_BATCH_DIR) init_blastdb_minutes_timeout = cfg.timeouts.init_pv subs = { 'QUERY_BATCHES': query_batches, 'ELB_PD_SIZE': pd_size, 'ELB_CLUSTER_NAME': cluster_name, 'ELB_DB': db, 'ELB_DB_PATH': db_path, 'ELB_TAX_DB_PATH': taxdb_path, 'ELB_DB_MOL_TYPE': ElbSupportedPrograms().get_molecule_type(program), 'ELB_BLASTDB_SRC': cfg.blast.db_source.name, 'BUCKET': results_bucket, 'ELB_DOCKER_IMAGE': ELB_DOCKER_IMAGE, 'ELB_TAXIDLIST': cfg.blast.taxidlist if cfg.blast.taxidlist is not None else '', 'K8S_JOB_GET_BLASTDB': K8S_JOB_GET_BLASTDB, 'K8S_JOB_LOAD_BLASTDB_INTO_RAM': K8S_JOB_LOAD_BLASTDB_INTO_RAM, 'K8S_JOB_IMPORT_QUERY_BATCHES': K8S_JOB_IMPORT_QUERY_BATCHES, 'K8S_JOB_BLAST': K8S_JOB_BLAST, 'K8S_JOB_RESULTS_EXPORT': K8S_JOB_RESULTS_EXPORT } with TemporaryDirectory() as d: set_extraction_path(d) storage_gcp = resource_filename('elb', 'templates/storage-gcp-ssd.yaml') cmd = f"kubectl apply -f {storage_gcp}" if dry_run: logging.info(cmd) else: safe_exec(cmd) pvc_yaml = os.path.join(d, 'pvc.yaml') with open(pvc_yaml, 'wt') as f: f.write( substitute_params( resource_string('elb', 'templates/pvc.yaml.template').decode(), subs)) cmd = f"kubectl apply -f {pvc_yaml}" if dry_run: logging.info(cmd) else: safe_exec(cmd) start = timer() job_init_pv = pathlib.Path(os.path.join(d, 'job-init-pv.yaml')) with job_init_pv.open(mode='wt') as f: f.write( substitute_params( resource_string( 'elb', f'templates/{job_init_pv_template}').decode(), subs)) cmd = f"kubectl apply -f {job_init_pv}" if dry_run: logging.info(cmd) else: safe_exec(cmd) _wait_for_job(job_init_pv, init_blastdb_minutes_timeout, dry_run=dry_run) end = timer() logging.debug(f'RUNTIME init-pv {end-start} seconds') # save persistent disk id so that it can be deleted on clean up disk = get_persistent_disks(dry_run) if disk: cfg.appstate.disk_id = disk[0] disk_id_file = os.path.join(d, ELB_STATE_DISK_ID_FILE) with open(disk_id_file, 'w') as f: print(cfg.appstate.disk_id, file=f) dest = os.path.join(cfg.cluster.results, ELB_METADATA_DIR, ELB_STATE_DISK_ID_FILE) upload_file_to_gcs(disk_id_file, dest, dry_run) if not 'ELB_DONT_DELETE_SETUP_JOBS' in os.environ: cmd = f"kubectl delete -f {job_init_pv}" if dry_run: logging.info(cmd) else: get_logs('app=setup', [K8S_JOB_GET_BLASTDB, K8S_JOB_IMPORT_QUERY_BATCHES], dry_run) safe_exec(cmd) # ${LOGDATETIME} setup_pd end >>${ELB_LOGFILE} # Interim fix to prevent mouont errors on BLAST k8s jobs (EB-239?, EB-282?) if not dry_run: secs2sleep = int( os.getenv('ELB_PAUSE_AFTER_INIT_PV', str(ELB_PAUSE_AFTER_INIT_PV))) time.sleep(secs2sleep)
def initialize_local_ssd(cfg: ElasticBlastConfig, db: str, db_path: str = '') -> None: """ Initialize local SSDs for ElasticBLAST cluster """ if not db: raise ValueError("Argument 'db' can't be empty") dry_run = cfg.cluster.dry_run init_blastdb_minutes_timeout = cfg.timeouts.init_pv num_nodes = cfg.cluster.num_nodes program = cfg.blast.program job_init_template = 'job-init-local-ssd.yaml.template' taxdb_path = '' if db_path: # Custom database job_init_template = 'job-init-local-ssd-custom.yaml.template' taxdb_path = gcp_get_blastdb_latest_path() + '/taxdb.*' subs = { 'ELB_DB': db, 'ELB_DB_PATH': db_path, 'ELB_TAX_DB_PATH': taxdb_path, 'ELB_DB_MOL_TYPE': ElbSupportedPrograms().get_molecule_type(program), 'ELB_BLASTDB_SRC': cfg.blast.db_source.name, 'NODE_ORDINAL': '0', 'ELB_DOCKER_IMAGE': ELB_DOCKER_IMAGE, 'K8S_JOB_GET_BLASTDB': K8S_JOB_GET_BLASTDB, 'K8S_JOB_LOAD_BLASTDB_INTO_RAM': K8S_JOB_LOAD_BLASTDB_INTO_RAM, 'K8S_JOB_IMPORT_QUERY_BATCHES': K8S_JOB_IMPORT_QUERY_BATCHES, 'K8S_JOB_BLAST': K8S_JOB_BLAST, 'K8S_JOB_RESULTS_EXPORT': K8S_JOB_RESULTS_EXPORT } with TemporaryDirectory() as d: set_extraction_path(d) start = timer() job_init_local_ssd_tmpl = resource_string( 'elb', f'templates/{job_init_template}').decode() for n in range(num_nodes): job_init_local_ssd = pathlib.Path( os.path.join(d, f'job-init-local-ssd-{n}.yaml')) subs['NODE_ORDINAL'] = str(n) with job_init_local_ssd.open(mode='wt') as f: f.write(substitute_params(job_init_local_ssd_tmpl, subs)) cmd = f"kubectl apply -f {d}" if dry_run: logging.info(cmd) else: safe_exec(cmd) # wait for multiple jobs timeout = init_blastdb_minutes_timeout * 60 sec2wait = 20 while timeout > 0: cmd = f'kubectl get jobs -o jsonpath=' \ '{.items[?(@.status.active)].metadata.name}{\'\\t\'}' \ '{.items[?(@.status.failed)].metadata.name}{\'\\t\'}' \ '{.items[?(@.status.succeeded)].metadata.name}' if dry_run: logging.info(cmd) res = '\t\t' + \ ' '.join([f'init-ssd-{n}' for n in range(num_nodes)]) else: proc = safe_exec(cmd) res = proc.stdout.decode() logging.debug(res) active, failed, succeeded = res.split('\t') if failed: proc = safe_exec(f'kubectl logs -l app=setup') for line in proc.stdout.split('\n'): logging.debug(line) raise RuntimeError( f'Local SSD initialization jobs failed: {failed}') if not active: logging.debug( f'Local SSD initialization jobs succeeded: {succeeded}') break time.sleep(sec2wait) timeout -= sec2wait if timeout < 0: raise TimeoutError(f'{d} jobs timed out') end = timer() logging.debug(f'RUNTIME init-storage {end-start} seconds') # Delete setup jobs if not 'ELB_DONT_DELETE_SETUP_JOBS' in os.environ: cmd = 'kubectl delete jobs -l app=setup' if dry_run: logging.info(cmd) else: safe_exec(cmd)
def extract_2_(self,eggDir,osDir='/tmp'): ''' Doesn't work yet !!! ''' pkg_resources.set_extraction_path(osDir) filename = pkg_resources.resource_filename(__name__,eggDir) print filename
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import sys import os import tempfile import pkg_resources import atexit import logging log = logging.getLogger(__name__) try: egg_cache_dir = tempfile.mkdtemp() pkg_resources.set_extraction_path(egg_cache_dir) except ValueError: # If the path is already set the module throw an error pass @atexit.register def clean_egg_cache(): try: import shutil log.debug("Clean egg cache %s", egg_cache_dir) shutil.rmtree(egg_cache_dir) except Exception: # We don't care if we can not cleanup pass
# # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import sys import os import tempfile import pkg_resources try: pkg_resources.set_extraction_path(tempfile.mkdtemp()) except ValueError: pass # If the path is already set the module throw an error def get_resource(resource_name): resource_path = None if hasattr(sys, "frozen") and sys.platform.startswith("darwin"): resource_name = os.path.join("../Resources", resource_name) if hasattr(sys, "frozen") and os.path.exists(resource_name): resource_path = os.path.normpath(os.path.join(os.getcwd(), resource_name)) elif not hasattr(sys, "frozen") and pkg_resources.resource_exists("gns3", resource_name): resource_path = pkg_resources.resource_filename("gns3", resource_name) resource_path = os.path.normpath(resource_path) return resource_path