• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python path.Path类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: path

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


示例2: test_load_journal

 def test_load_journal(self):
     dest = 'zoobar/todo.txt'
     p = Path(dest)
     p.load_journal(create=True)
     assert os.path.exists(dest)
     p.remove()
     assert not os.path.exists(dest)
开发者ID:charlesbrandt,项目名称:moments,代码行数:7,代码来源:test_path.py


示例3: find_photos

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


示例4: main

def main():
    if len(sys.argv) > 1:
        helps = ['--help', 'help', '-h']
        for i in helps:
            if i in sys.argv:
                usage()
                exit()

        f1 = sys.argv[1]
        if len(sys.argv) > 2:
            f2 = sys.argv[2]
        else:
            f1_path = Path(f1)
            f1_dir = f1_path.parent()
            
            f2 = os.path.join(str(f1_dir), "summary.txt")
            f2_path = Path(f2)
            if not f2_path.exists():
                print("Saving output to: %s" % f2)
            else:
                print("Warning: %s exists!" % f2)
                exit()

        create_summary(f1, f2)
    else:
        usage()
        exit()
开发者ID:charlesbrandt,项目名称:mindstream,代码行数:27,代码来源:time_report.py


示例5: path

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


示例6: add_new

def add_new(source_list, source_dir, destination=None):
    #ignores = ["classics", "misc", "other", "youtube-dl", "playlists"]
    ignores = ["playlists"]

    m3u = M3U(source_list)
    if os.path.isdir(source_dir):
        source_dir_path = Path(source_dir)
        subdirs = source_dir_path.load().directories
        #subdirs = os.listdir(source_dir)
        for subdir in subdirs:
            print("")
            if check_ignore(str(subdir), ignores):
                print("SKIP (IGNORES): %s" % subdir)
            else:
                print("SUBDIR: %s" % subdir)
                scan_dir(m3u, subdir)

        scan_dir(m3u, source_dir)


    else:
        print("NOT A DIRECTORY: %s" % source_dir)

    print("")
    print("")
    #for item in m3u:
    #    print item
    if destination is None:
        source_list_path = Path(source_list)
        dest_name = Timestamp().compact(accuracy="day") + "-videos.m3u"
        destination = os.path.join(str(source_list_path.parent()), dest_name)
        
    print("Saving to: %s" % destination)
    m3u.save(destination)
开发者ID:charlesbrandt,项目名称:medley,代码行数:34,代码来源:update_playlist.py


示例7: copy_up

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


示例8: test_create

 def test_create(self):
     p = "create_me.txt"
     path = Path(p)
     assert not os.path.exists(p)
     path.create()
     assert os.path.exists(p)
     path.remove()
     assert not os.path.exists(p)
开发者ID:charlesbrandt,项目名称:moments,代码行数:8,代码来源:test_path.py


示例9: test_files_to_journal

 def test_files_to_journal(self):
     output = "temp_files_to_journal_test_output.txt"
     self.d.files_to_journal(journal_file=output)
     dest = os.path.join('./zoobar', output)
     assert os.path.exists(dest)
     path = Path(dest)
     path.remove()
     assert not os.path.exists(dest)
开发者ID:charlesbrandt,项目名称:moments,代码行数:8,代码来源:test_path.py


示例10: find_json

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


示例11: process_files

def process_files(source_list, translate=None, action="copy", m3u_dest="temp.txt"):
    """
    copy *only* the files referenced in a source_list to a new loacation
    """
    result = ''
    
    #j = Journal()
    #j.from_file(journal)
    #j = load_journal(journal)
    #m = MediaList()
    #m.from_journal(j, local_path='/c')
    #sources = Sources()

    sl = Path(source_list)
    assert sl.exists()
    converter = Converter()

    if sl.extension == ".m3u":
        print("M3U!")
        sources = converter.from_m3u(source_list)
    elif sl.extension == ".txt":
        sources = converter.from_journal(source_list)
    else:
        print("UNKNOWN EXTENSION: %s" % sl.extension)

    
    new_sources = Sources()
    counter = 0
    for i in sources:
        #print i
        #if re.search('\.mp3', i.path):
        if os.path.exists(str(i.path)):
            destination = make_destination(i.path, translate)
            #print "SOURCE: %s" % i
            print("DEST: %s" % destination)

            if action == "copy":
                print("Copy %03d: %s" % (counter, i.path))
                copy_file(i.path, destination)
            if action == "m3u":
                new_sources.append(Source(destination))
        else:
            print("COULD NOT FIND FILE: %s" % i.path)
        counter += 1

    if action == "m3u":
        #print len(new_sources)
        m3u = converter.to_m3u(new_sources, verify=False)
        #print m3u
        print("SAVING M3U TO: %s" % m3u_dest)
        f = open(m3u_dest, 'w')
        f.write(m3u)
        f.close()
