當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。