• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python path.local函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中py.path.local函数的典型用法代码示例。如果您正苦于以下问题:Python local函数的具体用法?Python local怎么用?Python local使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了local函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:razvanch,项目名称:meetings-registration-tool,代码行数:35,代码来源:test_meeting_participant_picture.py


示例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(),
     }
开发者ID:apagac,项目名称:cfme_tests,代码行数:28,代码来源:__init__.py


示例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()
     }
开发者ID:amavinag,项目名称:cfme_tests,代码行数:28,代码来源:__init__.py


示例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()
开发者ID:ManageIQ,项目名称:integration_tests,代码行数:34,代码来源:composite.py


示例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()
开发者ID:razvanch,项目名称:meetings-registration-tool,代码行数:34,代码来源:test_meeting_participant_picture.py


示例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)
开发者ID:jwadkins,项目名称:cfme_tests,代码行数:32,代码来源:cfme_data.py


示例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
开发者ID:ManageIQ,项目名称:integration_tests,代码行数:34,代码来源:composite.py


示例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)
开发者ID:pylada,项目名称:pylada-light,代码行数:9,代码来源:__init__.py


示例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
开发者ID:judy2k,项目名称:envtool,代码行数:9,代码来源:test_envtool.py


示例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
开发者ID:AmericanSundown,项目名称:coding-events,代码行数:56,代码来源:test_events_processors.py


示例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')
开发者ID:paskma,项目名称:py,代码行数:10,代码来源:test_local.py


示例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)
开发者ID:andyplusplus,项目名称:scripts,代码行数:10,代码来源:rename-m.py


示例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
开发者ID:arve0,项目名称:leicaexperiment,代码行数:54,代码来源:test_experiment.py


示例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)
开发者ID:bcrochet,项目名称:cfme_tests,代码行数:13,代码来源:credentials.py


示例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
开发者ID:MattSkinner,项目名称:pypiserver,代码行数:14,代码来源:test_server.py


示例16: server_hierarchy

def server_hierarchy(prefix):
    from py.path import local
    srv = local(prefix).join('build', 'srv', 'salt')
    srv.ensure(dir=True)
    if not srv.join('_states').exists():
        srv.join('_states').mksymlinkto(local(condiment_dir).join('_states'))
    if not srv.join('_modules').exists():
        srv.join('_modules').mksymlinkto(local(condiment_dir).join('_modules'))
    if not srv.join('_grains').exists():
        srv.join('_grains').mksymlinkto(local(condiment_dir).join('_grains'))

    local(prefix).join('build', 'etc', 'salt').ensure(dir=True)
    local(prefix).join('build', 'var', 'log', 'salt').ensure(dir=True)
    local(prefix).join('build', 'var', 'cache',
                       'salt', 'master').ensure(dir=True)
开发者ID:UCL-RITS,项目名称:CondimentStation,代码行数:15,代码来源:setup.py


示例17: test_initialize_reldir

 def test_initialize_reldir(self):
     old = self.root.chdir()
     try:
         p = local('samplefile')
         assert p.check()
     finally:
         old.chdir()
开发者ID:paskma,项目名称:py,代码行数:7,代码来源:test_local.py


示例18: __init__

 def __init__(self, directory=None, prefix='pwscf'):
     from py.path import local
     super(Extract, self).__init__()
     self.directory = str(local() if directory is None else directory)
     """ Directory where files are to be found """
     self.prefix = prefix
     """ Prefix for files and subdirectory """
开发者ID:pylada,项目名称:pylada-light,代码行数:7,代码来源:extract.py


示例19: test_create_event_from_dict_with_all_fields

    def test_create_event_from_dict_with_all_fields(self):
        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)
        self.assertEqual(2, test_event.pk)
        self.assertEqual("Ljubljana", test_event.location)
        self.assertEqual("46.05528", str(test_event.geoposition.latitude))
        self.assertIn("tag1", test_event.tags.names())
        self.assertIn("tag2", test_event.tags.names())

        assert "event_picture/alja" in test_event.picture.path
开发者ID:naisnouk,项目名称:coding-events,代码行数:31,代码来源:test_events_processors.py


示例20: test_meeting_custom_logos

def test_meeting_custom_logos(app, user, brand_dir):
    meeting = MeetingFactory()
    right_logo = (StringIO('Right'), 'right.png')
    left_logo = (StringIO('Left'), 'left.jpg')
    upload_dir = local(app.config['UPLOADED_LOGOS_DEST'])

    with app.test_request_context():
        resp = upload_new_logo(app, user, meeting.id, 'PRODUCT_LOGO', left_logo)
        product_logo = Logo('product_logo')

        assert product_logo.url in resp.data
        assert upload_dir.join(product_logo.filename).check()

        resp = upload_new_logo(app, user, meeting.id, 'PRODUCT_SIDE_LOGO',
                               right_logo)
        product_side_logo = Logo('product_side_logo')

        assert product_side_logo.url in resp.data
        assert upload_dir.join(product_side_logo.filename).check()

    client = app.test_client()
    with app.test_request_context():
        with client.session_transaction() as sess:
            sess['user_id'] = user.id
        resp = client.get(url_for('meetings.logos', meeting_id=meeting.id))
        assert resp.status_code == 200
        html = PyQuery(resp.data)
        logo_src = html('#PRODUCT_LOGO a').attr('href')
        assert logo_src == product_logo.url
        side_logo_src = html('#PRODUCT_SIDE_LOGO a').attr('href')
        assert side_logo_src == product_side_logo.url

        remove_buttons = html('.remove-photo.disabled ')
        assert len(remove_buttons) == 0
开发者ID:razvanch,项目名称:meetings-registration-tool,代码行数:34,代码来源:test_meeting_logos.py



注:本文中的py.path.local函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python test.raises函数代码示例发布时间:2022-05-25
下一篇:
Python code.Source类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap