diff options
author | Robert Buchholz <rbu@goodpoint.de> | 2008-03-24 22:57:29 +0100 |
---|---|---|
committer | Robert Buchholz <rbu@goodpoint.de> | 2008-03-24 23:06:17 +0100 |
commit | db29fd05848fdcd9846288fb4e3d17a938f6631f (patch) | |
tree | d8f9713c11bde6de9d36da71cd46892cde028b69 | |
parent | Remove url and ebuild from generated distfile, use .INDEX file ending. (diff) | |
download | distindex-db29fd05848fdcd9846288fb4e3d17a938f6631f.tar.gz distindex-db29fd05848fdcd9846288fb4e3d17a938f6631f.tar.bz2 distindex-db29fd05848fdcd9846288fb4e3d17a938f6631f.zip |
Redesign *Info class structure.
We now also index non-archive distfiles (with their metadata), and write the output to a file named $distfile.INDEX.mtime
-rwxr-xr-x | distfiles-indexer.py | 41 |
1 files changed, 17 insertions, 24 deletions
diff --git a/distfiles-indexer.py b/distfiles-indexer.py index 0895fe0..7922313 100755 --- a/distfiles-indexer.py +++ b/distfiles-indexer.py @@ -38,17 +38,21 @@ class ArchiveInfo: def write_info(self, outfiledir): - outfilename = "%s.INDEX" % (self.basename) + outfilename = "%s.INDEX.%s" % (self.basename, self.mtime) + self.out_fd = open(outfilename, "w") + self.write_header() + header_end = self.out_fd.tell() try: - self.out_fd = open(outfilename, "w") - self.write_header() - self.write_content() - self.out_fd.close() - return outfilename + self.write_tar_content() except: - if outfilename: - os.remove(outfilename) - raise + self.out_fd.seek(header_end) + try: + self.write_zip_content() + except: + self.out_fd.seek(header_end) + self.out_fd.truncate() + self.out_fd.close() + def write_header(self): self.out_fd.write("File-dist-name: %s\n" % (self.basename)) @@ -71,8 +75,7 @@ class ArchiveInfo: distfile.close() -class TarInfo(ArchiveInfo): - def write_content(self): + def write_tar_content(self): tar = tarfile.TarFile.open(self.filename, 'r') file_info = tar.next() @@ -95,8 +98,7 @@ class TarInfo(ArchiveInfo): file_info = tar.next() tar.close() -class ZipInfo(ArchiveInfo): - def write_content(self): + def write_zip_content(self): zip = zipfile.ZipFile(self.filename, 'r') filecount = 0 @@ -146,18 +148,9 @@ def main(): if not infilename: print "Please specify a filename." else: - tar_finished = False - try: - t = TarInfo(infilename) - filename = t.write_info(outdir) - tar_finished = True - except: - pass - if tar_finished: - sys.exit(0) try: - t = ZipInfo(infilename) - filename = t.write_info(outdir) + a = ArchiveInfo(infilename) + filename = a.write_info(outdir) except: print infilename, " could not be opened" |