当前位置: 首页>>代码示例>>Python>>正文


Python OSFS.opendir方法代码示例

本文整理汇总了Python中fs.osfs.OSFS.opendir方法的典型用法代码示例。如果您正苦于以下问题:Python OSFS.opendir方法的具体用法?Python OSFS.opendir怎么用?Python OSFS.opendir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fs.osfs.OSFS的用法示例。


在下文中一共展示了OSFS.opendir方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cmd_scan

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
    def cmd_scan(self, *params, **options):

        favicons_fs = OSFS(settings.MEDIA_ROOT).makeopendir('favicons')

        for path in favicons_fs.walkdirs(wildcard="???"):
            icon_fs = favicons_fs.opendir(path)

            if icon_fs.isfile('scan.pik'):

                icon_sizes = ','.join(str(s) for s in sorted(int(p.split('.')[0][4:]) for p in icon_fs.listdir(wildcard='icon*.png')))
                if not icon_sizes:
                    continue

                favicon, created = FavIcon.import_(icon_fs.open('scan.pik'))
                if favicon is None:
                    continue

                old_sizes = favicon.sizes
                favicon.sizes = icon_sizes
                favicon.update()
                favicon.save()

                if created:
                    print "New object:\t", path
                else:
                    print path
                if old_sizes != favicon.sizes:
                    print "Icon sizes changed!\t", path
                    favicon.export(icon_fs.open('scan.pik', 'w'))
开发者ID:willmcgugan,项目名称:Locidesktop,代码行数:31,代码来源:favicons.py

示例2: build_folders

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
def build_folders(source, destination_temp, standards, root):
    print "Building register..."

    source_fs = OSFS(source)

    # iterate over all standards in source directory
    for standard in standards:
        print "Processing %s ... " % standard['id']
        standard_fs = source_fs.opendir(standard['id'])

        # list all sub standards of a standard
        artifacts = standard_fs.listdir(dirs_only=True)
        if '.git' in artifacts: artifacts.remove(".git")

        for artifact in artifacts:
            # check whether artifact folder exists in destination_temp 
            if root.exists('%s/%s' % (destination_temp, artifact)) == False:
                root.makedir('%s/%s' % (destination_temp, artifact))
                
            # copy standard folders from source to destination_temp in desired structure
            root.copydir('%s/%s/%s' % (source, standard['id'], artifact),  '%s/%s/%s' % (destination_temp, artifact, standard['id']))

        # create standard HTML page
        html = create_standard_webpage(standard, artifacts)

        # check whether standard folder exists in register root
        if root.exists('%s/%s' % (destination_temp, standard['id'])) == False:
            root.makedir('%s/%s' % (destination_temp, standard['id']))
        
        # write standard HTML page to register/standard/index.html
        with codecs.open('%s/%s/index.html' % (destination_temp, standard['id']), 'w', encoding='utf8') as f:
            f.write(html)
开发者ID:wilkoquak,项目名称:technisch-register,代码行数:34,代码来源:backend.py

示例3: build_folders

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
def build_folders(source, destination_temp, standard, root):
    """Transform the repos' folder structure to that of the register
    and build HTML pages for each standard.
    """

    source_fs = OSFS(source)

    print "Processing %s ... " % standard['id']
    standard_fs = source_fs.opendir(standard['id'])

    # list all artifacts of a standard
    artifacts = standard_fs.listdir(dirs_only=True)
    if '.git' in artifacts: artifacts.remove(".git")

    for artifact in artifacts:
        # check whether artifact folder exists in destination_temp 
        if root.exists('%s/%s' % (destination_temp, artifact)) == False:
            root.makedir('%s/%s' % (destination_temp, artifact))

        # copy standard folders from source to destination_temp in desired structure
        root.copydir('%s/%s/%s' % (source, standard['id'], artifact),  '%s/%s/%s' % (destination_temp, artifact, standard['id']))

    html = create_standard_webpage(standard, artifacts)

    # check whether register/standard exists
    if root.exists('%s/%s' % (destination_temp, standard['id'])) == False:
        root.makedir('%s/%s' % (destination_temp, standard['id']))
    
    # write standard HTML page to register/standard/index.html
    with codecs.open('%s/%s/index.html' % (destination_temp, standard['id']), 'w', encoding='utf8') as f:
        f.write(html)

    # copy web assets
    root.copydir('web/assets', '%s/r' % destination_temp, overwrite=True)
开发者ID:fterpstra,项目名称:technisch-register,代码行数:36,代码来源:backend.py

示例4: get_artifacts

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
def get_artifacts(root, build_path, sources_path, standard):
    source_fs = OSFS(ospath.join(root.getsyspath('.'),  build_path, sources_path))

    # print "Processing %s ... " % standard['id']
    standard_fs = source_fs.opendir(standard['id'])
    artifacts = standard_fs.listdir(dirs_only=True)
    if '.git' in artifacts: artifacts.remove(".git")

    return artifacts
开发者ID:BertScholten,项目名称:technisch-register,代码行数:11,代码来源:utils.py

