本文整理汇总了Python中unipath.Path.absolute方法的典型用法代码示例。如果您正苦于以下问题:Python Path.absolute方法的具体用法?Python Path.absolute怎么用?Python Path.absolute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unipath.Path
的用法示例。
在下文中一共展示了Path.absolute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def handle(self, *args, **options):
from ....media.models import MediaFile
from ...models import Transcript
if len(args) != 1:
raise CommandError('Provide media URL.')
(url,) = args
local_path = Path(url)
if local_path.exists():
url = 'file://{}'.format(local_path.absolute())
media_file = MediaFile.objects.create(
data_url=url,
)
if options['verbosity']:
self.stdout.write('Created media file: {}'.format(media_file))
transcript = Transcript.objects.create(
name=url,
)
if options['verbosity']:
self.stdout.write('Created transcript: {}'.format(transcript))
示例2: create_file
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def create_file(self, name, contents):
"""
Creates a gzip file
:param name: (str) name of the file to be created
:param contents: (str) contents to be written in the file
:return: (str or False) path of the created file
"""
# write a tmp file
tmp = mkstemp()[1]
with gzip.open(tmp, 'wb') as handler:
handler.write(contents)
# send it to the FTP server
if self.ftp:
self.ftp.storbinary('STOR {}'.format(name), open(tmp, 'rb'))
return '{}{}'.format(self.path, name)
# or save it locally
else:
new_path = Path(self.path).child(name)
tmp_path = Path(tmp)
tmp_path.copy(new_path)
if new_path.exists():
return new_path.absolute()
return False
示例3: auto
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def auto(options):
'''
Load my task options
'''
this_file = Path(__file__)
cfg_file = this_file.absolute().parent.child('pavement_config.yml')
cfg = bunchify_yaml_file(cfg_file)
options.cfg = cfg
示例4: unused_write_release_notes
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def unused_write_release_notes():
"""
Generate docs/releases/x.y.z.rst file from setup_info.
"""
v = env.SETUP_INFO['version']
if v.endswith('+'):
return
notes = Path(env.ROOTDIR, 'docs', 'releases', '%s.rst' % v)
if notes.exists():
return
must_confirm("Create %s" % notes.absolute())
#~ context = dict(date=get_current_date().strftime(env.long_date_format))
context = dict(date=get_current_date().strftime('%Y%m%d'))
context.update(env.SETUP_INFO)
txt = """\
==========================
Version %(version)s
==========================
Release process started :blogref:`%(date)s`
List of changes
===============
New features
------------
Optimizations
-------------
Bugfixes
--------
Manual tasks after upgrade
--------------------------
""" % context
notes.write_file(txt)
notes.parent.child('index.rst').set_times()
args = [os.environ['EDITOR']]
args += [notes.absolute()]
local(' '.join(args))
示例5: test_load_street_types_no_space_end_of_line
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def test_load_street_types_no_space_end_of_line(self):
temp_dir = Path(tempfile.mkdtemp())
temp_file = Path(temp_dir, 'test.txt')
temp_file.write_file('VILLAGE VILL VLG\n')
StreetType.load_street_types(temp_file.absolute())
temp_dir.rmtree()
self.assertEqual('VILLAGE VILL', StreetType.objects.first().name)
self.assertEqual('VLG', StreetType.objects.first().abbreviation)
示例6: test_load_directionals_no_space_end_of_line
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def test_load_directionals_no_space_end_of_line(self):
temp_dir = Path(tempfile.mkdtemp())
temp_file = Path(temp_dir, 'test.txt')
temp_file.write_file('Northeast NE\n')
Directional.load_directionals(temp_file.absolute())
temp_dir.rmtree()
self.assertEqual('Northeast', Directional.objects.first().direction)
self.assertEqual('NE', Directional.objects.first().abbreviation)
示例7: test_load_states_space_end_of_line
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def test_load_states_space_end_of_line(self):
temp_dir = Path(tempfile.mkdtemp())
temp_file = Path(temp_dir, 'test.txt')
temp_file.write_file('Florida FL \n')
State.load_states(temp_file.absolute())
temp_dir.rmtree()
self.assertEqual('Florida', State.objects.first().name)
self.assertEqual('FL', State.objects.first().abbreviation)
示例8: __check_directory
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def __check_directory(self):
"""
Check if the entered directory exists
:return: (unipath.Path or False) the path to the existing directory
"""
directory = Path(self.arguments['<directory>'])
if not directory.exists() or not directory.isdir():
msg = '{} is not a valid directory'.format(directory.absolute())
self.__output(msg, error=True)
return False
return directory
示例9: ReleaseUnpackerRarFile
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
class ReleaseUnpackerRarFile(object):
def __init__(self, rar_file_path):
self.rar_file_path = Path(rar_file_path)
if (not self.rar_file_path.exists() or not self.rar_file_path.isfile()
or not self.rar_file_path.ext == '.rar'):
raise ReleaseUnpackerRarFileError('Invalid RAR file {}'.format(
self. rar_file_path))
self.rar_file_path_abs = self.rar_file_path.absolute()
self.rar_file = rarfile.RarFile(self.rar_file_path)
def __repr__(self):
return '<ReleaseUnpackerRarFile: {}>'.format(self.rar_file_path_abs)
@lazy
def name(self):
if self.subs_dir:
name = self.rar_file_path.parent.parent.name
else:
name = self.rar_file_path.parent.name
return str(name)
@lazy
def subs_dir(self):
if self.rar_file_path.parent.name.lower() in ('subs', 'sub'):
return True
else:
return False
@lazy
def file_list(self):
files = []
for file in self.rar_file.infolist():
files.append({'name': Path(file.filename), 'size': file.file_size})
return files
def set_mtime(self):
with file(self.extracted_file_path, 'a'):
os.utime(self.extracted_file_path, None)
def extract_file(self, file_name, unpack_dir):
self.rar_file.extract(file_name, path=unpack_dir)
self.extracted_file_path = Path(unpack_dir, file_name)
# Set the mtime to current time
self.set_mtime()
return self.extracted_file_path
示例10: parse
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def parse(path='./flat_files/'):
path = Path(path)
print "parsing records at {}".format(path.absolute())
records = []
for p in path.listdir():
try:
gbr = GenBank.read(open(p))
records.append(gbr)
except:
print 'error with file', p
print "parsed %s records.." % len(records)
return records
示例11: get_current_release_name
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def get_current_release_name():
run_args = {}
# Append capture value if we are running locally
if env.run.__name__ == "elocal":
run_args["capture"] = True
path = env.run(
"ls -dt %s/*/ | sort -n -t _ -k 2 | tail -1" %
get_releases_path(), **run_args)
if not path:
return
release = Path(path)
try:
int(release.absolute().name)
except ValueError as e:
print e
return
return release.absolute().name
示例12: content
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def content(request=None):
base = Path(current_app.config.get('INUPYPI_REPO',
Path('.', 'packages')))
if request:
repo = Path(base, request)
else:
repo = base
try:
repo = repo.absolute()
base = base.absolute()
if not repo.exists():
if base == repo:
raise InuPyPIMissingRepoPath
# sets the request to lowercase and compares it with
# the existing items in the repository in lowercase
repo = search_path(repo, base)
if not repo:
raise InuPyPI404Exception
if repo.isdir():
return Dirs(repo)
if repo.isfile():
return repo
except InuPyPIMissingRepoPath:
abort(500, 'Missing repository or package path!')
except InuPyPI404Exception:
abort(404, 'Path or File could not be found!')
except:
abort(500, 'Internal Server Error!')
return repo
示例13: download_zipped_corpus
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
def download_zipped_corpus():
tempdir = tempfile.mkdtemp()
url = 'https://github.com/torvalds/linux/archive/master.zip'
test_url = 'https://github.com/facebook/libphenom/archive/master.zip'
file_name = url.split('/')[-1]
# download zipfile with output to console
def clear(): os.system('cls' if os.name=='nt' else 'clear')
wget_out_file = Path(tempdir, file_name)
wget = sub.Popen(['wget', url,'-O', wget_out_file], stdout=sub.PIPE, stderr=sub.STDOUT)
while True:
line = wget.stdout.readline()
if not line: break
clear()
print line
wget.wait()
return wget_out_file.absolute()
示例14: ReleaseUnpacker
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
class ReleaseUnpacker(object):
def __init__(self, release_search_dir, tmp_dir, unpack_dir,
no_remove=False):
self.release_search_dir = Path(release_search_dir)
self.release_search_dir_abs = self.release_search_dir.absolute()
self.tmp_dir = Path(tmp_dir)
self.unpack_dir = Path(unpack_dir)
self.no_remove = no_remove
if not self.release_search_dir_abs.exists():
raise ReleaseUnpackerError(
'Release search dir {} doesn\'t exist'.format(
self.release_search_dir))
elif not self.release_search_dir_abs.isdir():
raise ReleaseUnpackerError(
'Release search dir {} is not a dir'.format(
self.release_search_dir))
elif not self.tmp_dir.exists():
raise ReleaseUnpackerError(
'Tmp dir {} doesn\'t exist'.format(self.tmp_dir))
elif not self.tmp_dir.isdir():
raise ReleaseUnpackerError(
'Tmp dir {} is not a dir'.format(
self.tmp_dir))
elif not self.unpack_dir.exists():
raise ReleaseUnpackerError(
'Unpack dir {} doesn\'t exist'.format(self.unpack_dir))
elif not self.unpack_dir.isdir():
raise ReleaseUnpackerError(
'Unpack dir {} is not a dir'.format(
self.unpack_dir))
def __repr__(self):
return '<ReleaseUnpacker: {} ({}) ({})>'.format(
self.release_search_dir_abs, self.tmp_dir, self.unpack_dir)
def file_exists_size_match(self, unpack_file_path, size_in_rar):
"""Returns True if unpack_file_path exists and size is a match"""
if (unpack_file_path.exists() and
unpack_file_path.size() == size_in_rar):
log.info('{} already exists and size match'.format(
unpack_file_path))
return True
else:
return False
def scan_rars(self):
"""Find all folders in release_search_dir and return the first RAR
file if one is found in a dir.
"""
rar_files = []
scan_dirs = [dir for dir in
self.release_search_dir_abs.walk(filter=DIRS)]
scan_dirs.append(self.release_search_dir_abs)
for dir in scan_dirs:
rar_files_found = dir.listdir(pattern='*.rar', filter=FILES)
if rar_files_found:
rar_files.append(rar_files_found[0])
return rar_files
def unpack_release_dir_rars(self):
"""Run the unpacker. Find the first RAR file in dirs found in
release_search_dir.
"""
# Scan for RAR files
self.rar_files = self.scan_rars()
if not self.rar_files:
log.debug('No RARs found in {}'.format(
self.release_search_dir_abs))
return False
# Process the RAR files in any were found
for rar_file_path in self.rar_files:
log.debug('Found RAR file {}'.format(rar_file_path))
release_unpacker_rar_file = ReleaseUnpackerRarFile(rar_file_path)
if release_unpacker_rar_file.subs_dir:
self.unpack_subs_rar(release_unpacker_rar_file)
else:
self.unpack_rar(release_unpacker_rar_file)
# Remove release dirs when unpack is done
self.remove_release_dirs()
return self
def remove_release_dirs(self):
"""Remove all release dirs from rar_files list"""
for rar_file_path in self.rar_files:
release_dir = rar_file_path.parent
if release_dir.exists():
if self.no_remove:
log.info('No remove active, not removing {}'.format(
release_dir))
else:
log.info(
#.........这里部分代码省略.........
示例15: Path
# 需要导入模块: from unipath import Path [as 别名]
# 或者: from unipath.Path import absolute [as 别名]
#! coding=utf-8
import datetime, smtplib, imp, os
from email.mime.text import MIMEText
import requests
from git import Repo
from git.errors import *
from unipath import Path
from jinja2 import Template
# Local settings are stored in $HOME/.ometrics/settings.py
# Find and load module there, creating files/dirs where appropriate
om = Path( os.environ['HOME'] ).absolute().child('.ometrics')
om.mkdir()
module_path = om.absolute()
if not om.child('settings.py').exists():
print('Copying setitngs.py into %s' % str(om.child('settings.py')))
Path(__file__).parent.child('settings.py').copy(om.child('settings.py'))
imp.load_source('settings', module_path.child('settings.py'))
from settings import *
from template import HTML_MAIL
now = datetime.datetime.utcnow()
gap = datetime.timedelta(days=INTERVAL_DAYS)
begins = now - gap