Beispiel #1
0
 def rehash(self):
     """Rename file path hash if it is old.
     """
     to_reload = False
     for i in listdir(config.cache_dir):
         try:
             dat_stat_file = os.path.join(config.cache_dir, i, 'dat.stat')
             if os.path.isfile(dat_stat_file):
                 f = open(dat_stat_file)
                 dat_stat = f.readlines()[0].strip()
                 f.close()
             else:
                 dat_stat = i
                 f = open(dat_stat_file, 'wb')
                 f.write(i + '\n')
                 f.close()
             hash = title.file_hash(dat_stat)
             if i == hash:
                 continue
             sys.stderr.write('rehash %s to %s\n' % (i, hash))
             shutil.move(os.path.join(config.cache_dir, i),
                         os.path.join(config.cache_dir, hash))
             to_reload = True
         except (IOError, OSError, IndexError), err:
             sys.stderr.write('rehash error %s for %s\n' % (err, i))
Beispiel #2
0
 def rehash(self):
     """Rename file path hash if it is old.
     """
     to_reload = False
     for i in listdir(config.cache_dir):
         try:
             dat_stat_file = os.path.join(config.cache_dir, i, 'dat.stat')
             if os.path.isfile(dat_stat_file):
                 f = open(dat_stat_file)
                 dat_stat = f.readlines()[0].strip()
                 f.close()
             else:
                 dat_stat = i
                 f = open(dat_stat_file, 'wb')
                 f.write(i + '\n')
                 f.close()
             hash = title.file_hash(dat_stat)
             if i == hash:
                 continue
             sys.stderr.write('rehash %s to %s\n' % (i, hash))
             shutil.move(os.path.join(config.cache_dir, i),
                         os.path.join(config.cache_dir, hash))
             to_reload = True
         except (IOError, OSError, IndexError), err:
             sys.stderr.write('rehash error %s for %s\n' % (err, i))
Beispiel #3
0
 def setpath(self):
     if (self.idstr == "") or (self.datfile == ""):
         return
     self.dathash = title.file_hash(self.datfile)
     self.path = os.path.join(config.cache_dir, self.dathash, 'record',
                              self.idstr)
     self.body_path = os.path.join(config.cache_dir, self.dathash, 'body',
                                   self.idstr)
     self.rm_path = os.path.join(config.cache_dir, self.dathash, 'removed',
                                 self.idstr)
Beispiel #4
0
 def setpath(self):
     if (self.idstr == "") or (self.datfile == ""):
         return
     self.dathash = title.file_hash(self.datfile)
     self.path = os.path.join(config.cache_dir,
                              self.dathash,
                              'record',
                              self.idstr)
     self.body_path = os.path.join(config.cache_dir,
                                   self.dathash,
                                   'body',
                                   self.idstr)
     self.rm_path = os.path.join(config.cache_dir,
                                 self.dathash,
                                 'removed',
                                 self.idstr)
Beispiel #5
0
    def __init__(self, datfile, sugtagtable=None, recentlist=None):
        dict.__init__(self)
        self.datfile = datfile
        self.dathash = title.file_hash(datfile)
        self.datpath += "/" + self.dathash
        self.removed = {}

        self.stamp = self._load_status('stamp')
        self.valid_stamp = self._load_status('validstamp')
        self.recent_stamp = self.stamp
        if recentlist is None:
            recentlist = RecentList()
        if self.datfile in recentlist.lookup:
            recent_stamp = recentlist.lookup[self.datfile].stamp
            if self.recent_stamp < recent_stamp:
                self.recent_stamp = recent_stamp
        self.size = self._load_status('size')
        self.count = self._load_status('count')
        self.node = RawNodeList(os.path.join(self.datpath, 'node.txt'))
        self.tags = TagList(self.datfile, os.path.join(self.datpath,
                                                       'tag.txt'))
        if sugtagtable is None:
            sugtagtable = SuggestedTagTable()
        if self.datfile in sugtagtable:
            self.sugtags = sugtagtable[self.datfile]
        else:
            self.sugtags = SuggestedTagList(sugtagtable, self.datfile)

        for type in config.types:
            if self.datfile.startswith(type):
                self.type = type
                break

        self.save_record = config.save_record.get(self.type, 0)
        self.save_size = config.save_size.get(self.type, 1)
        self.get_range = config.get_range.get(self.type, 0)
        self.sync_range = config.sync_range.get(self.type, 0)
        self.save_removed = config.save_removed.get(self.type, 0)

        if self.sync_range == 0:
            self.save_removed = 0
        elif self.save_removed == 0:
            pass
        elif self.save_removed <= self.sync_range:
            self.save_removed = self.sync_range + 1
Beispiel #6
0
    def __init__(self, datfile, sugtagtable=None, recentlist=None):
        dict.__init__(self)
        self.datfile = datfile
        self.dathash = title.file_hash(datfile)
        self.datpath += "/" + self.dathash
        self.removed = {}

        self.stamp = self._load_status('stamp')
        self.valid_stamp = self._load_status('validstamp')
        self.recent_stamp = self.stamp
        if recentlist is None:
            recentlist = RecentList()
        if self.datfile in recentlist.lookup:
            recent_stamp = recentlist.lookup[self.datfile].stamp
            if self.recent_stamp < recent_stamp:
                self.recent_stamp = recent_stamp
        self.size = self._load_status('size')
        self.count = self._load_status('count')
        self.node = RawNodeList(os.path.join(self.datpath, 'node.txt'))
        self.tags = TagList(self.datfile,
                            os.path.join(self.datpath, 'tag.txt'))
        if sugtagtable is None:
            sugtagtable = SuggestedTagTable()
        if self.datfile in sugtagtable:
            self.sugtags = sugtagtable[self.datfile]
        else:
            self.sugtags = SuggestedTagList(sugtagtable, self.datfile)

        for type in config.types:
            if self.datfile.startswith(type):
                self.type = type
                break

        self.save_record = config.save_record.get(self.type, 0)
        self.save_size = config.save_size.get(self.type, 1)
        self.get_range = config.get_range.get(self.type, 0)
        self.sync_range = config.sync_range.get(self.type, 0)
        self.save_removed = config.save_removed.get(self.type, 0)

        if self.sync_range == 0:
            self.save_removed = 0
        elif self.save_removed == 0:
            pass
        elif self.save_removed <= self.sync_range:
            self.save_removed = self.sync_range + 1