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


Python osfs.OSFS类代码示例

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


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

示例1: cmd_scan

    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,代码行数:29,代码来源:favicons.py

示例2: export

    def export(self):
        """
        Perform the export given the parameters handed to this class at init.
        """
        with self.modulestore.bulk_operations(self.courselike_key):

            fsm = OSFS(self.root_dir)
            root = lxml.etree.Element("unknown")

            # export only the published content
            with self.modulestore.branch_setting(ModuleStoreEnum.Branch.published_only, self.courselike_key):
                courselike = self.get_courselike()
                export_fs = courselike.runtime.export_fs = fsm.makeopendir(self.target_dir)

                # change all of the references inside the course to use the xml expected key type w/o version & branch
                xml_centric_courselike_key = self.get_key()
                adapt_references(courselike, xml_centric_courselike_key, export_fs)
                courselike.add_xml_to_node(root)

            # Make any needed adjustments to the root node.
            self.process_root(root, export_fs)

            # Process extra items-- drafts, assets, etc
            root_courselike_dir = self.root_dir + "/" + self.target_dir
            self.process_extra(root, courselike, root_courselike_dir, xml_centric_courselike_key, export_fs)

            # Any last pass adjustments
            self.post_process(root, export_fs)
开发者ID:solashirai,项目名称:edx-platform,代码行数:28,代码来源:xml_exporter.py

示例3: detect_format

def detect_format(source):
    fs = OSFS(source)
    if fs.walkfiles('/', '*.morph'):
        return 'baserock-morphologies'
    if fs.walkfiles('/', '*.cida'):
        return 'cida-definitions'
    return None
开发者ID:gtristan,项目名称:ybd,代码行数:7,代码来源:wrangler.py

示例4: build_folders

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,代码行数:34,代码来源:backend.py

示例5: write_chunk_metafile

def write_chunk_metafile(defs, chunk):
    '''Writes a chunk .meta file to the baserock dir of the chunk

    The split rules are used to divide up the installed files for the chunk
    into artifacts in the 'products' list

    '''
    app.log(chunk['name'], 'splitting chunk')
    rules, splits = compile_rules(defs, chunk)

    install_dir = chunk['install']
    fs = OSFS(install_dir)
    files = fs.walkfiles('.', search='depth')
    dirs = fs.walkdirs('.', search='depth')

    for path in files:
        for artifact, rule in rules:
            if rule.match(path):
                splits[artifact].append(path)
                break

    all_files = [a for x in splits.values() for a in x]
    for path in dirs:
        if not any(map(lambda y: y.startswith(path),
                   all_files)) and path != '':
            for artifact, rule in rules:
                if rule.match(path) or rule.match(path + '/'):
                    splits[artifact].append(path)
                    break

    write_metafile(rules, splits, chunk)
开发者ID:gtristan,项目名称:ybd,代码行数:31,代码来源:splitting.py

示例6: Recent

class Recent(Files):
    def __init__(self):
        super(Recent, self).__init__()
        self._paths = []
        # http://python.6.n6.nabble.com/Access-Most-Recently-Used-MRU-entries-td1953541.html
        self.mru_path = shell.SHGetSpecialFolderPath(0, shellcon.CSIDL_RECENT, 0)
        self.mrufs = OSFS(self.mru_path)
        self.watcher = None

    def setup(self):
        self._update_path()
        self.watcher = self.mrufs.add_watcher(lambda e: self._update_path())

    def _update_path(self):
        self._paths = sorted(
            [os.path.join(self.mru_path, f) for f in self.mrufs.listdir()], key=os.path.getmtime, reverse=True
        )
        self.path_list_changed()

    def teardown(self):
        if self.watcher:
            self.mrufs.del_watcher(self.watcher)

    @property
    def paths(self):
        return self._paths

    @property
    def name(self):
        return "re"

    def lit(self, *args, **kargs):
        return super(Recent, self).lit(*args, **kargs)
开发者ID:Answeror,项目名称:lit,代码行数:33,代码来源:recent.py

示例7: build_folders

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,代码行数:32,代码来源:backend.py

示例8: deploy_register

