def get_files(self): """returns {root: Container}""" # lazy initialisation if self.files != {}: return FileSharingMixin.get_files(self) # full init for repo in self.init_repos(): try: self.files[repo] = create_container(repo, checked=False) except AssertionError: print "non valid repo '%s'"% repo # if no valid repo found, does not try any further... if self.files == {}: return self.files for option in self.config.options(SECTION_FILE): # get share & tag try: o_description = self.config.get(SECTION_FILE, option) o_file, o_share, o_size, o_tag = o_description.split(',', 3) o_file = (o_file == 'F') and True or False o_share = (o_share == SHARED_TAG) o_tag = force_unicode(o_tag) o_size = int(o_size) except (ValueError, ConfigParser.NoSectionError, ConfigParser.NoOptionError), err: print >> sys.stderr, "option '%s' not well formated: %s"\ % (o_description, err) o_file, o_share, o_tag, o_size = False, False, DEFAULT_TAG, 0 # add container try: file_container = o_file and self.get_file(option) \ or self.get_container(option) file_container.share(o_share) file_container.tag(o_tag) file_container.size = o_size except KeyError: print "non valid file '%s'"% option
def add_repository(self, path, share=True, checked=True): """create a Container pointing to 'path' to directory raise ContainerException""" # check type & format if not isinstance(path, str): raise TypeError("repository '%s' expected as str"% path) if path.endswith(os.sep): path = path[:-1] # already added? if path in self.files: return # included or including existing path? for repo in self.files: if path.startswith(repo): raise ContainerException("'%s' part of existing repo %s"\ %(path, repo)) if repo.startswith(path): raise ContainerException("'%s' conflicts with existing repo %s"\ %(path, repo)) # else: continue self.files[path] = create_container(path, share=share, checked=checked)