def get_data_file(file_name):
path = None
if os.path.isfile('pv/%s' % file_name):
path = 'pv/%s' % file_name
elif os.path.isfile(site.getusersitepackages()+'/cse/'+file_name):
path = site.getusersitepackages()+'/cse/'+file_name
else:
sp = site.getsitepackages()
if isinstance(sp, list):
for item in sp:
if os.path.isfile(item+'/cse/'+file_name):
path = item+'/cse/'+file_name
break
elif os.path.isfile(sp+'/cse/'+file_name):
path = sp+'/cse/'+file_name
content = ''
if path is not None:
with open(path) as f:
content = f.read()
return content
python类getusersitepackages()的实例源码
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
def binaries_directory():
"""Return the installation directory, or None"""
if '--user' in sys.argv:
paths = (site.getusersitepackages(),)
else:
py_version = '%s.%s' % (sys.version_info[0], sys.version_info[1])
paths = (s % (py_version) for s in (
sys.prefix + '/lib/python%s/dist-packages/',
sys.prefix + '/lib/python%s/site-packages/',
sys.prefix + '/local/lib/python%s/dist-packages/',
sys.prefix + '/local/lib/python%s/site-packages/',
'/Library/Python/%s/site-packages/',
))
# yield the first valid path
for path in paths:
# add the package and bin subdir and, if exists, return it
path = os.path.join(path, '%s/%s' % (info.__pkg_name__, constant.REL_DIR_BIN))
if os.path.exists(path):
return path
logging.getLogger().error(
'pyasp binaries path not found. You need to download and'
' put in place the binaries for gringo3, gringo4 and clasp'
' in order to start using pyasp.'
' You can find binaries from ' + BINARIES_BASE_URL +
' or https://sourceforge.net/projects/potassco/files/,'
' or compile them yourself.'
)
exit()
return None
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
def test_getusersitepackages(self):
site.USER_SITE = None
site.USER_BASE = None
user_site = site.getusersitepackages()
# the call sets USER_BASE *and* USER_SITE
self.assertEqual(site.USER_SITE, user_site)
self.assertTrue(user_site.startswith(site.USER_BASE), user_site)
def is_user_site_package():
try:
user_site = site.getusersitepackages()
except AttributeError:
return False
return os.path.abspath(__file__).startswith(os.path.join(user_site, ""))
def get_binaries_directory():
"""Return the installation directory, or None
http://stackoverflow.com/questions/36187264"""
if '--user' in sys.argv:
paths = (site.getusersitepackages(),)
else:
if hasattr(site, 'getsitepackages'):
print("cmany setup: site-packages", site.getsitepackages())
print("cmany setup: site-user-packages", site.getusersitepackages())
print("cmany setup: site-prefix", os.path.dirname(sys.executable))
paths = site.getsitepackages()
else:
print("cmany setup: no site.getsitepackages()...")
py_prefix = os.path.dirname(sys.executable)
paths = [
py_prefix + '/lib/site-packages',
py_prefix + '/lib/site-packages',
py_prefix + '/lib',
]
py_version = '{}.{}'.format(sys.version_info[0], sys.version_info[1])
paths += (s.format(py_version) for s in (
sys.prefix + '/lib/python{}/site-packages/',
sys.prefix + '/lib/python{}/dist-packages/',
sys.prefix + '/local/lib/python{}/site-packages/',
sys.prefix + '/local/lib/python{}/dist-packages/',
'/Library/Python/{}/site-packages/',
))
for path in paths:
if os.path.exists(path):
print('cmany setup: installation path:', path)
return path
raise Exception('cmany setup: no installation path found', file=sys.stderr)
return None
def python_env(options, unset_env=False):
"""
Setup our overrides_hack.py as sitecustomize.py script in user
site-packages if unset_env=False, else unset, previously set
env.
"""
subprojects_path = os.path.join(options.builddir, "subprojects")
gst_python_path = os.path.join(SCRIPTDIR, "subprojects", "gst-python")
if not os.path.exists(os.path.join(subprojects_path, "gst-python")) or \
not os.path.exists(gst_python_path):
return False
sitepackages = site.getusersitepackages()
if not sitepackages:
return False
sitecustomize = os.path.join(sitepackages, "sitecustomize.py")
overrides_hack = os.path.join(gst_python_path, "testsuite", "overrides_hack.py")
if not unset_env:
if os.path.exists(sitecustomize):
if os.path.realpath(sitecustomize) == overrides_hack:
print("Customize user site script already linked to the GStreamer one")
return False
old_sitecustomize = os.path.join(sitepackages,
"old.sitecustomize.gstuninstalled.py")
shutil.move(sitecustomize, old_sitecustomize)
elif not os.path.exists(sitepackages):
os.makedirs(sitepackages)
os.symlink(overrides_hack, sitecustomize)
return os.path.realpath(sitecustomize) == overrides_hack
else:
if not os.path.realpath(sitecustomize) == overrides_hack:
return False
os.remove(sitecustomize)
old_sitecustomize = os.path.join(sitepackages,
"old.sitecustomize.gstuninstalled.py")
if os.path.exists(old_sitecustomize):
shutil.move(old_sitecustomize, sitecustomize)
return True