def deploy_register():
    """Put the staging version to production hosted at 
    register.geostandaarden.nl
    """

    ## TODO: feed this function absolute paths

    print "Deploying production..."
    logging.info("Deploying production...")

    production = OSFS(production_path)

    # NOTE: only build paths within script_dir are currently supported
    call ('cp -r %s %s' % (ospath.join(build_path, register_path), ospath.join(production_path, register_path + '-new')), shell=True)

    if production.exists(register_path):
        backup_dir = time.strftime('%Y-%m-%d-%H-%M-%S')

        production.copydir(register_path, '%s/%s' % (backups_path, backup_dir), overwrite=True)
        
        try:
            production.movedir(register_path, register_path + '-old', overwrite=True)
        except ResourceNotFoundError:
            pass

    production.movedir(register_path + '-new', register_path, overwrite=True)

    try:
        production.removedir(register_path + '-old', force=True)
    except ResourceNotFoundError:
        pass

    call('chmod -R a+rx %s/%s' % (production_path, register_path), shell=True)

    logging.info("Production built successfully!")
开发者ID:Geonovum,项目名称:technisch-register,代码行数:35,代码来源:backend.py

示例9: export

    def export(self):
        """
        Perform the export given the parameters handed to this class at init.
        """
        with self.modulestore.bulk_operations(self.courselike_key):
            # depth = None: Traverses down the entire course structure.
            # lazy = False: Loads and caches all block definitions during traversal for fast access later
            #               -and- to eliminate many round-trips to read individual definitions.
            # Why these parameters? Because a course export needs to access all the course block information
            # eventually. Accessing it all now at the beginning increases performance of the export.
            fsm = OSFS(self.root_dir)
            courselike = self.get_courselike()
            export_fs = courselike.runtime.export_fs = fsm.makeopendir(self.target_dir)
            root_courselike_dir = self.root_dir + '/' + self.target_dir

            root = lxml.etree.Element('unknown')  # pylint: disable=no-member

            # export only the published content
            with self.modulestore.branch_setting(ModuleStoreEnum.Branch.published_only, self.courselike_key):
                # change all of the references inside the course to use the xml expected key type w/o version & branch
                xml_centric_courselike_key = self.get_key()
                adapt_references(courselike, xml_centric_courselike_key, export_fs)
                courselike.add_xml_to_node(root)

            # Make any needed adjustments to the root node.
            self.process_root(root, export_fs)

            # Process extra items-- drafts, assets, etc
            self.process_extra(root, courselike, root_courselike_dir, xml_centric_courselike_key, export_fs)

            # Any last pass adjustments
            self.post_process(root, export_fs)
开发者ID:gregrgay,项目名称:edx-platform,代码行数:32,代码来源:xml_exporter.py

示例10: check_export_roundtrip

    def check_export_roundtrip(self, data_dir, course_dir, mock_get):

        # Patch network calls to retrieve the textbook TOC
        mock_get.return_value.text = dedent("""
            <?xml version="1.0"?><table_of_contents>
            <entry page="5" page_label="ii" name="Table of Contents"/>
            </table_of_contents>
        """).strip()

        root_dir = path(self.temp_dir)
        print("Copying test course to temp dir {0}".format(root_dir))

        data_dir = path(data_dir)
        shutil.copytree(data_dir / course_dir, root_dir / course_dir)

        print("Starting import")
        initial_import = XMLModuleStore(root_dir, course_dirs=[course_dir])

        courses = initial_import.get_courses()
        self.assertEquals(len(courses), 1)
        initial_course = courses[0]

        # export to the same directory--that way things like the custom_tags/ folder
        # will still be there.
        print("Starting export")
        fs = OSFS(root_dir)
        export_fs = fs.makeopendir(course_dir)

        xml = initial_course.export_to_xml(export_fs)
        with export_fs.open('course.xml', 'w') as course_xml:
            course_xml.write(xml)

        print("Starting second import")
        second_import = XMLModuleStore(root_dir, course_dirs=[course_dir])

        courses2 = second_import.get_courses()
        self.assertEquals(len(courses2), 1)
        exported_course = courses2[0]

        print("Checking course equality")

        # HACK: filenames change when changing file formats
        # during imports from old-style courses.  Ignore them.
        strip_filenames(initial_course)
        strip_filenames(exported_course)

        self.assertEquals(initial_course, exported_course)
        self.assertEquals(initial_course.id, exported_course.id)
        course_id = initial_course.id

        print("Checking key equality")
        self.assertEquals(sorted(initial_import.modules[course_id].keys()),
                          sorted(second_import.modules[course_id].keys()))

        print("Checking module equality")
        for location in initial_import.modules[course_id].keys():
            print("Checking", location)
            self.assertEquals(initial_import.modules[course_id][location],
                              second_import.modules[course_id][location])
