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


Python Path.remove方法代码示例

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


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

示例1: test_load_journal

# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import remove [as 别名]
 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,代码行数:9,代码来源:test_path.py

示例2: test_files_to_journal

# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import remove [as 别名]
 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,代码行数:10,代码来源:test_path.py

示例3: test_create

# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import remove [as 别名]
 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,代码行数:10,代码来源:test_path.py

示例4: walk_logs

# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import remove [as 别名]
def walk_logs(source, destination='/c/journal/', add_tags=[], subtract_tags=[],
              include_all_path_tags=False, include_some_path_tags=True):
    """
    walk the given path and
    load a journal object for each log encountered in the path
    then split it up using split_logs function

    based on moments.journal.load_journal

    """

    #ignore_items = [ 'downloads', 'index.txt' ]
    ignore_items = [ ]
    log_check = re.compile('.*\.txt$')
    if os.path.isdir(source):
        for root,dirs,files in os.walk(source):
            for f in files:
                current_file = os.path.join(root, f)
                
                #make sure it is a log file (.txt):
                if not log_check.search(f):
                    continue

                if not check_ignore(current_file, ignore_items):
                    these_tags = add_tags[:]
                    filename_tags = []
                    if include_all_path_tags:
                        filename_tags = Path(current_file).to_tags()
                    elif include_some_path_tags:
                        #rather than include all tags from path
                        #check relative path only
                        #include those tags that are not a date tag
                        #otherwise ok to skip
                        full_path = Path(current_file)
                        relative_path = full_path.to_relative(source)
                        filename_tags = Path(os.path.join('/', relative_path)).to_tags()
                        filename_tags = omit_date_tags(filename_tags)
                        #typically this is not really the appropriate tag.
                        #used more as a generic file
                        #for history in a given context.  
                        if 'journal' in filename_tags:
                            filename_tags.remove('journal')

                    these_tags.extend(filename_tags)

                    #subtract tags last:
                    for tag in subtract_tags:
                        if tag in these_tags:
                            these_tags.remove(tag)

                    print("add_tags: %s" % these_tags)
                            
                    split_log(current_file, add_tags=these_tags, destination=destination)

    else:
        print("pass in a directory")
开发者ID:charlesbrandt,项目名称:mindstream,代码行数:58,代码来源:split_logs_to_days.py

示例5: test_make_thumbs

# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import remove [as 别名]
 def test_make_thumbs(self):
     path = Path('./zoobar/sized')
     path.remove()
     self.d.make_thumbs()
开发者ID:charlesbrandt,项目名称:moments,代码行数:6,代码来源:test_path.py

示例6: download_with_browser_helper

# 需要导入模块: from moments.path import Path [as 别名]
# 或者: from moments.path.Path import remove [as 别名]
def download_with_browser_helper(driver, link, browser_root='/Users/user/Downloads/', filename=None, ping_page=None, ping_interval=None):
    """
    specialized download routine to use the browser to save files
    then poll for the file to be complete before moving on

    driver is an instance of a selenium/webdriver instance running a browser 

    if the download stalls, move on after a threshold is met

    this does not handle moving the file
    only returns true or false depending on if the file needed to be skipped
    because it stalled out.

    browser_root is the default location that browser is configured
    to download to
    browser should be set to automatically download files
    of the type you are downloading in order to automate the process
    """
    skipped = False

    #*2011.12.30 13:28:09
    #sometimes it's not possible to know the filename
    #until after you start the download
    #(that is, it only shows up in the directory.)
    #
    #to work around that, 
    #get the current files in the directory before starting the download
    #then look after and see what the difference is
    pre_files = os.listdir(browser_root)

    #this kicks off the actual download:
    driver.get(link)

    #make sure there has been time for .part to be created
    time.sleep(30)

    post_files = os.listdir(browser_root)
    new_files = []
    for f in post_files:
        if f not in pre_files:
            new_files.append(f)
    print("found these new files: %s" % new_files)
    assert len(new_files) < 3 and len(new_files) > 0

    for f in new_files:
        if not re.search('\.part', f):
            filename = f

    download_dest = os.path.join(browser_root, filename)
    dpart = download_dest + '.part'

    #start = Timestamp()
    stall_start = None
    stalled = False
    size = 0
    new_size = -1

    ping_start = Timestamp()

    dpartp = Path(dpart)
    #there is a chance it finished downloading if the file was small
    if dpartp.exists():
        dpartf = dpartp.load()
        while dpartp.exists():
            #do this before the sleep to make sure it's still there
            new_size = dpartf.check_size()
            time.sleep(10)
            now = Timestamp()

            if ping_page and ping_interval:
                if now.datetime > ping_start.future(minutes=ping_interval).datetime:
                    print("time to ping! %s, %s" % (now, ping_page))
                    driver.get(ping_page)
                    ping_start = Timestamp()
            
            
            #if the size has changed, something is happening
            #not stalled
            if new_size != size:
                if stalled:
                    now = Timestamp()
                    print("download resumed: %s" % now)

                stalled = False
                size = new_size

            #could just be slow to download, but want to at least check
            else:
                #we've already set it before
                if stalled:
                    #check if stall_start was 25 minutes ago

                    if now.datetime > stall_start.future(minutes=25).datetime:
                        print("stall threshold met. deleting: %s" % dest)
                        dpartp.remove()
                        dpath.remove()
                        #if we get here, we know it didn't work
                        skipped = True

                        #log skips to make sure we go back:
#.........这里部分代码省略.........
开发者ID:charlesbrandt,项目名称:medley,代码行数:103,代码来源:scraper.py


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