當前位置: 首頁>>代碼示例>>Python>>正文


Python Path.type方法代碼示例

本文整理匯總了Python中moments.path.Path.type方法的典型用法代碼示例。如果您正苦於以下問題:Python Path.type方法的具體用法?Python Path.type怎麽用?Python Path.type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在moments.path.Path的用法示例。


在下文中一共展示了Path.type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: copy_up

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def copy_up(relative=''):
    """
    find the item at the supplied path
    and copy it up to the parent directory
    this is useful for images that should show up as the default image
    """
    global path_root

    if re.match('~', relative):
        relative = os.path.expanduser(relative)

    full_path = os.path.join(path_root, relative)
    path = Path(full_path, relative_prefix=path_root)

    if path.type() == "Image":
        cur_dir = path.parent()
        parent = cur_dir.parent()

        path.copy(parent)

        #this should be sufficient
        return "Success!"

    else:
        return "Failed"
開發者ID:charlesbrandt,項目名稱:sortable_list,代碼行數:27,代碼來源:application.py

示例2: path

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def path(relative=''):
    """
    serve a static file

    this also allows pose to function as a customizable file system browser

    be careful with what you set path_root to
    if the machine you run this on has sensitive information
    and is connected to a public network
    """
    global path_root

    if re.match('~', relative):
        relative = os.path.expanduser(relative)

    full_path = os.path.join(path_root, relative)
 
    path = Path(full_path, relative_prefix=path_root)
    if path.type() == "Directory":
        #we shouldn't be returning directory listing here
        pass    
    else:
        #this is equivalent to a view...
        #indicate it in the log:
        #path.log_action()
        return static_file(relative, root=path_root)
開發者ID:charlesbrandt,項目名稱:medley,代碼行數:28,代碼來源:application.py

示例3: find_photos

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def find_photos(cur_summary, cur_year, photo_roots, ignores=[]):
    #look for pictures
    #may require customization for each root
    #but starting with one known one for now
    for photo_root in photo_roots:
        #now look for content matching the day:
        year_path = os.path.join(photo_root, cur_year)
        options = os.listdir(year_path)
        for option in options:
            ignore = False
            for i in ignores:
                if re.search(i, option):
                    ignore = True

            if re.match(d_compact, option) and not ignore:
                #find all photos in dir:
                option_path = os.path.join(year_path, option)
                print("looking in: %s" % option_path)
                #very similar to content.Content.find_media()
                #but this is only checking one level down
                #I don't think we want to walk here:
                kind = "Image"
                image_options = os.listdir(option_path)
                for io in image_options:
                    media = os.path.join(option_path, io)
                    mpath = Path(media)
                    #if debug:
                    #    print "looking at: %s" % media
                    if mpath.type() == kind:
                        print("matched!", media)
                        if not media in cur_summary.photos:
                            cur_summary.photos.append(media)
開發者ID:charlesbrandt,項目名稱:mindstream,代碼行數:34,代碼來源:make_summary.py

示例4: path

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def path(relative=''):
    """
    serve a static file

    this also allows pose to function as a customizable file system browser

    be careful with what you set path_root to
    if the machine you run this on has sensitive information
    and is connected to a public network
    """
    global path_root

    if re.match('~', relative):
        relative = os.path.expanduser(relative)
    ## else:
    ##     relative = os.path.join('/', relative)
    ##     full = os.path.abspath(relative)
    ## print full

    full_path = os.path.join(path_root, relative)
 
    path = Path(full_path, relative_prefix=path_root)
    if path.type() == "Directory":
        node = path.load()
        #will depend what we want to sort by here:
        node.sort_by_path()
        #node.sort_by_date()
        return template('directory', path=path, contents=node.contents)
    else:
        #this is equivalent to a view...
        #indicate it in the log:
        #path.log_action()
        return static_file(relative, root=path_root)
開發者ID:charlesbrandt,項目名稱:mindstream,代碼行數:35,代碼來源:application.py

