本文整理汇总了Python中os.path.abspath函数的典型用法代码示例。如果您正苦于以下问题:Python abspath函数的具体用法?Python abspath怎么用?Python abspath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了abspath函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: check_mask_coverage
def check_mask_coverage(epi,brainmask):
from os.path import abspath
from nipype import config, logging
config.enable_debug_mode()
logging.update_logging(config)
from nilearn import plotting
from nipype.interfaces.nipy.preprocess import Trim
trim = Trim()
trim.inputs.in_file = epi
trim.inputs.end_index = 1
trim.inputs.out_file = 'epi_vol1.nii.gz'
trim.run()
epi_vol = abspath('epi_vol1.nii.gz')
maskcheck_filename='maskcheck.png'
display = plotting.plot_anat(epi_vol, display_mode='ortho',
draw_cross=False,
title = 'brainmask coverage')
display.add_contours(brainmask,levels=[.5], colors='r')
display.savefig(maskcheck_filename)
display.close()
maskcheck_file = abspath(maskcheck_filename)
return(maskcheck_file)
开发者ID:catcamacho,项目名称:infant_rest,代码行数:25,代码来源:preprocessing_classic.py
示例2: find_pylintrc
def find_pylintrc():
"""search the pylint rc file and return its path if it find it, else None
"""
# is there a pylint rc file in the current directory ?
if exists("pylintrc"):
return abspath("pylintrc")
if isfile("__init__.py"):
curdir = abspath(os.getcwd())
while isfile(join(curdir, "__init__.py")):
curdir = abspath(join(curdir, ".."))
if isfile(join(curdir, "pylintrc")):
return join(curdir, "pylintrc")
if "PYLINTRC" in os.environ and exists(os.environ["PYLINTRC"]):
pylintrc = os.environ["PYLINTRC"]
else:
user_home = expanduser("~")
if user_home == "~" or user_home == "/root":
pylintrc = ".pylintrc"
else:
pylintrc = join(user_home, ".pylintrc")
if not isfile(pylintrc):
pylintrc = join(user_home, ".config", "pylintrc")
if not isfile(pylintrc):
if isfile("/etc/pylintrc"):
pylintrc = "/etc/pylintrc"
else:
pylintrc = None
return pylintrc
开发者ID:GymWenFLL,项目名称:tpp_libs,代码行数:28,代码来源:config.py
示例3: results_table
def results_table(path_dict):
""" Return precalculated results images for subject info in `path_dict`
Parameters
----------
path_dict : dict
containing key 'rootdir'
Returns
-------
rtab : dict
dict with keys given by run directories for this subject, values being a
list with filenames of effect and sd images.
"""
# Which runs correspond to this design type?
rootdir = path_dict['rootdir']
runs = filter(lambda f: isdir(pjoin(rootdir, f)),
['results_%02d' % i for i in range(1,5)] )
# Find out which contrasts have t-statistics,
# storing the filenames for reading below
results = {}
for rundir in runs:
rundir = pjoin(rootdir, rundir)
for condir in listdir(rundir):
for stat in ['sd', 'effect']:
fname_effect = abspath(pjoin(rundir, condir, 'effect.nii'))
fname_sd = abspath(pjoin(rundir, condir, 'sd.nii'))
if exists(fname_effect) and exists(fname_sd):
results.setdefault(condir, []).append([fname_effect,
fname_sd])
return results
开发者ID:GaelVaroquaux,项目名称:nipy,代码行数:34,代码来源:fiac_util.py
示例4: inside
def inside(dir, name):
"""
检查给定的目录中是否有给定的文件名。
"""
dir = abspath(dir)
name = abspath(name)
return name.startswith(join(dir, ''))
开发者ID:DerekChenGit,项目名称:p2pFilesManager,代码行数:7,代码来源:server.py
示例5: check_filepath
def check_filepath(filepath):
if not filepath:
return None
base_filename = basename(filepath)
abs_dirname = dirname(abspath(filepath)) if base_filename else abspath(filepath)
return join(abs_dirname, base_filename)
开发者ID:Auzzy,项目名称:personal,代码行数:7,代码来源:main.py
示例6: check
def check(self):
""" Checks parameters and paths
"""
if 'TITLE' not in PAR:
setattr(PAR, 'TITLE', unix.basename(abspath('..')))
if 'SUBTITLE' not in PAR:
setattr(PAR, 'SUBTITLE', unix.basename(abspath('.')))
# check parameters
if 'NTASK' not in PAR:
setattr(PAR, 'NTASK', 1)
if 'NPROC' not in PAR:
setattr(PAR, 'NPROC', 1)
if 'VERBOSE' not in PAR:
setattr(PAR, 'VERBOSE', 1)
# check paths
if 'GLOBAL' not in PATH:
setattr(PATH, 'GLOBAL', join(abspath('.'), 'scratch'))
if 'LOCAL' not in PATH:
setattr(PATH, 'LOCAL', '')
if 'SUBMIT' not in PATH:
setattr(PATH, 'SUBMIT', unix.pwd())
if 'OUTPUT' not in PATH:
setattr(PATH, 'OUTPUT', join(PATH.SUBMIT, 'output'))
if 'SYSTEM' not in PATH:
setattr(PATH, 'SYSTEM', join(PATH.GLOBAL, 'system'))
开发者ID:AlainPlattner,项目名称:seisflows,代码行数:35,代码来源:serial.py
示例7: getIcons
def getIcons(filename=None):
"""Creates wxBitmaps ``self.icon`` and ``self.iconAdd`` based on the the image.
The latter has a plus sign added over the top.
png files work best, but anything that wx.Image can import should be fine
"""
icons = {}
if filename is None:
filename = join(dirname(abspath(__file__)), 'base.png')
# get the low-res version first
im = Image.open(filename)
icons['24'] = pilToBitmap(im, scaleFactor=0.5)
icons['24add'] = pilToBitmap(im, scaleFactor=0.5)
# try to find a 128x128 version
filename128 = filename[:-4]+'128.png'
if False: # TURN OFF FOR NOW os.path.isfile(filename128):
im = Image.open(filename128)
else:
im = Image.open(filename)
icons['48'] = pilToBitmap(im)
# add the plus sign
add = Image.open(join(dirname(abspath(__file__)), 'add.png'))
im.paste(add, [0, 0, add.size[0], add.size[1]], mask=add)
# im.paste(add, [im.size[0]-add.size[0], im.size[1]-add.size[1],
# im.size[0], im.size[1]], mask=add)
icons['48add'] = pilToBitmap(im)
return icons
开发者ID:andela-dowoade,项目名称:psychopy,代码行数:29,代码来源:__init__.py
示例8: copy_strip
def copy_strip():
"""Copy idle.html to idlelib/help.html, stripping trailing whitespace.
Files with trailing whitespace cannot be pushed to the hg cpython
repository. For 3.x (on Windows), help.html is generated, after
editing idle.rst in the earliest maintenance version, with
sphinx-build -bhtml . build/html
python_d.exe -c "from idlelib.help import copy_strip; copy_strip()"
After refreshing TortoiseHG workshop to generate a diff,
check both the diff and displayed text. Push the diff along with
the idle.rst change and merge both into default (or an intermediate
maintenance version).
When the 'earlist' version gets its final maintenance release,
do an update as described above, without editing idle.rst, to
rebase help.html on the next version of idle.rst. Do not worry
about version changes as version is not displayed. Examine other
changes and the result of Help -> IDLE Help.
If maintenance and default versions of idle.rst diverge, and
merging does not go smoothly, then consider generating
separate help.html files from separate idle.htmls.
"""
src = join(abspath(dirname(dirname(dirname(__file__)))),
'Doc', 'build', 'html', 'library', 'idle.html')
dst = join(abspath(dirname(__file__)), 'help.html')
with open(src, 'rb') as inn,\
open(dst, 'wb') as out:
for line in inn:
out.write(line.rstrip() + b'\n')
print('idle.html copied to help.html')
开发者ID:whqkdhfh13,项目名称:sswp,代码行数:31,代码来源:help.py
示例9: test_reset_files
def test_reset_files(self):
"""reset files"""
for document in self.documents:
document.share_file(abspath("data"), True)
self.assertEquals(document.get_container(abspath("data"))._shared, True)
document.reset_files()
self.assertEquals(document.get_files(), {})
开发者ID:BackupTheBerlios,项目名称:solipsis-svn,代码行数:7,代码来源:unittest_document.py
示例10: test_get_home_dir_7
def test_get_home_dir_7():
"""Using HOMESHARE, os=='nt'."""
os.name = 'nt'
env["HOMESHARE"] = abspath(HOME_TEST_DIR)
home_dir = path.get_home_dir()
nt.assert_equal(home_dir, abspath(HOME_TEST_DIR))
开发者ID:markvoorhies,项目名称:ipython,代码行数:7,代码来源:test_path.py
示例11: convert_disk_image
def convert_disk_image(args):
"""Convert disk to another format."""
filename = op.abspath(args.file.name)
output = op.abspath(args.output)
os.environ['LIBGUESTFS_CACHEDIR'] = os.getcwd()
if args.verbose:
os.environ['LIBGUESTFS_DEBUG'] = '1'
if args.zerofree:
guestfish_zerofree(filename)
for fmt in args.formats:
if fmt in (tar_formats + disk_formats):
output_filename = "%s.%s" % (output, fmt)
if output_filename == filename:
continue
logger.info("Creating %s" % output_filename)
try:
if fmt in tar_formats:
tar_convert(filename, output_filename,
args.tar_excludes,
args.tar_compression_level)
else:
qemu_convert(filename, fmt, output_filename)
except ValueError as exp:
logger.error("Error: %s" % exp)
开发者ID:mickours,项目名称:kameleon-helpers,代码行数:27,代码来源:export_appliance.py
示例12: main
def main():
"""The main function."""
options = ParseOptions()
required_flags = ["version_file", "output", "input", "build_dir",
"gen_out_dir", "auto_updater_dir", "build_type"]
for flag in required_flags:
if getattr(options, flag) is None:
logging.error("--%s is not specified." % flag)
exit(-1)
version = mozc_version.MozcVersion(options.version_file)
# \xC2\xA9 is the copyright mark in UTF-8
copyright_message = '\xC2\xA9 %d Google Inc.' % _COPYRIGHT_YEAR
long_version = version.GetVersionString()
short_version = version.GetVersionInFormat('@[email protected]@[email protected]@[email protected]')
variables = {
'MOZC_VERSIONINFO_MAJOR': version.GetVersionInFormat('@[email protected]'),
'MOZC_VERSIONINFO_MINOR': version.GetVersionInFormat('@[email protected]'),
'MOZC_VERSIONINFO_LONG': long_version,
'MOZC_VERSIONINFO_SHORT': short_version,
'MOZC_VERSIONINFO_FINDER':
'Google Japanese Input %s, %s' % (long_version, copyright_message),
'GEN_OUT_DIR': path.abspath(options.gen_out_dir),
'BUILD_DIR': path.abspath(options.build_dir),
'AUTO_UPDATER_DIR': path.abspath(options.auto_updater_dir),
'MOZC_DIR': path.abspath(path.join(os.getcwd(), ".."))
}
open(options.output, 'w').write(
_RemoveDevOnlyLines(
_ReplaceVariables(open(options.input).read(), variables),
options.build_type))
开发者ID:Ranats,项目名称:mozc,代码行数:33,代码来源:tweak_pkgproj.py
示例13: rev_get_dataset_root
def rev_get_dataset_root(path):
"""Return the root of an existent dataset containing a given path
The root path is returned in the same absolute or relative form
as the input argument. If no associated dataset exists, or the
input path doesn't exist, None is returned.
If `path` is a symlink or something other than a directory, its
the root dataset containing its parent directory will be reported.
If none can be found, at a symlink at `path` is pointing to a
dataset, `path` itself will be reported as the root.
"""
suffix = '.git'
altered = None
if op.islink(path) or not op.isdir(path):
altered = path
path = op.dirname(path)
apath = op.abspath(path)
# while we can still go up
while op.split(apath)[1]:
if op.exists(op.join(path, suffix)):
return path
# new test path in the format we got it
path = op.normpath(op.join(path, os.pardir))
# no luck, next round
apath = op.abspath(path)
# if we applied dirname() at the top, we give it another go with
# the actual path, if it was itself a symlink, it could be the
# top-level dataset itself
if altered and op.exists(op.join(altered, suffix)):
return altered
return None
开发者ID:datalad,项目名称:datalad,代码行数:33,代码来源:dataset.py
示例14: syncfiles
def syncfiles(args):
if len(args) < 3:
printtofile ('args not enough, need: files src_host dest_hosts')
return
dest_hosts = []
src_host = ''
files = ast.literal_eval(args[2])
if len(args) >= 4:
src_host = args[3]
if len(args) >= 5:
dest_hosts = ast.literal_eval(args[4])
if len(dest_hosts) == 0:
if len(src_host) == 0:
dest_hosts = primary_host + replicas_host
else:
dest_hosts = replicas_host
for file in files:
fullfilepath = ''
if (src_host == ''):
fullfilepath = base_dir + '/' + path.abspath(file).replace(path.abspath(local_base), '')
printtofile ('local to remote : ' + fullfilepath)
else:
fullfilepath = base_dir + '/' + file
for dest_host in dest_hosts:
dest_host_path = loginuser + '@' + dest_host + ':' + fullfilepath
if src_host == '':
# using local file
os.system(scp_local + file + ' ' + dest_host_path)
else:
os.system(scp_remote + src_host + ':' + fullfilepath + ' ' + dest_host_path)
printtofile ('finished.')
开发者ID:izenecloud,项目名称:driver-ruby,代码行数:32,代码来源:easy_tool.py
示例15: test_get_shared_files
def test_get_shared_files(self):
document = CacheDocument()
document.add_repository(TEST_DIR)
document.expand_dir(abspath("data"))
document.expand_dir(abspath(os.path.join("data", "subdir1")))
document.share_files(abspath("data"),
[os.sep.join([TEST_DIR, "data", ".path"]),
os.sep.join([TEST_DIR, "data", ".svn"]),
os.sep.join([TEST_DIR, "data", "date.txt"]),
os.sep.join([TEST_DIR, "data", "emptydir"]),
os.sep.join([TEST_DIR, "data", "profiles"]),
os.sep.join([TEST_DIR, "data", "subdir1", ".svn"]),
os.sep.join([TEST_DIR, "data", "subdir1", "subsubdir"])],
False)
document.share_files(abspath("data"),
[os.sep.join([TEST_DIR, "data"]),
os.sep.join([TEST_DIR, "data", ".path"]),
os.sep.join([TEST_DIR, "data", "date.txt"]),
os.sep.join([TEST_DIR, "data", "routage"]),
os.sep.join([TEST_DIR, "data", "subdir1"]),
os.sep.join([TEST_DIR, "data", "subdir1", "TOtO.txt"]),
os.sep.join([TEST_DIR, "data", "subdir1", "date.doc"])],
True)
shared_files = [file_container.get_path() for file_container
in document.get_shared_files()[TEST_DIR]]
shared_files.sort()
self.assertEquals(shared_files, [os.sep.join([TEST_DIR, "data", ".path"]),
os.sep.join([TEST_DIR, "data", "02_b_1280x1024.jpg"]),
os.sep.join([TEST_DIR, "data", "Python-2.3.5.zip"]),
os.sep.join([TEST_DIR, "data", "arc en ciel 6.gif"]),
os.sep.join([TEST_DIR, "data", "date.txt"]),
os.sep.join([TEST_DIR, "data", "pywin32-203.win32-py2.3.exe"]),
os.sep.join([TEST_DIR, "data", "routage"]),
os.sep.join([TEST_DIR, "data", "subdir1", "TOtO.txt"]),
os.sep.join([TEST_DIR, "data", "subdir1", "date.doc"])])
开发者ID:BackupTheBerlios,项目名称:solipsis-svn,代码行数:35,代码来源:unittest_document.py
示例16: __init__
def __init__(self, pdf_page, svg_filename, png_filename):
self._svg_filename = abspath(svg_filename)
self._png_filename = abspath(png_filename) if png_filename else None
self._context, self._surface = self._get_context(
svg_filename, *pdf_page.get_size())
pdf_page.render(self._context)
开发者ID:MikeTrenfield,项目名称:pdftables,代码行数:7,代码来源:diagnostics.py
示例17: _assertContent
def _assertContent(self, doc):
"""check validity of content"""
self.assertEquals(u"atao", doc.get_pseudo())
self.assertEquals(u"Mr", doc.get_title())
self.assertEquals(u"manu", doc.get_firstname())
self.assertEquals(u"breton", doc.get_lastname())
self.assertEquals(QUESTION_MARK(), doc.get_photo())
self.assertEquals(u"[email protected]", doc.get_email())
self.assertEquals({'City': u'', 'color': u'blue', 'Country': u'',
'Favourite Book': u'', 'homepage': u'manu.com',
'Favourite Movie': u'', 'Studies': u''},
doc.get_custom_attributes())
# assert correct file structure
files = doc.get_files()
self.assertEquals(files.has_key(TEST_DIR), True)
self.assertEquals(files[TEST_DIR][os.sep.join([abspath("data"), "date.txt"])]._tag, "tagos")
self.assertEquals(files[TEST_DIR][abspath("data")]._shared, False)
self.assertEquals(files[TEST_DIR][os.sep.join([abspath("data"), "routage"])]._shared, True)
self.assertEquals(files[TEST_DIR][os.sep.join([abspath("data"), "emptydir"])]._shared, True)
self.assertEquals(files[TEST_DIR][os.sep.join([abspath("data"), "subdir1"])]._shared, True)
self.assertEquals(files[TEST_DIR][os.sep.join([abspath("data"), "subdir1", ""])]._shared, True)
self.assertEquals(files[TEST_DIR][os.sep.join([abspath("data"), "subdir1", "subsubdir"])]._shared, False)
self.assertEquals(files[TEST_DIR][os.sep.join([abspath("data"), "subdir1", "subsubdir", "null"])]._shared, True)
self.assertEquals(files[TEST_DIR][os.sep.join([abspath("data"), "subdir1", "subsubdir", "dummy.txt"])]._shared, True)
self.assertEquals(files[TEST_DIR].has_key(os.sep.join([abspath("data"), "subdir1", "subsubdir", "default.solipsis"])), False)
# peers
peers = doc.get_peers()
self.assertEquals(peers.has_key(PROFILE_BRUCE), True)
self.assertEquals(peers[PROFILE_BRUCE].state, PeerDescriptor.FRIEND)
self.assertEquals(peers[PROFILE_BRUCE].connected, False)
开发者ID:BackupTheBerlios,项目名称:solipsis-svn,代码行数:30,代码来源:unittest_file_document.py
示例18: fixate
def fixate():
"puts activation code to usercustomize.py for user"
print_message('Fixate')
import site
userdir = site.getusersitepackages()
if not userdir:
raise PundleException('Can`t fixate due user have not site package directory')
try:
makedirs(userdir)
except OSError:
pass
template = FIXATE_TEMPLATE.replace('op.dirname(__file__)', "'%s'" % op.abspath(op.dirname(__file__)))
usercustomize_file = op.join(userdir, 'usercustomize.py')
print_message('Will edit %s file' % usercustomize_file)
if op.exists(usercustomize_file):
content = open(usercustomize_file).read()
if '# pundle user customization start' in content:
regex = re.compile(r'\n# pundle user customization start.*# pundle user customization end\n', re.DOTALL)
content, res = regex.subn(template, content)
open(usercustomize_file, 'w').write(content)
else:
open(usercustomize_file, 'a').write(content)
else:
open(usercustomize_file, 'w').write(template)
link_file = op.join(userdir, 'pundle.py')
if op.lexists(link_file):
print_message('Remove exist link to pundle')
os.unlink(link_file)
print_message('Create link to pundle %s' % link_file)
os.symlink(op.abspath(__file__), link_file)
print_message('Complete')
开发者ID:Deepwalker,项目名称:pundler,代码行数:31,代码来源:pundle.py
示例19: run
def run(self):
sFiles=self.parser.getArgs()[0:-1]
dFile=path.abspath(self.parser.getArgs()[-1])
for s in sFiles:
sName=path.abspath(s)
dName=dFile
if len(s)>1:
print f.name+"Source file",sName,f.reset
try:
source=ParsedParameterFile(sName,
backup=False,
debug=self.opts.debugParser,
listLengthUnparsed=self.opts.longlist,
noBody=self.opts.noBody,
noHeader=self.opts.noHeader,
boundaryDict=self.opts.boundaryDict,
listDict=self.opts.listDict,
listDictWithHeader=self.opts.listDictWithHeader)
except IOError,e:
self.warning("Problem with file",sName,":",e)
continue
except PyFoamParserError,e:
self.warning("Parser problem with",sName,":",e)
continue
开发者ID:floli,项目名称:tools,代码行数:26,代码来源:CompareDictionary.py
示例20: build_chm_doc
def build_chm_doc(libname):
"""Return CHM documentation file (on Windows only), which is copied under
{PythonInstallDir}\Doc, hence allowing Spyder to add an entry for opening
package documentation in "Help" menu. This has no effect on a source
distribution."""
args = ''.join(sys.argv)
if os.name == 'nt' and ('bdist' in args or 'build' in args):
try:
import sphinx # analysis:ignore
except ImportError:
print('Warning: `sphinx` is required to build documentation',
file=sys.stderr)
return
hhc_base = r'C:\Program Files%s\HTML Help Workshop\hhc.exe'
for hhc_exe in (hhc_base % '', hhc_base % ' (x86)'):
if osp.isfile(hhc_exe):
break
else:
print('Warning: `HTML Help Workshop` is required to build CHM '\
'documentation file', file=sys.stderr)
return
doctmp_dir = 'doctmp'
subprocess.call('sphinx-build -b htmlhelp doc %s' % doctmp_dir,
shell=True)
atexit.register(shutil.rmtree, osp.abspath(doctmp_dir))
fname = osp.abspath(osp.join(doctmp_dir, '%s.chm' % libname))
subprocess.call('"%s" %s' % (hhc_exe, fname), shell=True)
if osp.isfile(fname):
return fname
else:
print('Warning: CHM building process failed', file=sys.stderr)
开发者ID:PierreRaybaut,项目名称:PythonQwt,代码行数:31,代码来源:setup.py
注:本文中的os.path.abspath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论