def from_file(self, path): # Moving the file around file_name = '.'.join(split_name(os.path.basename(path))[:2]) destination = self.ensure_path(os.path.join(self.base_path, file_name)) shutil.copy(path, destination) self.index(destination) return destination
def from_data(self, path, data): # Build the name of the package based on its spec and extension file_name = '.'.join(split_name(os.path.basename(path))[:2]) destination = self.ensure_path(os.path.join(self.base_path, file_name)) with open(destination, 'wb') as fobj: fobj.write(data) self.index(destination) return destination
def match_format(format_, name): ext = split_name(name)[1] if format_.startswith('~'): return format_[1:] != ext return format_ == ext