本文整理汇总了Python中py.path.local函数的典型用法代码示例。如果您正苦于以下问题:Python local函数的具体用法?Python local怎么用?Python local使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了local函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_participant_picture_rotate_deletes_all_old_files
def test_participant_picture_rotate_deletes_all_old_files(app, user):
pic = ProfilePictureFactory()
filename = pic.value
pic.custom_field.meeting.photo_field = pic.custom_field
upload_dir = local(app.config['UPLOADED_CUSTOM_DEST'])
crop_dir = local(app.config['UPLOADED_CROP_DEST'] /
app.config['PATH_CUSTOM_KEY'])
thumb_crop_dir = local(app.config['UPLOADED_THUMBNAIL_DEST'] /
app.config['PATH_CROP_KEY'] /
app.config['PATH_CUSTOM_KEY'])
thumb_dir = local(app.config['UPLOADED_THUMBNAIL_DEST'] /
app.config['PATH_CUSTOM_KEY'])
image = Image.new('RGB', (250, 250), 'red')
image.save(str(upload_dir.join(filename)))
crop_dir.ensure(filename)
thumb_name, thumb_fm = os.path.splitext(filename)
thumb_full_name = Thumbnail._get_name(thumb_name, thumb_fm,
'200x200', 85)
thumb_crop_dir.ensure(thumb_full_name)
thumb_dir.ensure(thumb_full_name)
with app.test_request_context():
with app.client.session_transaction() as sess:
sess['user_id'] = user.id
url = url_for('meetings.custom_field_rotate',
meeting_id=pic.custom_field.meeting.id,
participant_id=pic.participant.id,
field_slug=pic.custom_field.slug)
resp = app.client.post(url)
assert resp.status_code == 200
assert not upload_dir.join(filename).check()
assert not crop_dir.join(filename).check()
assert not thumb_crop_dir.join(thumb_full_name).check()
assert not thumb_dir.join(thumb_full_name).check()
示例2: parse_config
def parse_config(self):
"""
Reads the config data and sets up values
"""
if not self.config:
return False
self.log_dir = local(self.config.get("log_dir", log_path))
self.log_dir.ensure(dir=True)
self.artifact_dir = local(self.config.get("artifact_dir", log_path.join("artifacts")))
self.artifact_dir.ensure(dir=True)
self.logger = create_logger("artifactor", self.log_dir.join("artifactor.log").strpath)
self.squash_exceptions = self.config.get("squash_exceptions", False)
if not self.log_dir:
print("!!! Log dir must be specified in yaml")
sys.exit(127)
if not self.artifact_dir:
print("!!! Artifact dir must be specified in yaml")
sys.exit(127)
self.config["zmq_socket_address"] = "tcp://127.0.0.1:{}".format(random_port())
self.setup_plugin_instances()
self.start_server()
self.global_data = {
"artifactor_config": self.config,
"log_dir": self.log_dir.strpath,
"artifact_dir": self.artifact_dir.strpath,
"artifacts": dict(),
"old_artifacts": dict(),
}
示例3: parse_config
def parse_config(self):
"""
Reads the config data and sets up values
"""
if not self.config:
return False
self.log_dir = local(self.config.get('log_dir', log_path))
self.log_dir.ensure(dir=True)
self.artifact_dir = local(self.config.get('artifact_dir', log_path.join('artifacts')))
self.artifact_dir.ensure(dir=True)
self.logger = create_logger('artifactor', self.log_dir.join('artifactor.log').strpath)
self.squash_exceptions = self.config.get('squash_exceptions', False)
if not self.log_dir:
print "!!! Log dir must be specified in yaml"
sys.exit(127)
if not self.artifact_dir:
print "!!! Artifact dir must be specified in yaml"
sys.exit(127)
self.config['zmq_socket_address'] = 'tcp://127.0.0.1:{}'.format(random_port())
self.setup_plugin_instances()
self.start_server()
self.global_data = {
'artifactor_config': self.config,
'log_dir': self.log_dir.strpath,
'artifact_dir': self.artifact_dir.strpath,
'artifacts': dict(),
'old_artifacts': dict()
}
示例4: _queue_worker
def _queue_worker(rc):
# multithreaded file puller, takes tuples of remote, local, item, items_done
# pulls the files and then updates the progress meter
jenkins_host = composite['jenkins_host']
client = rc.ssh_client
client.connect(jenkins_host, username=credentials['jenkins-result']['username'],
password=credentials['jenkins-result']['password'],
timeout=10,
allow_agent=False,
look_for_keys=False,
gss_auth=False)
scp = None
while True:
source, destination, item, items_done = rc._queue.get()
destination = local(destination)
destination_dir = local(destination.dirname)
destination_dir.ensure(dir=True)
if not destination.check():
if scp is None:
scp = SCPClient(client.get_transport())
try:
scp.get(source, destination.strpath)
except SCPException:
# remote destination didn't exist
pass
except (SSHException, socket.timeout):
# SSH blew up :(
rc._queue.put((source, destination, item, items_done))
rc._queue.task_done()
continue
rc._progress_update(item, items_done)
rc._queue.task_done()
示例5: test_participant_picture_change_deletes_all_old_files
def test_participant_picture_change_deletes_all_old_files(app, user):
pic = ProfilePictureFactory()
filename = pic.value
pic.custom_field.meeting.photo_field = pic.custom_field
upload_dir = local(app.config['UPLOADED_CUSTOM_DEST'])
crop_dir = local(app.config['UPLOADED_CROP_DEST'] /
app.config['PATH_CUSTOM_KEY'])
thumb_crop_dir = local(app.config['UPLOADED_THUMBNAIL_DEST'] /
app.config['PATH_CROP_KEY'] /
app.config['PATH_CUSTOM_KEY'])
thumb_dir = local(app.config['UPLOADED_THUMBNAIL_DEST'] /
app.config['PATH_CUSTOM_KEY'])
upload_dir.ensure(filename)
crop_dir.ensure(filename)
thumb_name, thumb_fm = os.path.splitext(filename)
thumb_full_name = Thumbnail._get_name(thumb_name, thumb_fm,
'200x200', 85)
thumb_crop_dir.ensure(thumb_full_name)
thumb_dir.ensure(thumb_full_name)
data = {'picture': (StringIO('Test'), 'test_edit.png')}
with app.test_request_context():
with app.client.session_transaction() as sess:
sess['user_id'] = user.id
resp = app.client.post(url_for('meetings.custom_field_upload',
meeting_id=pic.custom_field.meeting.id,
participant_id=pic.participant.id,
field_slug=pic.custom_field.slug),
data=data)
assert resp.status_code == 200
assert not upload_dir.join(filename).check()
assert not crop_dir.join(filename).check()
assert not thumb_crop_dir.join(thumb_full_name).check()
assert not thumb_dir.join(thumb_full_name).check()
示例6: load_cfme_data
def load_cfme_data(filename=None):
"""Loads the cfme_data YAML from the given filename
If the filename is omitted or None, attempts will be made to load it from
its normal location in the parent of the utils directory.
The cfme_data dict loaded with this method supports value randomization,
thanks to the RandomizeValues class. See that class for possible options
Example usage in cfme_data.yaml (quotes are important!):
top_level:
list:
- "{random_str}"
- "{random_int}"
- "{random_uuid}"
random_thing: "{random_string:24}"
"""
if filename is None:
this_file = os.path.abspath(__file__)
path = local(this_file).new(basename="../cfme_data.yaml")
else:
path = local(filename)
if path.check():
cfme_data_fh = path.open()
cfme_data_dict = yaml.load(cfme_data_fh)
return RandomizeValues.from_dict(cfme_data_dict)
else:
msg = "Usable to load cfme_data file at %s" % path
raise Exception(msg)
示例7: test_reports
def test_reports(self):
print('Collecting test reports to determine best build nodes')
log_dirs = self.template_log_dirs()
reports = {}
c = self.ssh_client
jenkins_host = composite['jenkins_host']
c.connect(jenkins_host, username=credentials['jenkins-result']['username'],
password=credentials['jenkins-result']['password'],
timeout=10,
allow_agent=False,
look_for_keys=False,
gss_auth=False)
builds_done = {}
self._progress_update(None, builds_done)
for build_number, log_dir in log_dirs:
build_work_dir = local(self.work_dir.join(str(build_number)))
build_work_dir.ensure(dir=True)
_remote = local(log_dir).join('test-report.json').strpath
_local = build_work_dir.join('test-report.json').strpath
builds_done[build_number] = False
self._progress_update(None, builds_done)
self._queue.put((_remote, _local, build_number, builds_done))
self._queue.join()
self._progress_finish()
for build_number, __ in log_dirs:
build_work_dir = local(self.work_dir.join(str(build_number)))
for path in build_work_dir.visit('*/test-report.json'):
try:
report = json.load(path.open())
reports[build_number] = report
except:
# invalid json, skip this report
pass
return reports
示例8: local_path
def local_path(path=None, *args):
""" Returns a py.path, expanding environment variables """
from os.path import expandvars
from py.path import local
if path is None:
return local(*args)
if isinstance(path, str):
return local(expandvars(path), expanduser=True).join(*args)
return path.join(*args)
示例9: test_cli_incorrect_param
def test_cli_incorrect_param():
runner = CliRunner()
with runner.isolated_filesystem():
src = local('src')
dest = local('dest')
src.mkdir()
dest.mkdir()
result = runner.invoke(envtool.main, ['convert', str(src), str(dest)])
assert result.exit_code == -1
示例10: test_edit_event_with_all_fields
def test_edit_event_with_all_fields(self):
# First create a new event
with open(local(__file__).dirname + '/../../static/img/team/alja.jpg') as fp:
io = StringIO.StringIO()
io.write(fp.read())
uploaded_picture = InMemoryUploadedFile(
io, None, "alja.jpg", "jpeg", io.len, None)
uploaded_picture.seek(0)
event_data = {
"end_date": datetime.datetime.now(),
"start_date": datetime.datetime.now(),
"organizer": "some organizer",
"creator": User.objects.filter(pk=1)[0],
"title": "event title",
"pub_date": datetime.datetime.now(),
"country": "SI",
"geoposition": Geoposition(46.05528, 14.51444),
"location": "Ljubljana",
"audience": [1],
"theme": [1],
"tags": ["tag1", "tag2"],
"picture": uploaded_picture
}
test_event = create_or_update_event(**event_data)
# Then edit it
with open(local(__file__).dirname + '/../../static/img/team/ercchy.jpg') as fp:
io = StringIO.StringIO()
io.write(fp.read())
uploaded_picture = InMemoryUploadedFile(
io, None, "ercchy.jpg", "jpeg", io.len, None)
uploaded_picture.seek(0)
event_data = {
"end_date": datetime.datetime.now(),
"start_date": datetime.datetime.now(),
"organizer": "another organiser",
"creator": User.objects.filter(pk=1)[0],
"title": "event title - edited",
"pub_date": datetime.datetime.now(),
"country": "SI",
# "geoposition": Geoposition(46.05528,14.51444),
"location": "Ljubljana",
"audience": [1],
"theme": [1],
"tags": ["tag3", "tag4"],
"picture": uploaded_picture
}
test_event = create_or_update_event(
event_id=test_event.id, **event_data)
assert "tag1" not in test_event.tags.names()
assert 'event_picture/alja' not in test_event.picture
assert 'event_picture/ercchy' in test_event.picture.path
示例11: test_init_from_path
def test_init_from_path(self):
l = local()
l2 = local(l)
assert l2 is l
wc = py.path.svnwc('.')
l3 = local(wc)
assert l3 is not wc
assert l3.strpath == wc.strpath
assert not hasattr(l3, 'commit')
示例12: main
def main():
"""Define our main top-level entry point"""
root = local(sys.argv[1]) # 1 to skip the program name
pattern = sys.argv[2]
if local(sys.argv[0]).purebasename == "renamefiles":
rename_files(root, pattern)
else:
rename_dirs(root, pattern)
示例13: test_compression
def test_compression(tmpdir, experiment):
"It should compress and decompress experiment without dataloss."
from leicaexperiment.experiment import decompress
from PIL import Image
import numpy as np
# compress
pngs = experiment.compress(folder=tmpdir.mkdir('pngs').strpath)
# reported output is actually written and the same amount
assert pngs == tmpdir.join('pngs').listdir('*.png', sort=True)
assert len(pngs) == len(experiment.images)
# keep data for decompress test
origs = []
orig_tags = []
# check that compression is lossless
for tif,png in zip(experiment.images, pngs):
img = Image.open(tif)
orig = np.array(img)
origs.append(orig)
orig_tags.append(img.tag.as_dict())
compressed = np.array(Image.open(png))
# is lossless?
assert np.all(orig == compressed)
new_tifs = decompress(pngs, folder=tmpdir.mkdir('new_tifs').strpath)
# reported output is actually written and the same amount as original
assert new_tifs == tmpdir.join('new_tifs').listdir(sort=True)
assert len(new_tifs) == len(experiment.images)
# orig and decompressed images have similar file size
for orig,new_tif in zip(experiment.images, new_tifs):
diff = abs(path.local(orig).size() - path.local(new_tif).size())
assert diff < 1024
omit_tags = [273, 278, 279]
# check that decompression is lossless
for tif,orig,orig_tag in zip(new_tifs, origs, orig_tags):
img = Image.open(tif)
decompressed = np.array(img)
# compress->decompress is lossless?
assert np.all(orig == decompressed)
# check if TIFF-tags are intact
tag = img.tag.as_dict()
for omit in omit_tags:
del tag[omit]
del orig_tag[omit]
assert tag == orig_tag
示例14: load_credentials
def load_credentials(filename=None):
if filename is None:
this_file = os.path.abspath(__file__)
path = local(this_file).new(basename='../credentials.yaml')
else:
path = local(filename)
if path.check():
credentials_fh = path.open()
credentials_dict = yaml.load(credentials_fh)
return credentials_dict
else:
msg = 'Usable to load credentials file at %s' % path
raise Exception(msg)
示例15: project
def project(request):
def fin():
tmpdir.remove(True)
tmpdir = path.local(tempfile.mkdtemp())
request.addfinalizer(fin)
src_setup_py = path.local().join('tests', 'centodeps-setup.py')
assert src_setup_py.check()
projdir = tmpdir.join('centodeps')
projdir.mkdir()
dst_setup_py = projdir.join('setup.py')
src_setup_py.copy(dst_setup_py)
assert dst_setup_py.check()
return projdir