开发者ID:Bachmann1234,项目名称:edx-platform,代码行数:59,代码来源:test_export.py

示例11: main

def main():
    parser = argparse.ArgumentParser(description='Create free editor.slf')
    parser.add_argument('original', help="Original editor.slf")
    parser.add_argument(
        '-o',
        '--output',
        default='build/editor.slf',
        help="Where to store the created slf file"
    )
    args = parser.parse_args()

    if not os.path.exists(os.path.dirname(args.output)):
        os.makedirs(os.path.dirname(args.output))

    target_fs = BufferedSlfFS()
    replacement_fs = OSFS('editor')
    with open(args.original, 'rb') as source_file:
        source_fs = SlfFS(source_file)

        target_fs.library_name = source_fs.library_name
        target_fs.library_path = source_fs.library_path
        target_fs.version = source_fs.version
        target_fs.sort = source_fs.sort

        for directory in source_fs.walkdirs():
            if directory == '/':
                continue
            target_fs.makedir(directory)
        for file in source_fs.walkfiles():
            base_name, _ = os.path.splitext(file)
            with source_fs.open(file, 'rb') as source, target_fs.open(file, 'wb') as target:
                ja2_images = load_8bit_sti(source)
                replacement_path = base_name + '.gif'
                replacement_file_exists = replacement_fs.isfile(replacement_path)
                replacement_dir = file
                replacement_dir_exists = replacement_fs.isdir(replacement_dir)
                if len(ja2_images) == 1 and replacement_file_exists:
                    print("Replacing {0} with {1}".format(file, replacement_path))
                    replacement_img = Image.open(replacement_fs.open(replacement_path, 'rb'))
                    ja2_images._palette = replacement_img.palette
                    ja2_images.images[0]._image = replacement_img
                elif len(ja2_images) > 1 and replacement_dir_exists:
                    for i in range(len(ja2_images)):
                        replacement_path = replacement_dir + '/{}.gif'.format(i)

                        print("Replacing {0} with {1}".format(file, replacement_path))
                        replacement_img = Image.open(replacement_fs.open(replacement_path, 'rb'))
                        ja2_images._palette = replacement_img.palette
                        ja2_images.images[i]._image = replacement_img
                else:
                    print("Replacing {0} with nothingness".format(file))
                    for sub_image in ja2_images.images:
                        width, height = sub_image.image.size
                        sub_image._image = Image.new('P', (width, height), color=54)

                save_8bit_sti(ja2_images, target)

    with open(args.output, 'wb') as target_file:
        target_fs.save(target_file)
开发者ID:ja2-stracciatella,项目名称:free-ja2-resources,代码行数:59,代码来源:create_free_editorslf.py

示例12: run

    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,代码行数:58,代码来源:deploy.py

示例13: export_to_xml

