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


Python OSFS.getsyspath方法代码示例

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


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

示例1: run

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import getsyspath [as 别名]
    def run(self):
        args = self.args
        device_class = args.device_class
        conf_path = constants.CONF_PATH

        if not os.path.exists(conf_path):
            sys.stderr.write('{} does not exist.\n'.format(conf_path))
            sys.stderr.write("please run 'dataplicity init' first\n")
            return -1

        print("reading conf from {}".format(conf_path))
        cfg = settings.read(conf_path)
        serial = cfg.get('device', 'serial')
        auth_token = cfg.get('device', 'auth')
        server_url = cfg.get('server', 'url', constants.SERVER_URL)

        remote = jsonrpc.JSONRPC(server_url)

        print("downloading firmware...")
        with remote.batch() as batch:
            batch.call_with_id('register_result',
                               'device.register',
                               auth_token=auth_token,
                               name=args.name or serial,
                               serial=serial,
                               device_class_name=device_class)
            batch.call_with_id('auth_result',
                               'device.check_auth',
                               device_class=device_class,
                               serial=serial,
                               auth_token=auth_token)
            batch.call_with_id('firmware_result',
                               'device.get_firmware')
        batch.get_result('register_result')
        batch.get_result('auth_result')
        fw = batch.get_result('firmware_result')

        if not fw['firmware']:
            sys.stderr.write('no firmware available!\n')
            return -1
        version = fw['version']

        firmware_bin = b64decode(fw['firmware'])
        firmware_file = BytesIO(firmware_bin)
        firmware_fs = ZipFS(firmware_file)

        dst_fs = OSFS(constants.FIRMWARE_PATH, create=True)

        firmware.install(device_class,
                         version,
                         firmware_fs,
                         dst_fs)

        fw_path = dst_fs.getsyspath('/')
        print("installed firmware {} to {}".format(version, fw_path))

        firmware.activate(device_class, version, dst_fs)
        print("activated {}".format(version))
开发者ID:alextgn63,项目名称:dataplicity,代码行数:60,代码来源:deploy.py

