summaryrefslogtreecommitdiffstats
path: root/pym/xpak.py
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2006-02-19 20:19:41 +0000
committerZac Medico <zmedico@gentoo.org>2006-02-19 20:19:41 +0000
commitaa21babd731a9c437c1bcb008e7372d56b5bc059 (patch)
tree21426dddc9eb9e6f9ed1cb701a0d983974243a9b /pym/xpak.py
parentdf20c94a12d5d4e040d9e8f59edcd0cae44df1af (diff)
downloadportage-aa21babd731a9c437c1bcb008e7372d56b5bc059.tar.gz
portage-aa21babd731a9c437c1bcb008e7372d56b5bc059.tar.bz2
portage-aa21babd731a9c437c1bcb008e7372d56b5bc059.zip
In order do avoid the need for temporary files, add a new xpak_mem() function that creates an xpak_segment from a map object.
svn path=/main/trunk/; revision=2747
Diffstat (limited to 'pym/xpak.py')
-rw-r--r--pym/xpak.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/pym/xpak.py b/pym/xpak.py
index 5cb2d61ab..56c2f4b07 100644
--- a/pym/xpak.py
+++ b/pym/xpak.py
@@ -66,34 +66,39 @@ def xpak(rootdir,outfile=None):
addtolist(mylist,"")
mylist.sort()
+ mydata = {}
+ for x in mylist:
+ a = open(x, "r")
+ mydata[x] = a.read()
+ a.close()
+ os.chdir(origdir)
- #Our list index has been created
-
+ xpak_segment = xpak_mem(mydata)
+ if outfile:
+ outf = open(outfile, "w")
+ outf.write(xpak_segment)
+ outf.close()
+ else:
+ return xpak_segment
+
+def xpak_mem(mydata):
+ """Create an xpack segement from a map object."""
indexglob=""
indexpos=0
dataglob=""
datapos=0
- for x in mylist:
- a=open(x,"r")
- newglob=a.read()
- a.close()
+ for x, newglob in mydata.iteritems():
mydatasize=len(newglob)
indexglob=indexglob+encodeint(len(x))+x+encodeint(datapos)+encodeint(mydatasize)
indexpos=indexpos+4+len(x)+4+4
dataglob=dataglob+newglob
datapos=datapos+mydatasize
- os.chdir(origdir)
- if outfile:
- outf=open(outfile,"w")
- outf.write("XPAKPACK"+encodeint(len(indexglob))+encodeint(len(dataglob)))
- outf.write(indexglob)
- outf.write(dataglob)
- outf.write("XPAKSTOP")
- outf.close()
- else:
- myret="XPAKPACK"+encodeint(len(indexglob))+encodeint(len(dataglob))
- myret=myret+indexglob+dataglob+"XPAKSTOP"
- return myret
+ return "XPAKPACK" \
+ + encodeint(len(indexglob)) \
+ + encodeint(len(dataglob)) \
+ + indexglob \
+ + dataglob \
+ + "XPAKSTOP"
def xsplit(infile):
"""(infile) -- Splits the infile into two files.