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


Python Path.extension方法代码示例

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


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

示例1: sort

# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import extension [as 别名]
def sort(relative=''):
    """
    accept a path to a moment log and enable sorting on the items
    using jquery ui for a drag and drop interface
    """
    global path_root

    if re.match('~', relative):
        relative = os.path.expanduser(relative)
    if not re.match('/', relative):
        relative = path_root + relative

    #set some defaults here...
    #if they've been changed, this will get over written on load
    groups = { "all":[], "edit":[], "slide1":[], "slide2":[], "slide3":[], "slide4":[], "slide5":[], "slide6":[], "slide7":[], "slide8":[], "slide9":[], }

    tab_order = ['all', 'edit', "slide1", "slide2", "slide3", "slide4", "slide5", "slide6", "slide7", "slide8", "slide9"]

    path = Path(relative, relative_prefix=path_root)
    print(path)
    if path.exists() and path.type() == "Directory":
        response = "Error: need a file name to store the meta data in<br>"
        response = "You supplied a directory path: %s<br>" % path
        return response
    else:
        parent_directory = path.parent()
        if path.extension == ".txt":
            #create a text journal if we don't have one
            if not path.exists():
                #convert images to journal
                #print "PARENT: %s" % parent_directory
                directory = parent_directory.load()
                #print "directory: %s, of type: %s" % (directory, type(directory))
                directory.create_journal(journal=path.filename)
                #journal = path.load_journal(create=True)

            journal = path.load_journal()
            items = []
            for e in journal.entries():
                new_p = os.path.join(str(parent_directory), e.data.strip())
                #print new_p
                p = Path(new_p)
                #print p.exists()
                items.append(p)

            #initial version of groups:
            destination = Path(relative)
            destination.extension = '.json'

            groups['all'] = items
            
        elif path.extension == ".json":
            #we can make the initial version here...
            #skip the generation of a moments log step
            if not path.exists():
                directory = parent_directory.load()
                #print "directory: %s, of type: %s" % (directory, type(directory))
                directory.sort_by_date()
                directory.scan_filetypes()
                
                groups['all'] = directory.images
                
            else:
                loaded = load_groups(str(path))
                #template expects all items in groups to be Path objects.
                #do that now
                groups = {}
                for key, value in list(loaded.items()):
                    groups[key] = []
                    for v in value:
                        groups[key].append(Path(v))
            
            destination = Path(relative)

        else:
            #dunno!
            print("UNKNOWN FILE TYPE: %s" % relative)
            groups = {}
            destination = None

        #clean up tab_order as needed
        for key in list(groups.keys()):
            if not key in tab_order:
                tab_order.append(key)
        for item in tab_order[:]:
            if item not in list(groups.keys()):
                tab_order.remove(item)

        print(tab_order)
        
        #return template('sort', path=path, items=items)
        return template('sort', path=path, groups=groups, destination=destination, tab_order=tab_order)
开发者ID:charlesbrandt,项目名称:mindstream,代码行数:94,代码来源:application.py


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