1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import os
22 import sys
23 import shutil
24 import re
25
30 return repr(self.value)
31
32 -def repack(files, ar='ar', target='liball.a', verbose=False):
33 """For linux only. Repackage the list of files using ar as the
34 archiver program. The input files list can contain .a or .o
35 files. The output library name is supplied by the target keyword
36 argument. This will raise an exception arar_error in the event of
37 a problem, setting the exception value field with an explanation."""
38 import glob
39 pid= os.getpid()
40
41 tdir = 'tmp.arar.%d' % (pid)
42 if os.path.exists(tdir):
43 raise arar_error('Conflict with existing temporary directory: %s' % \
44 (tdir))
45 os.mkdir(tdir)
46
47 os.chdir(tdir)
48 doto = []
49 for arg in files:
50 if re.search(r'[.]o$', arg):
51 if arg[0] == '/':
52 doto.append(arg)
53 else:
54 doto.append(os.path.join('..',arg))
55 continue
56 if arg[0] == '/':
57 cmd = "%s x %s" % (ar,arg)
58 else:
59 cmd = "%s x ../%s" % (ar,arg)
60 if verbose:
61 print "EXTRACTING %s" % (cmd)
62 error= os.system(cmd)
63 if error:
64 raise arar_error('Extract failed for command %s' % (cmd))
65 files = glob.glob('*.o') + doto
66 local_target = os.path.basename(target)
67 cmd = "%s rcv %s %s" % (ar, local_target, " ".join(files))
68 if verbose:
69 print "RECOMBINING %s" % (cmd)
70 error=os.system(cmd)
71 if error:
72 raise arar_error('Recombine failed')
73
74 os.chdir('..')
75 os.rename(os.path.join(tdir,local_target), target)
76 if verbose:
77 print "CREATED %s" % (target)
78 shutil.rmtree(tdir)
79