示例5: cmd_import

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
    def cmd_import(self, *params, **options):

        """ Imports an icon set """

        media_fs = OSFS(settings.MEDIA_ROOT)
        iconsets_fs = media_fs.opendir('iconsets')

        try:
            iconset_name = params[0]
            iconsets = iconsets_fs.listdir(wildcard = iconset_name, dirs_only=True)

        except IndexError, e:
            print "<catalog name, or wildcard>"
            return
开发者ID:willmcgugan,项目名称:Locidesktop,代码行数:16,代码来源:icons.py

示例6: build

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
def build(fs, settings_path="settings.ini", rebuild=False, archive=None, master_settings=None):
    """Build a project"""
    if isinstance(fs, string_types):
        if '://' in fs:
            fs = fsopendir(fs)
        else:
            fs = OSFS(fs)

    if isinstance(settings_path, string_types):
        settings_path = [settings_path]
    if archive is None:
        archive = Archive(fs)
    context = Context()

    syspath = fs.getsyspath('/', allow_none=True)

    cwd = os.getcwd()

    if syspath is not None:
        os.chdir(syspath)

    try:
        root = context.root
        root['libs'] = archive.libs
        root['apps'] = archive.apps
        root['fs'] = FSWrapper(fs)

        log.debug("reading settings from {}".format(textual_list(settings_path)))
        archive.cfg = SettingsContainer.read(fs, settings_path, master=master_settings)
        root['settings'] = SettingsContainer.from_dict(archive.cfg['settings'])
        startup_path = archive.cfg.get('project', 'startup')
        docs_location = archive.cfg.get('project', 'location')

        archive.init_settings()
        root['console'] = archive.console
        root['debug'] = archive.debug
        root['_rebuild'] = rebuild

        parser = Parser(archive, fs.opendir(docs_location), startup_path)
        doc = parser.parse()

        if doc is None:
            raise errors.StartupFailedError('unable to parse "{}"'.format(startup_path))

        archive.build(doc, fs=fs)

        return archive, context, doc

    finally:
        os.chdir(cwd)
开发者ID:chrmorais,项目名称:moya,代码行数:52,代码来源:build.py

示例7: cmd_makepreviews

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
    def cmd_makepreviews(self, *params, **options):

        PREVIEW_ICON_SIZE = 32
        WIDTH_COUNT = 11
        BORDER = 5

        ICON_DIMENSIONS = (BORDER*2 + PREVIEW_ICON_SIZE)

        preview_width = ICON_DIMENSIONS * WIDTH_COUNT

        media_fs = OSFS(settings.MEDIA_ROOT)
        media_fs.makedir('iconsetpreviews', allow_recreate=True)
        previews_fs = media_fs.opendir('iconsetpreviews')

        for catalog in IconCatalog.objects.all():

            for category in catalog.get_categories():

                filename =  "%s.%s.jpg" % (catalog.name, category)

                icons = catalog.icon_set.filter(category=category).order_by('name')
                num_icons = icons.count()

                icons_height_count = (num_icons + WIDTH_COUNT-1) // WIDTH_COUNT
                preview_height = icons_height_count * ICON_DIMENSIONS

                preview_img = Image.new('RGB', (preview_width, preview_height), (255, 255, 255))
                print preview_width, preview_height

                for i, icon in enumerate(icons):

                    y, x = divmod(i, WIDTH_COUNT)

                    pth = icon.path.replace('[SIZE]', str(PREVIEW_ICON_SIZE))

                    icon_pth = media_fs.getsyspath(pth)

                    img = Image.open(icon_pth)
                    if img.size[0] != img.size[1]:
                        img = img.crop((0, 0, PREVIEW_ICON_SIZE, PREVIEW_ICON_SIZE))
                    try:
                        preview_img.paste(img, (x*ICON_DIMENSIONS+BORDER, y*ICON_DIMENSIONS+BORDER), img)
                    except ValueError:
                        preview_img.paste(img, (x*ICON_DIMENSIONS+BORDER, y*ICON_DIMENSIONS+BORDER))


                sys_filename = previews_fs.getsyspath(filename)
                print sys_filename
                preview_img.save(previews_fs.getsyspath(filename), quality=75)
开发者ID:willmcgugan,项目名称:Locidesktop,代码行数:51,代码来源:icons.py

示例8: cmd_optimize

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
    def cmd_optimize(self, *params, **options):

        """ Optimizes icon images. """

        media_fs = OSFS(settings.MEDIA_ROOT)
        iconsets_fs = media_fs.opendir('iconsets')

        count = 0
        for filename in list(iconsets_fs.walkfiles(wildcard="*.png")):

            sys_filename = iconsets_fs.getsyspath(filename)
            try:
                os.system('optipng -o3 -q "%s"' % sys_filename)
            except Exception, e:
                print "Error:", str(e)
            else:
                print "Optimized", filename

            #sys_filename = iconsets_fs.getsyspath(filename)
            #img = Image.open(sys_filename)
            #img.save(sys_filename, optimize=True)
            #print '.',
            count += 1