示例5: series

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def series(type="Image", relative=''):
    """
    show the current item in a series
    along with links to previous and next
    """
    global path_root

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

    path = Path(relative, relative_prefix=path_root)
    if path.type() != "Directory":
        parent = path.parent()
        parent_dir = parent.load()
        #parent_dir.sort_by_date()
        parent_dir.sort_by_path()
        parent_dir.scan_filetypes()
        if path.type() == "Image":
            count = 0
            position = None
            for i in parent_dir.images:
                if str(i) == str(path):
                    position = count
                    break
                count += 1

            if position is None:
                raise ValueError("Couldn't find matching image in directory: %s" % str(parent))
            else:
                if position != 0:
                    prev_pos = position-1
                else:
                    prev_pos = 0
                previous = parent_dir.images[prev_pos]

                nexts = []
                next_len = 5
                end = position + next_len
                if end >= len(parent_dir.images):
                    nexts = parent_dir.images[position+1:]
                else:
                    nexts = parent_dir.images[position+1:end]

                return template('series', path=path, parent=parent, previous=previous, nexts=nexts)
開發者ID:charlesbrandt,項目名稱:mindstream,代碼行數:48,代碼來源:application.py

示例6: find_json

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def find_json(item, limit_by_name=False, debug=False):
    """
    take any string
    see if it is a path for a json file
    or a path to a directory that contains a json file
    or look in the same directory as the item

    if more than one json file found, print a warning
    return the last json file

    if limit_by_name is true, and if item is a (non-json) file,
    use its filename to limit jsons to match that filename by default
    also [2016.04.10 14:21:49]
    switching this behavior
    now if limit_by_name is set to true,
    it will only return a result if the name matches
    otherwise the default behavior will be to try to match the name
    if there is more than one json in the directory
    otherwise it won't be strict
    
    """
    matches = find_jsons(item, limit_by_name, debug)

    if not matches:
        return None

    elif len(matches) == 1:
        logging.debug("find_json: found match: %s" % matches[0])
        return matches[0]

    else:
        #found more than one
        logging.debug("find_json: found many: %s" % matches)

        #even if limit by name was not specified as true,
        #in the case of multiple matches,
        #it may still make sense to try to match by name
        #if no match, then it's still possible to return the last one
        found = False
        name = ''
        p = Path(item)
        #maybe this should be checked for directories too???
        if p.type() != "Directory":
            name = to_tag(p.name)
            
        if name: 
            for match in matches:
                if re.search(name, str(match)):
                    found = match

        if found:
            logging.debug("find_json: matched name: %s" % found)
            return found
        else:
            print("WARNING: find_json: more than one match found: %s" % matches)
            logging.debug("find_json: returning last: %s" % matches[-1])
            return matches[-1]
開發者ID:charlesbrandt,項目名稱:medley,代碼行數:59,代碼來源:helpers.py

示例7: launch_path

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def launch_path(source=''):
    global path_root
    path = Path(path_root + source, relative_prefix=path_root)

    # just assume the whole thing has been sent
    # path = Path(source)

    response = ''
    if path.type() == "Log":
        edit(path)
        response += "editing: %s<br>" % path
    elif path.type() == "Directory":
        file_browse(path)
        response += "browsing: %s<br>" % path
    else:
        response += "unknown type: %s for: %s<br>" % (path.type(), path)

    response += "LAUNCH PATH: %s<br>" % source
    return response
開發者ID:charlesbrandt,項目名稱:sortable_list,代碼行數:21,代碼來源:application.py

示例8: rotate_image

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def rotate_image(source, degrees):
    if os.path.exists(source):
        p = Path(source)
        assert p.type() == "Image"
        i = p.load()
        print("Rotating %s by %s degrees" % (source, degrees))
        i.rotate(degrees)
        #i.auto_rotate()
        
    else:
        print("Couldn't find path: %s" % source)
        exit()
開發者ID:charlesbrandt,項目名稱:templates,代碼行數:14,代碼來源:rotate_image.py

示例9: find_jsons

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def find_jsons(item, limit_by_name=False, debug=False):
    """
    foundation for find_json
    but this returns all matches (based on parameters)
    """

    if re.search('.*\.json$', item):
        if debug:
            #print "find_and_load_json: item is a json string: %s" % item
            logging.debug("find_json: item is a json string: %s" % item)
        return [item]

    else:
        parent = ''
        name = ''
        p = Path(item)
        if p.type() == "Directory":
            #item must be a directory... just look here
            parent = p
            d = p.load()
        else:
            name = to_tag(p.name)
            #must be some other file type... load the parent directory:
            parent = p.parent()
            d = parent.load()
            if debug:
                print("%s not a directory, using: %s" % (item, parent))
            
        matches = []
        for j in d.files:
            #if debug:
            #    print "Checking: %s" % j
            if re.search('\.json$', str(j)):
                if debug:
                    print("matched json: %s" % j)

                match = os.path.join(str(parent), str(j))
                #this should allow us to hone in on one
                #if there is more than one media file in a directory
                if name and limit_by_name:
                    if re.search(name, str(j)):
                        matches.append(match)
                    else:
                        if debug:
                            print("could not find %s in %s" % (name, str(j)))
                else:
                    matches.append(match)

        if debug:
            print("Found the following: %s" % matches)

        return matches