示例2: build

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import getsyspath [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

示例3: cmd_makepreviews

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import getsyspath [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

示例4: deploy

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import getsyspath [as 别名]
    def deploy(self):
        """Deploy latest firmware"""
        self.log.info("requesting firmware...")
        with self.remote.batch() as batch:
            batch.call_with_id('register_result',
                               'device.register',
                               auth_token=self.auth_token,
                               name=self.name or self.serial,
                               serial=self.serial,
                               device_class_name=self.device_class)
            batch.call_with_id('auth_result',
                               'device.check_auth',
                               device_class=self.device_class,
                               serial=self.serial,
                               auth_token=self.auth_token)
            batch.call_with_id('firmware_result',
                               'device.get_firmware')
        try:
            batch.get_result('register_result')
        except Exception as e:
            self.log.warning(e)
        batch.get_result('auth_result')

        fw = batch.get_result('firmware_result')
        if not fw['firmware']:
            self.log.warning('no firmware available!')
            return False
        version = fw['version']

        firmware_bin = b64decode(fw['firmware'])
        firmware_file = StringIO(firmware_bin)
        firmware_fs = ZipFS(firmware_file)

        dst_fs = OSFS(constants.FIRMWARE_PATH, create=True)

        firmware.install(self.device_class,
                         version,
                         firmware_fs,
                         dst_fs)

        fw_path = dst_fs.getsyspath('/')
        self.log.info("installed firmware {:010} to {}".format(version, fw_path))

        firmware.activate(self.device_class, version, dst_fs)
        self.log.info("activated firmware {:010}".format(version))
开发者ID:Vladimirek,项目名称:dataplicity,代码行数:47,代码来源:client.py

示例5: cmd_makeadminpreviews

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import getsyspath [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

示例6: run

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import getsyspath [as 别名]
    def run(self):
        parser = self.get_argparse()
        args = parser.parse_args(sys.argv[1:])

        if args.version is None:
            major, minor = __version__.split('.')[:2]
            version = "{}.{}".format(major, minor)
        else:
            version = args.version

        try:
            with open(expanduser(args.settings), 'rt') as f_ini:
                cfg = SettingsContainer.read_from_file(f_ini)
                print("Read settings from {}".format(args.settings))
        except IOError:
            cfg = SettingsContainer()

        from ..docgen.extracter import Extracter
        from ..docgen.builder import Builder
        from ..command import doc_project
        location = dirname(doc_project.__file__)

        extract_fs = OSFS(join('doccode', version), create=True)
        base_docs_fs = OSFS('text')
        languages = [d for d in base_docs_fs.listdir(dirs_only=True) if len(d) == 2]

        def do_extract():
            print("Extracting docs v{}".format(version))
            utils.remove_all(extract_fs, '/')
            try:
                archive, context, doc = moya_build.build_server(location, 'settings.ini')
            except Exception:
                raise
                return -1

            extract_fs.makedir("site/docs", recursive=True)
            extract_fs.makedir("site/tags", recursive=True)
            #extract_fs.makedir("libs")

            with extract_fs.opendir('site/tags') as tags_fs:
                extracter = Extracter(archive, tags_fs)
                const_data = {}
                builtin_tags = []
                for namespace in self.builtin_namespaces:
                    xmlns = getattr(namespaces, namespace, None)
                    if xmlns is None:
                        raise ValueError("XML namespace '{}' is not in namespaces.py".format(namespace))
                    namespace_tags = archive.registry.get_elements_in_xmlns(xmlns).values()
                    builtin_tags.extend(namespace_tags)

                extracter.extract_tags(builtin_tags, const_data=const_data)

            for language in languages:
                with extract_fs.makeopendir("site/docs") as language_fs:
                    doc_extracter = Extracter(None, language_fs)
                    docs_fs = base_docs_fs.opendir(language)
                    doc_extracter.extract_site_docs(docs_fs, dirname=language)

        if args.extract:
            do_extract()

        if args.build:
            theme_path = cfg.get('paths', 'theme', None)
            dst_path = join('html', version)
            if theme_path is None:
                theme_fs = OSFS('theme')
            else:
                theme_fs = fsopendir(theme_path)

            output_path = cfg.get('paths', 'output', None)

            if output_path is None:
                output_base_fs = OSFS(dst_path, create=True)
            else:
                output_root_base_fs = fsopendir(output_path)
                output_base_fs = output_root_base_fs.makeopendir(dst_path, recursive=True)

            #output_base_fs = OSFS(join('html', version), create=True)
            utils.remove_all(output_base_fs, '/')

            def do_build():
                print("Building docs v{}".format(version))
                lib_info = {}
                lib_paths = {}
                for long_name, lib in self.document_libs:
                    lib_info[long_name] = moya_build.get_lib_info(lib)
                    lib_paths[long_name] = output_base_fs.getsyspath(join('libs', long_name, 'index.html'))
                for language in languages:
                    docs_fs = base_docs_fs.makeopendir(language)
                    output_fs = output_base_fs.makeopendir(language)
                    utils.remove_all(output_fs, '/')

                    with extract_fs.opendir("site") as extract_site_fs:
                        builder = Builder(extract_site_fs, output_fs, theme_fs)
                        from ..tools import timer
                        with timer('render time'):
                            builder.build({"libs": lib_info,
                                           "lib_paths": lib_paths})

                    # output_base_fs.makedir("libs", allow_recreate=True)
#.........这里部分代码省略.........
开发者ID:chrmorais,项目名称:moya,代码行数:103,代码来源:moyadoc.py

示例7: OSFS

# 需要导入模块: from fs.osfs import OSFS [as 别名]
# 或者: from fs.osfs.OSFS import getsyspath [as 别名]
#!/usr/bin/env python
import sys
from fs.osfs import OSFS
import Image

img_fs = OSFS(sys.argv[1])

imgs = []

for path in img_fs.listdir(wildcard='*.png'):
    img = Image.open(img_fs.getsyspath(path))
    size = img.size[0]

    if size != 16:
        continue

    imgs.append((path, img))

sprite = Image.new('RGBA', (16, len(imgs)*16))

imgs.sort(key=lambda i:i[0])

sprite_text_f = img_fs.open('sprites.txt', 'wt')

for i, (path, img) in enumerate(imgs):
    y = i*16
    sprite.paste(img, (0, y))
    sprite_text_f.write( "%i\t%s\n" % (y, path))

sprite.save(img_fs.getsyspath('sprites.png'))
开发者ID:willmcgugan,项目名称:Locidesktop,代码行数:32,代码来源:makesprites.py


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