开发者ID:charlesbrandt,项目名称:medley,代码行数:53,代码来源:copy_media.py


示例12: rotate_image

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


示例13: diff_files

def diff_files(fname, path1, path2, indent, diff_system=False):

    #until we prove otherwise, we'll assume they're different
    is_difference = True
    p1 = Path(path1)
    n1 = p1.load()
    #n1 = make_node(path1)

    p2 = Path(path2)
    n2 = p2.load()
    #n2 = make_node(path2)

    if n1.size == n2.size:
        #probably pretty safe to assume that they are equal
        #print " %s - BOTH, SAME SIZE" % phraseUnicode2ASCII(fname)
        #print "EQUAL sizes: %s %s" % (n1.size, n2.size)
        is_difference = False

        #could do additional checks if desired
        #enabling another diff level will take longer, but will be more accurate:
        f_a = file(path1)
        f_b = file(path2)
        a = f_a.readlines()
        b = f_b.readlines()
        diff = unified_diff(a, b)
        for d in diff:
            is_difference = True
            #print d

        #this will signal which files have differences:
        if is_difference:
            print(" %s - BOTH, DIFFERENT CONTENT" % fname.translate(unaccented_map()))
            
        #could move it somewhere else:
        #os.rename(path1, os.path.join(d1, "dupes", fname))
        #os.rename(path2, os.path.join(d2, "merged", fname))

    else:
        #print " %s - BOTH, DIFFERENT SIZE" % phraseUnicode2ASCII(fname)
        print(" %s - BOTH, DIFFERENT SIZE" % fname.translate(unaccented_map()))
        if diff_system:
            print("diffing: %s %s\n" % (path1, path2))
            try:
                #diff_system( phraseUnicode2ASCII(path1),
                #             phraseUnicode2ASCII(path2) )
                #diff_playlists(n1, n2)
                diff_system( path1.translate(unaccented_map()),
                             path2.translate(unaccented_map()) )
            except:
                print("Unable to diff.")

    return is_difference
开发者ID:charlesbrandt,项目名称:templates,代码行数:52,代码来源:diff_json_and_merge.py


示例14: find_jsons

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


示例15: image

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


示例16: extract_zips

def extract_zips(source, make_subdir=True):
    """
    take a source
    make sure it has not been extracted already
    unzip the file
    """

    path = Path(source)
    source = path.load()
    #print source.directories
    for d in source.directories:
        #print d.path
        dpath = d.load()
        for f in dpath.files:
            #must have a zip file
            if re.search('.zip', f.path) and f.extension == '.zip':
                if make_subdir:
                    # this uses the zip's filename for the directory
                    #destination = os.path.join(str(f.parent()), str(f.name))
                    # sometimes the zip is not descriptive...
                    # better to use the parent directory name
                    destination = os.path.join(str(f.parent()), str(f.parent().name))
                    dest_path = Path(destination)
                else:
                    #otherwise, just put them in the main directory
                    #dest_path = Path(destination)
                    destination = str(f.parent())
                    dest_path = f.parent()

                #TODO:
                #create a file to indicate the extract already happen
                #to skip on future runs
                #if not alredy_extracted.exists():
                #if not dest_path.exists():
                #else:
                #    print "already extracted: %s" % f.path

                #print "extracting: %s" % f.path
                #this extracts to the dpath directory, not a new
                #subdirectory with the same name (like we are checking for)
                #good enough for this round, but may want to improve on that
                #command = "unzip %s -d %s" % (f.path, d.path)
                #command = "unzip %s -d %s" % (f.path, destination)
                #adding -fo option -f: freshen -o: overwrite without prompting
                command = "unzip -o %s -d %s" % (f.path, destination)
                print("not found, unzipping: %s" % command)
                process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE)
                output = process.communicate()[0]
                if output:
                    print(output)
开发者ID:charlesbrandt,项目名称:templates,代码行数:51,代码来源:extract_zips.py


示例17: size_of_list

