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


Python Item.remove_path方法代码示例

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


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

示例1: __init__

# 需要导入模块: import Item [as 别名]
# 或者: from Item import remove_path [as 别名]
class Album:
    def __init__(
        self, directory_path, delimiter, copy, simulate, verbosity, regroup):
        self.set_options(delimiter, copy, simulate, verbosity, regroup)
        self.set_directory_path(directory_path)
        self.initialize_item_list()
    def set_options(self, delimiter, copy, simulate, verbosity, regroup):
        self.delimiter = delimiter
        self.copy = copy
        self.simulate = simulate
        self.verbosity = verbosity
        self.regroup = regroup
    def set_directory_path(self, directory_path):
        if not os.path.isdir(directory_path):
            print "Directory not found:", directory_path
            directory_path = None
        else:
            directory_path = os.path.join(directory_path, "")
        self.directory_path = directory_path
    def initialize_item_list(self):
        self.items = None
        if self.directory_path != None:
            for file_name in os.listdir(self.directory_path):
                path = self.directory_path + file_name
                if Itemizer.Itemizer.is_item(path):
                    number = Itemizer.Itemizer.extract_item_number(path)
                    self.add_items(path, number)
    def add_items(self, paths, index=None):
        if type(paths) == str:
            paths = [paths]
        current_index = self.build_index(index)
        for path in paths:
            if not os.path.isfile(path):
                print "File not found:", path
            else:
                if self.items == None:
                    self.add_first_item(path, current_index)
                else:
                    self.items = self.items.remove_path(path)
                    if self.items == None:
                        self.add_first_item(path, current_index)
                    else:
                        self.items = self.items.insert(path, current_index)
                if current_index:
                    current_index += 1
                if self.verbosity > 1:
                    print "Added file to list:", path
    def build_index(self, index):
        if type(index) == str:
            index = int(index)
        return index
    def add_first_item(self, path, index):
        if index == None:
            index = 1
        self.items = Item(path, index)
    def remove(self, paths):
        current = self.items
        while current != None:
            path = self.find_path_in_list(current.path, paths)
            if path:
                outgoing = current
                self.items = self.items.remove_path(outgoing.path)
                outgoing.erase_index()
                outgoing.save(
                    self.directory_path, None, self.delimiter, self.copy,
                    self.simulate, self.verbosity)
                paths.remove(path)
            current = current.next
    def find_path_in_list(self, key, paths):
        for path in paths:
            if os.path.samefile(key, path):
                return path
    def commit(self):
        if self.directory_path != None and self.items != None:
            if self.regroup:
                self.items.bunch()
            current = self.items
            prefix_length = self.determine_prefix_length()
            while current != None:
                current.save(
                    self.directory_path, prefix_length, self.delimiter,
                    self.copy, self.simulate, self.verbosity)
                current = current.next
    def print_items(self):
        current = self.items
        while current != None:
            print current
            current = current.next
    def determine_prefix_length(self):
        largest_index = self.items.get_largest_index()
        return len(str(largest_index))
开发者ID:ohsqueezy,项目名称:itemize,代码行数:93,代码来源:Album.py


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