開發者ID:charlesbrandt,項目名稱:medley,代碼行數:54,代碼來源:helpers.py

示例10: image

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def image(relative=''):
    global path_root

    # if not re.match('/', relative):
    #    relative = os.path.join(path_root, relative)

    # print()"SHOWING IMAGE: %s" % relative)
    path = Path(relative, relative_prefix=path_root)
    if path.type() == "Image":
        return bottle.static_file(relative, root=path_root)
    else:
        # TODO: raise 404
        pass
開發者ID:charlesbrandt,項目名稱:sortable_list,代碼行數:15,代碼來源:application.py

示例11: copy_media

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def copy_media(source, source_root, destination_root):
    m3u = M3U(source)

    total_size = 0
    total_items = 0
    for item in m3u:
        if re.match(source_root, item):
            p = Path(item)
            relative = p.to_relative(source_root)
            sparent = p.parent()
            destination = os.path.join(destination_root, relative)
            dpath = Path(destination)
            dparent = dpath.parent()
            print(relative)
            print(sparent)
            print(destination)

            if not os.path.exists(str(dparent)):
                os.makedirs(str(dparent))

            if not os.path.exists(destination):
                p.copy(destination)
            else:
                print("already have: %s" % destination)

            for option in os.listdir(str(sparent)):
                soption = os.path.join(str(sparent), option)
                spath = Path(soption)
                print(spath.type())
                if spath.type() != "Movie" and spath.type() != "Directory":
                    doption = os.path.join(str(dparent), option)
                    if not os.path.exists(doption):
                        print("copy here: %s, to %s" % (soption, doption))
                        shutil.copy(soption, doption)
                    
                

            print()
開發者ID:charlesbrandt,項目名稱:medley,代碼行數:40,代碼來源:copy_playlist_media.py

示例12: find_zips

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def find_zips(item):
    p = Path(item)
    if p.type() == "Directory":
        root = item
    else:
        parent = p.parent()
        root = str(parent)

    matches = []
    options = os.listdir(root)
    for o in options:
        if re.search('.*\.zip$', o):
            zipf = os.path.join(root, o)
            matches.append(zipf)
            
    return matches
開發者ID:charlesbrandt,項目名稱:medley,代碼行數:18,代碼來源:helpers.py

示例13: image

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def image(relative=''):
    """
    this is redundant with path
    """
    global path_root

    #if not re.match('/', relative):
    #    relative = os.path.join(path_root, relative)

    print("SHOWING IMAGE: %s" % relative)
    path = Path(relative, relative_prefix=path_root)
    if path.type() == "Image":
        return static_file(relative, root=path_root)
    else:
        #TODO: raise 404
        pass
開發者ID:charlesbrandt,項目名稱:mindstream,代碼行數:18,代碼來源:application.py

示例14: make_json_path

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def make_json_path(item):

    name = ''
    parent = ''

    p = Path(item)
    if p.type() == "Directory":
        #item must be a directory... just look here
        parent = p
        name = p.name
    else:
        name = p.name
        #must be some other file type... load the parent directory:
        parent = p.parent()

    #making jsons named as tags to help normalize difficult characters
    json_name = "%s.json" % to_tag(name)
    #print json_name
    return os.path.join(str(parent), json_name)
開發者ID:charlesbrandt,項目名稱:medley,代碼行數:21,代碼來源:helpers.py

示例15: find_media

# 需要導入模塊: from moments.path import Path [as 別名]
# 或者: from moments.path.Path import type [as 別名]
def find_media(item):
    """
    using this in content.import_content to check for time based media
    (videos or sounds)
    """
    p = Path(item)
    if p.type() == "Directory":
        root = p.load()
    else:
        parent = p.parent()
        root = parent.load()

    matches = []
    #now root is a directory...
    #use that to help find media
    root.scan_filetypes()
    matches.extend(root.sounds)
    matches.extend(root.movies)
    return matches
開發者ID:charlesbrandt,項目名稱:medley,代碼行數:21,代碼來源:helpers.py


注:本文中的moments.path.Path.type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。