def parse_xml(self, file): tree = None if not os.path.isfile(file): raise PyvenException('Package file not available : ' + self.format_name('_') + '.xml') try: tree = etree.parse(file) except Exception as e: pyven_exception = PyvenException('') pyven_exception.args = e.args raise pyven_exception return tree
def pack(self, repo): Logger.get().info('Package ' + self.format_name() + ' --> Creating archive ' + self.basename()) if not os.path.isdir(self.location(repo.url)): os.makedirs(self.location(repo.url)) if os.path.isfile(os.path.join(self.location(repo.url), self.basename())): os.remove(os.path.join(self.location(repo.url), self.basename())) ok = True errors = [] for item in self.items: if not os.path.isfile(os.path.join(item.location(repo.url), item.basename())): errors.append('Package item not found --> ' + os.path.join(item.location(repo.url), item.basename())) ok = False for d in self.directories: if not os.path.isdir(os.path.join(self.cwd, d)): errors.append('Directory not found --> ' + os.path.join(self.cwd, d)) ok = False if ok: zf = zipfile.ZipFile(os.path.join(self.location(repo.url), self.basename()), mode='w') try: for d in self.directories: Logger.get().info('Package ' + self.format_name() + ' --> Adding directory ' + d) root = os.path.basename(os.path.normpath(os.path.join(self.cwd, d))) for current_dir, dirs, files in os.walk(os.path.join(self.cwd, d)): for f in [os.path.join(current_dir, f) for f in files]: zf.write(os.path.join(self.cwd, f), f[f.find(root):]) Logger.get().info('Package ' + self.format_name() + ' --> Added file : ' + f) Logger.get().info('Package ' + self.format_name() + ' --> Added directory ' + d) for pattern in self.patterns: for file in glob.glob(os.path.join(self.cwd, pattern)): zf.write(file, os.path.basename(file)) Logger.get().info('Package ' + self.format_name() + ' --> Added file from pattern : ' + os.path.basename(file)) finally: zf.close() Logger.get().info('Package ' + self.format_name() + ' --> Created archive ' + self.basename()) utils.str_to_file(self.to_xml(), os.path.join(self.location(repo.url), self.format_name('_') + '.xml')) else: e = PyvenException('') e.args = tuple(errors) raise e return ok