开发者ID:willmcgugan,项目名称:Locidesktop,代码行数:25,代码来源:icons.py

示例9: cmd_makeadminpreviews

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
    def cmd_makeadminpreviews(self, *params, **options):
        try:
            iconset = params[0]
        except IndexError:
            iconset = ''

        icon_fs = OSFS(settings.MEDIA_ROOT).opendir('iconsets')
        if params:
            icon_fs = icon_fs.opendir(params[0])

        done_dirs = set()
        for path in icon_fs.walkfiles(wildcard='*.png'):
            dirpath = dirname(path)
            png_path = icon_fs.getsyspath(path)
            img = Image.open(png_path).convert('RGBA')
            background_img = Image.new('RGB', img.size, (255, 255, 255))

            background_img.paste(img, None, img)

            new_path = os.path.splitext(png_path)[0] + '.jpg'
            background_img.save(new_path)
            if dirpath not in done_dirs:
                print "Generating admin previews in %s/*" % dirpath
                done_dirs.add(dirpath)            
开发者ID:willmcgugan,项目名称:Locidesktop,代码行数:26,代码来源:icons.py

示例10: OSFS

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]

try:
    src = sys.argv[1]
    dst = sys.argv[2]
except IndexError:
    src = '~/projects/linkstop/webapp/linkstop/media/faviconsx'
    dst = '~/projects/linkstop/webapp/linkstop/media/favicons'

src_fs = OSFS(src)
dst_fs = OSFS(dst)

count = 0
max_count = 2
for path in src_fs.listdir(dirs_only=True):
    icon_fs = src_fs.opendir(path)
    if icon_fs.isfile('scan.pik'):
        try:
            icon = pickle.load(icon_fs.open('scan.pik'))
        except Exception, e:
            print "%s (%s)" % (str(e), path)
            continue
        normalized_url = icon['normalized_url']
        out_dir = hash_path(normalized_url) + '/' + url_to_filename(normalized_url)
        print out_dir

        dest_dir_fs = dst_fs.makeopendir(out_dir, recursive=True)


        movedir(icon_fs, dest_dir_fs, overwrite=True, ignore_errors=True)
开发者ID:willmcgugan,项目名称:Locidesktop,代码行数:31,代码来源:shardfavicons.py

示例11: build_server

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import opendir [as 别名]
def build_server(fs,
                 settings_path,
                 server_element="main",
                 no_console=False,
                 rebuild=False,
                 validate_db=False,
                 breakpoint=False,
                 master_settings=None):
    """Build a server"""
    start = time()
    archive = Archive()
    console = archive.console
    try:
        archive, context, doc = build(fs, settings_path, rebuild=rebuild, master_settings=master_settings)
        console = archive.console
    except errors.ParseError as e:
        if not no_console:
            line, col = e.position
            console.document_error(text_type(e),
                                   e.path,
                                   e.code,
                                   line,
                                   col)
        return None
    except errors.ElementError as element_error:
        if not no_console:
            line = element_error.source_line
            col = 0
            console.document_error(text_type(element_error),
                                   element_error.element._location,
                                   element_error.element._code,
                                   line,
                                   col)
        raise errors.StartupFailedError('Failed to build project')

    if isinstance(fs, string_types):
        if '://' in fs:
            fs = fsopendir(fs)
        else:
            fs = OSFS(fs)
    archive.project_fs = fs

    try:
        app, server = doc.get_element(server_element)
    except errors.ElementNotFoundError:
        raise errors.StartupFailedError("no <server> element called '{}' found in the project (check setting [project]/startup)".format(server_element))
    error_msg = None
    docs_location = archive.cfg.get('project', 'location')
    try:
        server.startup(archive, context, fs.opendir(docs_location), breakpoint=breakpoint)
    except errors.StartupFailedError as error:
        error_msg = text_type(error)
        #raise
    except errors.ElementError as e:
        raise
    except Exception as e:
        failed = render_failed_documents(archive, console, no_console=no_console)
        if failed:
            raise errors.StartupFailedError("{} document(s) failed to build".format(failed))

        if hasattr(e, '__moyaconsole__'):
            e.__moyaconsole__(console)
        error_msg = text_type(e)
        raise errors.StartupFailedError(error_msg or 'Failed to build project')

    failed = render_failed_documents(archive, console, no_console=no_console)
    if failed:
        raise errors.StartupFailedError(error_msg or 'Failed to build project')

   # archive.finalize()
    archive.init_media()
    archive.init_data()

    if validate_db:
        from . import db
        if db.validate_all(archive, console) == 0:
            startup_log.debug('models validated successfully')
        else:
            msg = "Models failed to validate, see 'moya db validate' for more information"
            raise errors.StartupFailedError(msg)

    startup_log.info("%s built %.1fms", server, (time() - start) * 1000.0)
    return ServerBuildResult(archive=archive,
                             context=context,
                             server=server)
开发者ID:chrmorais,项目名称:moya,代码行数:87,代码来源:build.py


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