def pack(self, newarchive, filters=None): """ Recreate a new archive from the current one @param newarchive: the name of the new archive @type newarchive: string @param filters: tar filters to apply @type filters: array of strings @return: the new upstream source @rtype: UpstreamSource """ if not self.unpacked: raise GbpError("Need an unpacked source tree to pack") if not filters: filters = [] if not isinstance(filters, list): raise GbpError("Filters must be a list") try: unpacked = self.unpacked.rstrip('/') repackArchive = gbpc.PackTarArchive(newarchive, os.path.dirname(unpacked), os.path.basename(unpacked), filters) repackArchive() except gbpc.CommandExecFailed: # repackArchive already printed an error raise GbpError return type(self)(newarchive)
def pack(self, newarchive, filters=[], newprefix=None): """ Recreate a new archive from the current one @param newarchive: the name of the new archive @type newarchive: string @param filters: tar filters to apply @type filters: array of strings @param newprefix: new prefix, None implies that prefix is not mangled @type newprefix: string or None @return: the new upstream source @rtype: UpstreamSource """ if not self.unpacked: raise GbpError("Need an unpacked source tree to pack") if not filters: filters = [] if type(filters) != type([]): raise GbpError("Filters must be a list") run_dir = os.path.dirname(self.unpacked.rstrip('/')) pack_this = os.path.basename(self.unpacked.rstrip('/')) transform = None if newprefix is not None: newprefix = newprefix.strip('/.') if newprefix: transform = 's!%s!%s!' % (pack_this, newprefix) else: transform = 's!%s!%s!' % (pack_this, '.') try: repackArchive = gbpc.PackTarArchive(newarchive, run_dir, pack_this, filters, transform=transform) repackArchive() except gbpc.CommandExecFailed: # repackArchive already printed an error raise GbpError new = type(self)(newarchive) # Reuse the same unpacked dir if the content matches if not filters: new.unpacked = self.unpacked return new