def export_to_xml(modulestore, contentstore, course_location, root_dir, course_dir, draft_modulestore=None):

    course = modulestore.get_item(course_location)

    fs = OSFS(root_dir)
    export_fs = fs.makeopendir(course_dir)

    xml = course.export_to_xml(export_fs)
    with export_fs.open("course.xml", "w") as course_xml:
        course_xml.write(xml)

    # export the static assets
    contentstore.export_all_for_course(course_location, root_dir + "/" + course_dir + "/static/")

    # export the static tabs
    export_extra_content(export_fs, modulestore, course_location, "static_tab", "tabs", ".html")

    # export the custom tags
    export_extra_content(export_fs, modulestore, course_location, "custom_tag_template", "custom_tags")

    # export the course updates
    export_extra_content(export_fs, modulestore, course_location, "course_info", "info", ".html")

    # export the 'about' data (e.g. overview, etc.)
    export_extra_content(export_fs, modulestore, course_location, "about", "about", ".html")

    # export the grading policy
    policies_dir = export_fs.makeopendir("policies")
    course_run_policy_dir = policies_dir.makeopendir(course.location.name)
    with course_run_policy_dir.open("grading_policy.json", "w") as grading_policy:
        grading_policy.write(dumps(course.grading_policy))

    # export all of the course metadata in policy.json
    with course_run_policy_dir.open("policy.json", "w") as course_policy:
        policy = {"course/" + course.location.name: own_metadata(course)}
        course_policy.write(dumps(policy))

    # export draft content
    # NOTE: this code assumes that verticals are the top most draftable container
    # should we change the application, then this assumption will no longer
    # be valid
    if draft_modulestore is not None:
        draft_verticals = draft_modulestore.get_items(
            [None, course_location.org, course_location.course, "vertical", None, "draft"]
        )
        if len(draft_verticals) > 0:
            draft_course_dir = export_fs.makeopendir("drafts")
            for draft_vertical in draft_verticals:
                parent_locs = draft_modulestore.get_parent_locations(draft_vertical.location, course.location.course_id)
                # Don't try to export orphaned items.
                if len(parent_locs) > 0:
                    logging.debug("parent_locs = {0}".format(parent_locs))
                    draft_vertical.xml_attributes["parent_sequential_url"] = Location(parent_locs[0]).url()
                    sequential = modulestore.get_item(Location(parent_locs[0]))
                    index = sequential.children.index(draft_vertical.location.url())
                    draft_vertical.xml_attributes["index_in_children_list"] = str(index)
                    draft_vertical.export_to_xml(draft_course_dir)
开发者ID:bonavolontag,项目名称:edx-platform,代码行数:57,代码来源:xml_exporter.py

示例14: get_artifacts

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,代码行数:9,代码来源:utils.py

示例15: check_export_roundtrip

    def check_export_roundtrip(self, data_dir, course_dir):
        root_dir = path(self.temp_dir)
        print("Copying test course to temp dir {0}".format(root_dir))

        data_dir = path(data_dir)
        shutil.copytree(data_dir / course_dir, root_dir / course_dir)

        print("Starting import")
        initial_import = XMLModuleStore(root_dir, course_dirs=[course_dir])

        courses = initial_import.get_courses()
        self.assertEquals(len(courses), 1)
        initial_course = courses[0]

        # export to the same directory--that way things like the custom_tags/ folder
        # will still be there.
        print("Starting export")
        fs = OSFS(root_dir)
        export_fs = fs.makeopendir(course_dir)

        xml = initial_course.export_to_xml(export_fs)
        with export_fs.open('course.xml', 'w') as course_xml:
            course_xml.write(xml)

        print("Starting second import")
        second_import = XMLModuleStore(root_dir, course_dirs=[course_dir])

        courses2 = second_import.get_courses()
        self.assertEquals(len(courses2), 1)
        exported_course = courses2[0]

        print("Checking course equality")

        # HACK: filenames change when changing file formats
        # during imports from old-style courses.  Ignore them.
        strip_filenames(initial_course)
        strip_filenames(exported_course)

        self.assertEquals(initial_course, exported_course)
        self.assertEquals(initial_course.id, exported_course.id)
        course_id = initial_course.id

        print("Checking key equality")
        self.assertEquals(sorted(initial_import.modules[course_id].keys()),
                          sorted(second_import.modules[course_id].keys()))

        print("Checking module equality")
        for location in initial_import.modules[course_id].keys():
            print("Checking", location)
            if location.category == 'html':
                print(
                    "Skipping html modules--they can't import in"
                    " final form without writing files..."
                )
                continue
            self.assertEquals(initial_import.modules[course_id][location],
                              second_import.modules[course_id][location])
开发者ID:Mtax,项目名称:MHST2013-14,代码行数:57,代码来源:test_export.py


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