def size_of_list(source, media_root=None, ignores=['/c/',]):
    """
    ignores are used to distinguish actual media from markers
    """
    items = []
    if re.search('.m3u', source):
        items = M3U(source)

    elif re.search('.json', source):
        loaded = load_json(source)

        #see if we have a dictionary or a list:
        if isinstance(loaded, list):
            #already have a list
            #clean it up
            for item in loaded:
                #these are usually content .json files:
                content = Content(item[0])
                #print content.media
                items.append(content.media[-1][0])
        elif isinstance(loaded, dict):
            #walk the tree to load each item individually
            #could call size_of_list() recursively
            pass

    total_size = 0
    total_items = 0
    #seconds?
    total_length = 0
    for item in items:
        check_item = False
        if media_root and re.match(media_root, item):
            check_item = True
        #elif not re.match(ignore, item):
        elif not check_ignore(item, ignores):
            check_item = True

        if check_item:
            p = Path(item)
            f = p.load()

            total_size += f.check_size()
            results = get_media_properties(item)
            print(results)
            total_length += results[1]
            total_items += 1
            #print item

    print("found %s matching items" % total_items)
    return total_size, total_length, total_items
开发者ID:charlesbrandt,项目名称:medley,代码行数:50,代码来源:size_of_playlist_items.py


示例18: collection_zip

def collection_zip(collection_name=None, content_name=None):
    """

    """
    result = ''
    content = None
    if collection_name:
        summary = get_summary(collection_name)
        content = summary.load_content(content_name)
        if content:

            sources = []
            content.zips = find_zips(content.path)
            import zipfile
            for zipf in content.zips:
                zipp = Path(zipf)
                #print zipp.name
                zip_root = os.path.join(content.path, zipp.name)
                if not os.path.exists(zip_root):
                    os.makedirs(zip_root)
                zfile = zipfile.ZipFile(zipf)
                for name in zfile.namelist():
                    (dirname, filename) = os.path.split(name)
                    #print "Decompressing " + filename + " on " + dirname
                    dest_dir = os.path.join(zip_root, dirname)
                    if not dest_dir in sources:
                        sources.append(dest_dir)
                    print("Decompressing " + filename + " to " + dest_dir + "<br>")
                    if not os.path.exists(dest_dir):
                         os.makedirs(dest_dir)
                    dest = os.path.join(dest_dir, name)
                    if not os.path.exists(dest):
                        fd = open(dest, "w")
                        fd.write(zfile.read(name))
                        fd.close()
                        dpath = Path(dest)
                        print("making thumb")
                        img = dpath.load()
                        img.make_thumbs(['small'], save_original=False)


            zips = []
            for source in sources:
                spath = Path(source, relative_prefix=path_root)
                sdir = spath.load()
                zips.append(sdir.contents)
                print(source)

    #return template('simple', body=result, title="unzip!")
    return template('zip', zips=zips)
开发者ID:charlesbrandt,项目名称:medley,代码行数:50,代码来源:application.py


示例19: group_by_day

def group_by_day(path, dest_prefix=None, tags=[]):
    """
    look at a directory, and group all files by the day they were created

    run through a supplied directory's files
    create sub-directories that correspond to the day of the files' timestamps
    move the files to their corresponding day subdirectory
    in the new_dir destination

    """
    if dest_prefix is None:
        dest_prefix = path
    p = Path(path)
    d = p.load()
    #d = make_node(path)
    d.sort_by_date()

    dates = []
    destinations = []

    last_date = None
    cur_batch = []
    print("%s Files found in %s" % (len(d.files), path))
    for fpath in d.files:
        #print f.name
        f = fpath.load()
        if f.date() != last_date:
            #check if we need to move the previous day's files:
            print("New day: %s (previously: %s)" % (f.date(), last_date))
            if cur_batch:
                dest = process_batch(cur_batch, last_date, dest_prefix, tags)
                destinations.append(dest)

            cur_batch = [ f ]
            last_date = f.date()
        else:
            cur_batch.append(f)

    #get the last one:
    if cur_batch:
        dest = process_batch(cur_batch, last_date, dest_prefix, tags)
        if not dest in destinations:
            destinations.append( dest )

    #if we need to do something else to the new directories
    #we have them all collected in destinations list

    return destinations
开发者ID:charlesbrandt,项目名称:mindstream,代码行数:48,代码来源:import_media.py


示例20: image

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mommy.save_one函数代码示例发布时间:2022-05-27
下一篇:
Python moment.date函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap