Changeset 5

Show
Ignore:
Timestamp:
Sat Sep 3 12:10:09 2005
Author:
giovannibajo
Message:

Trim exceeding whitespaces

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/bindepend.py

    r2 r5  
    23 23 iswin = sys.platform[:3] == 'win'  
    24 24 cygwin = sys.platform == 'cygwin'  
    25   excludes = {'KERNEL32.DLL':1,  
    26         'ADVAPI.DLL':1,  
      25 excludes = {'KERNEL32.DLL':1,  
      26       'ADVAPI.DLL':1,  
    27 27       'MSVCRT.DLL':1,  
    28 28       'ADVAPI32.DLL':1,  
     
    54 54       'GLUB32.DLL':1,  
    55 55       '/usr/lib':1,  
    56         '/lib':1,}       
      56       '/lib':1,}  
    56 56  
    57 57 def getfullnameof(mod, xtrapath = None):  
    58 58   """Return the full path name of MOD.  
    59      
      59  
    59 59       MOD is the basename of a dll or pyd.  
    60 60       XTRAPATH is a path or list of paths to search first.  
     
    74 74       return npth  
    75 75   return ''  
    76      
      76  
    76 76 def getImports1(pth):  
    77 77     """Find the binary dependencies of PTH.  
    78        
      78  
    78 78         This implementation (not used right now) uses the MSVC utility dumpbin"""  
    79 79     import tempfile  
     
    93 93         i = i + 1  
    94 94     return rslt  
    95        
      95  
    95 95 def getImports2x(pth):  
    96 96     """Find the binary dependencies of PTH.  
    97        
      97  
    97 97         This implementation walks through the PE header"""  
    98 98     import struct  
     
    118 118       numdirs = struct.unpack('l', f[pehdrd+numdictoffset:pehdrd+numdictoffset+4])[0]  
    119 119       idata = ''  
    120         if magic == 17744:   
      120       if magic == 17744:  
    120 120           importsec, sz = struct.unpack('2l', f[pehdrd+importoffset:pehdrd+importoffset+8])  
    121 121           if sz == 0:  
     
    161 161 def getImports2(path):  
    162 162     """Find the binary dependencies of PTH.  
    163        
      163  
    163 163         This implementation walks through the PE header"""  
    164 164     import struct  
     
    175 175     coffhdr = struct.unpack(coffhdrfmt, rawcoffhdr)  
    176 176     coffhdr_numsections = coffhdr[1]  
    177        
      177  
    177 177     opthdrfmt = 'hbblllllllllhhhhhhllllhhllllll'  
    178 178     rawopthdr = f.read(struct.calcsize(opthdrfmt))  
     
    193 193         rawsection = f.read(sectionsize)  
    194 194         sections.append(struct.unpack(sectionfmt, rawsection))  
    195            
      195  
    195 195     importva, importsz = datadirs[1]  
    196 196     if importsz == 0:  
     
    226 226         data = data[iidescrsz:]  
    227 227     return dlls  
    228        
      228  
    228 228 def Dependencies(lTOC):  
    229 229   """Expand LTOC to include all the closure of binary dependencies.  
    230      
      230  
    230 230      LTOC is a logical table of contents, ie, a seq of tuples (name, path).  
    231 231      Return LTOC expanded by all the binary dependencies of the entries  
     
    258 258             print "E: lib not found:", lib, "dependency of", pth  
    259 259   return lTOC  
    260        
      260  
    260 260 def getImports3(pth):  
    261 261     """Find the binary dependencies of PTH.  
    262        
      262  
    262 262         This implementation is for ldd platforms"""  
    263 263     import tempfile  
     
    281 281         i = i + 1  
    282 282     return rslt  
    283        
      283  
    283 283 def getImports(pth):  
    284 284     """Forwards to either getImports2 or getImports3  
     
    288 288         return getImports2(pth)  
    289 289     return getImports3(pth)  
    290      
      290  
    290 290 def getWindowsPath():  
    291 291     """Return the path that Windows will search for dlls."""  
  • trunk/Makespec.py

    r2 r5  
    92 92         if filename.startswith(from_path):  
    93 93             rest = filename[len(from_path):]  
    94               if rest[0] in "\\/":   
      94             if rest[0] in "\\/":  
    94 94                 rest = rest[1:]  
    95 95             return to_name, rest  
    96 96     return None, filename  
    97            
      97  
    97 97 # An object used in place of a "path string" which knows how to repr()  
    98 98 # itself using variable names instead of hard-coded paths.  
     
    109 109             return repr(self.path)  
    110 110         return "os.path.join(" + self.variable_prefix + "," + repr(self.filename_suffix) + ")"  
    111            
      111  
    111 111 def main(scripts, name=None, tk=0, freeze=0, console=1, debug=0, strip=0, upx=0,  
    112 112          comserver=0, ascii=0, workdir=None, pathex=None, version_file=None, icon_file=None):  
  • trunk/icon.py

    r2 r5  
    86 86             data = data + e.tostring()  
    87 87         return data  
    88                
      88  
    88 88  
    89 89 def CopyIcons_FromIco (dstpath, srcpath):  
  • trunk/Build.py

    r2 r5  
    17 17     print "You must run Configure.py before building!"  
    18 18     sys.exit(1)  
    19        
      19  
    19 19 if config['hasRsrcUpdate']:  
    20 20     import icon, versionInfo  
    21        
      21  
    21 21 def build(spec):  
    22 22     global SPECPATH, BUILDPATH, WARNFILE, rthooks  
     
    45 45     except:  
    46 46         return 0  
    47        
      47  
    47 47 class Target:  
    48 48     invcnum = 0  
     
    57 57         if self.check_guts(mtime(self.out)):  
    58 58             self.assemble()  
    59                
      59  
    59 59 class Analysis(Target):  
    60 60     def __init__(self, scripts=None, pathex=None, hookspath=None, excludes=None):  
     
    275 275             fnm = checkCache(fnm, 1, 0)  
    276 276         cmd = "upx --best -q %s" % cachedfile  
    277       else:     
      277     else:  
    277 277         cmd = "strip %s" % cachedfile  
    278 278     shutil.copy2(fnm, cachedfile)  
     
    364 364                     self.dependencies.append((inm, fnm, typ))  
    365 365                 else:  
    366                       fnm = checkCache(fnm, self.strip_binaries,  
    367                                        self.upx_binaries and ( iswin or cygwin )  
      366                     fnm = checkCache(fnm, self.strip_binaries,  
      367                                      self.upx_binaries and ( iswin or cygwin )  
    368 368                                       and config['hasUPX'])  
    369                       mytoc.append((inm, fnm, self.cdict.get(typ,0),   
      369                     mytoc.append((inm, fnm, self.cdict.get(typ,0),  
    369 369                                   self.xformdict.get(typ,'b')))  
    370 370             elif typ == 'OPTION':  
     
    454 454             print "rebuilding %s because pkg is more recent" % outnm  
    455 455             return 1  
    456           return 0     
      456         return 0  
    456 456     def assemble(self):  
    457 457         print "building ELFEXE", os.path.basename(self.out)  
     
    464 464         if self.debug:  
    465 465             exe = exe + '_d'  
    466           exe = os.path.join(HOMEPATH, exe)       
      466         exe = os.path.join(HOMEPATH, exe)  
    466 466         if iswin or cygwin:  
    467 467             exe = exe + '.exe'  
     
    488 488         os.chmod(self.name, 0755)  
    489 489         f = open(self.out, 'w')  
    490           pprint.pprint((self.name, self.console, self.debug, self.icon, self.versrsrc,   
      490         pprint.pprint((self.name, self.console, self.debug, self.icon, self.versrsrc,  
    490 490                        self.strip, self.upx, mtime(self.name)), f)  
    491 491         f.close()  
     
    502 502             outf.write(data)  
    503 503  
    504   class DLL(ELFEXE):   
      504 class DLL(ELFEXE):  
    504 504     def assemble(self):  
    505 505         print "building DLL", os.path.basename(self.out)  
     
    515 515         os.chmod(self.name, 0755)  
    516 516         f = open(self.out, 'w')  
    517           pprint.pprint((self.name, self.console, self.debug, self.icon, self.versrsrc,   
      517         pprint.pprint((self.name, self.console, self.debug, self.icon, self.versrsrc,  
    517 517                        self.strip, self.upx, mtime(self.name)), f)  
    518 518         f.close()  
    519 519         return 1  
    520 520  
    521   class NonELFEXE(ELFEXE):   
      521 class NonELFEXE(ELFEXE):  
    521 521     def assemble(self):  
    522 522         print "building NonELFEXE", os.path.basename(self.out)  
     
    535 535         shutil.copy2(self.pkg.name, self.name+'.pkg')  
    536 536         f = open(self.out, 'w')  
    537           pprint.pprint((self.name, self.console, self.debug, self.icon, self.versrsrc,   
      537         pprint.pprint((self.name, self.console, self.debug, self.icon, self.versrsrc,  
    537 537                        self.strip, self.upx, mtime(self.name)), f)  
    538 538         f.close()  
     
    618 618                 os.makedirs(todir)  
    619 619             if typ in ('EXTENSION', 'BINARY'):  
    620                   fnm = checkCache(fnm, self.strip_binaries,  
    621                                    self.upx_binaries and ( iswin or cygwin )  
      620                 fnm = checkCache(fnm, self.strip_binaries,  
      621                                  self.upx_binaries and ( iswin or cygwin )  
    622 622                                   and config['hasUPX'])  
    623 623             shutil.copy2(fnm, tofnm)  
     
    779 779     else:  
    780 780         build(sys.argv[1])  
    781        
    782 781  
    783 782  
    784                
      783  
      784  
  • trunk/mf.py

    r2 r5  
    81 81             mod = PyModule(nm, pth, co)  
    82 82         return mod  
    83        
      83  
    83 83 class PYZOwner(Owner):  
    84 84     def __init__(self, path):  
     
    362 362         self.modules['__main__'] = mod  
    363 363         return self.analyze_r('__main__')  
    364        
      364  
    364 364  
    365 365     def ispackage(self, nm):  
     
    407 407                     for attr, val in hook.attrs:  
    408 408                         setattr(mod, attr, val)  
    409                    
      409  
    409 409                 if fqname != mod.__name__:  
    410 410                     print "W: %s is changing it's name to %s" % (fqname, mod.__name__)  
     
    501 501             mod.__name__ = self.__name__ + '.' + mod.__name__  
    502 502         return mod  
    503        
      503  
    503 503 class PkgInPYZModule(PyModule):  
    504 504     def __init__(self, nm, co, pyzowner):  
     
    569 569             instrs.append((op, oparg, incondition, curline))  
    570 570     return instrs  
    571        
      571  
    571 571 def scan_code(co, m=None, w=None, nested=0):  
    572 572     instrs = pass1(co.co_code)  
  • trunk/MakeComServer.py

    r2 r5  
    33 33             DllUnregisterServer()  
    34 34             break  
    35            
      35  
    35 35         # MS seems to like /automate to run the class factories.  
    36 36         if string.find(arg, "/automate") > -1:  
  • trunk/ArchiveViewer.py

    r2 r5  
    133 133               % (self.path, self.__class__.__name__)  
    134 134         if self.lib.read(len(self.pymagic)) != self.pymagic:  
    135               print "Warning: pyz is from a different Python version"   
      135             print "Warning: pyz is from a different Python version"  
    135 135         self.lib.read(4)  
    136            
      136  
    136 136 if __name__ == '__main__':  
    137 137     main()  
  • trunk/McGUI.py

    r2 r5  
    29 29         getFileButton = Button(fr1)  
    30 30         getFileButton["text"] = "Script..."  
    31           getFileButton.bind("<Button>",self.GetFile)   
      31         getFileButton.bind("<Button>",self.GetFile)  
    31 31         getFileButton.pack(side="left")  
    32 32         self.filein = Entry(fr1)  
     
    60 60         okaybutton = Button(fr4)  
    61 61         okaybutton["text"] = "Okay   "  
    62           okaybutton.bind("<Button>",self.makePackage)   
      62         okaybutton.bind("<Button>",self.makePackage)  
    62 62         okaybutton.pack(side="left")  
    63 63         cancelbutton = Button(fr4)  
  • trunk/iu.py

    r2 r5  
    10 10 # A shadowpath (a dictionary mapping the names in  
    11 11 # sys.path to their owners) is used so that sys.path  
    12   # (or a package's __path__) is still a bunch of strings,   
      12 # (or a package's __path__) is still a bunch of strings,  
    12 12  
    13 13 STRINGTYPE = type('')  
     
    157 157             return mod  
    158 158         return None  
    159        
      159  
    159 159 class PathImportDirector(ImportDirector):  
    160 160     def __init__(self, pathlist=None, importers=None, ownertypes=None):  
     
    291 291             if i:  
    292 292                 break  
    293                
      293  
    293 293         if i<len(nmparts):  
    294 294             if ctx and hasattr(sys.modules[ctx], nmparts[i]):  
     
    298 298             del sys.modules[fqname]  
    299 299             raise ImportError, "No module named %s" % fqname  
    300           if fromlist is None:   
      300         if fromlist is None:  
    300 300             #print "importHook done with %s %s %s (case 2)" % (name, globals['__name__'], fromlist)  
    301 301             if context:  
     
    484 484                     return a[:i]  
    485 485             return ''  
    486        
      486  
    486 486     global _os_stat  
    487 487     _os_stat = stat  
     
    493 493     global _os_path_dirname  
    494 494     _os_path_dirname = dirname  
    495        
      495  
    495 495     global _os_getcwd  
    496 496     _os_getcwd = getcwd  
    497        
      497  
    497 497 _os_bootstrap()  
    498 498  
  • trunk/archive.py

    r2 r5  
    29 29         _environ = mod.environ  
    30 30         break  
    31            
      31  
    31 31 if hasattr(sys, 'version_info'):  
    32 32     versuffix = '%d%d'%(sys.version_info[0],sys.version_info[1])  
     
    45 45         dot2 = len(vers)  
    46 46     versuffix = '%s%s' % (vers[:dot1], vers[dot1+1:dot2])  
    47        
      47  
    47 47 if "-vi" in sys.argv[1:]:  
    48 48     _verbose = 1  
    49        
      49  
    49 49 class Archive:  
    50 50     """ A base class for a repository of python code objects.  
     
    75 75             self.checkmagic()  
    76 76             self.loadtoc()  
    77                
      77  
    77 77             ####### Sub-methods of __init__ - override as needed #############  
    78 78     def checkmagic(self):  
     
    89 89             raise RuntimeError, "%s has version mismatch to dll" % (self.path)  
    90 90         self.lib.read(4)  
    91            
      91  
    91 91     def loadtoc(self):  
    92 92         """ Overridable.  
     
    100 100         self.lib.seek(self.start + offset)  
    101 101         self.toc = marshal.load(self.lib)  
    102            
      102  
    102 102         ######## This is what is called by FuncImporter #######  
    103 103         ## Since an Archive is flat, we ignore parent and modname.  
     
    113 113         ####            print "I: get_code: iname is %s" % iname  
    114 114         ##    rslt = self.extract(iname) # None if not found, (ispkg, code) otherwise  
    115           ####    if _verbose:   
      115         ####    if _verbose:  
    115 115         ####        print 'I: get_code: rslt', rslt  
    116 116         ##    if rslt is None:  
    117           ####      if _verbose:   
      117         ####      if _verbose:  
    117 117         ####          print 'I: get_code: importer', getattr(parent, "__importer__", None),'self',self  
    118 118         ##      # check the cache if there is no parent or self is the parents importer  
    119 119         ##      if parent is None or getattr(parent, "__importer__", None) is self:  
    120           ####            if _verbose:  
    121           ####                print 'I: get_code: cached 1',iname  
      120         ####            if _verbose:  
      121         ####                print 'I: get_code: cached 1',iname  
    122 122         ##            file, desc = Archive._bincache.get(iname, (None, None))  
    123           ####            if _verbose:   
      123         ####            if _verbose:  
    123 123         ####                print 'I: get_code: file',file,'desc',desc  
    124 124         ##            if file:  
     
    137 137         ##      if _verbose:  
    138 138         ##          print "I: import %s failed" % fqname  
    139           ##       
      139         ##  
    139 139         ##      return None  
    140 140         ##  
     
    147 147         ##        print "I: import %s found %s" % (fqname, iname)  
    148 148         ##    return ispkg, code, values  
    149            
      149  
    149 149         ####### Core method - Override as needed  #########  
    150 150     def extract(self, name):  
     
    167 167         self.lib.seek(self.start + pos)  
    168 168         return ispkg, marshal.load(self.lib)  
    169            
      169  
    169 169         ########################################################################  
    170 170         # Informational methods  
    171            
      171  
    171 171     def contents(self):  
    172 172         """Return a list of the contents  
     
    177 177         """  
    178 178         return self.toc.keys()  
    179            
      179  
    179 179         ########################################################################  
    180 180         # Building  
    181            
      181  
    181 181         ####### Top level method - shouldn't need overriding #######  
    182 182     def build(self, path, lTOC):  
     
    193 193         if self.HDRLEN:  
    194 194             self.lib.write('\0'*self.HDRLEN)  
    195                
      195  
    195 195             #create an empty toc  
    196                
      196  
    196 196         if type(self.TOCTMPLT) == type({}):  
    197 197             self.toc = {}  
    198           else:       # assume callable   
      198         else:       # assume callable  
    198 198             self.toc = self.TOCTMPLT()  
    199                
      199  
    199 199         for tocentry in lTOC:  
    200 200             self.add(tocentry)   # the guts of the archive  
    201                
    202           tocpos = self.lib.tell()  
      201  
      202         tocpos = self.lib.tell()  
    203 203         self.save_toc(tocpos)  
    204 204         if self.TRLLEN:  
    205 205             self.save_trailer(tocpos)  
    206 206         if self.HDRLEN:  
    207               self.update_headers(tocpos)   
      207             self.update_headers(tocpos)  
    207 207         self.lib.close()  
    208            
    209            
      208  
      209  
    210 210         ####### manages keeping the internal TOC and the guts in sync #######  
    211 211     def add(self, entry):  
     
    233 233         f.seek(8)       #skip magic and timestamp  
    234 234         self.lib.write(f.read())  
    235            
      235  
    235 235     def save_toc(self, tocpos):  
    236 236         """Default - toc is a dict  
     
    239 239         """  
    240 240         marshal.dump(self.toc, self.lib)  
    241            
      241  
    241 241     def save_trailer(self, tocpos):  
    242 242         """Default - not used"""  
    243 243         pass  
    244            
      244  
    244 244     def update_headers(self, tocpos):  
    245 245         """Default - MAGIC + Python's magic + tocpos"""  
     
    250 250         self.lib.write(self.pymagic)  
    251 251         self.lib.write(struct.pack('=i', tocpos))  
    252            
      252  
    252 252 class DummyZlib:  
    253 253     def decompress(self, data):  
     
    256 256     def compress(self, data, lvl):  
    257 257         return data  
    258            
      258  
    258 258 import iu  
    259 259 ##############################################################  
     
    269 269     TOCTMPLT = {}  
    270 270     LEVEL = 9  
    271        
      271  
    271 271     def __init__(self, path=None, offset=None, level=9):  
    272 272         if path is None:  
     
    292 292         else:  
    293 293             zlib = DummyZlib()  
    294                
    295                
      294  
      295  
    296 296     def extract(self, name):  
    297 297         (ispkg, pos, lngth) = self.toc.get(name, (0, None, 0))  
     
    304 304             raise ImportError, "PYZ entry '%s' failed to unmarshal" % name  
    305 305         return ispkg, co  
    306            
      306  
    306 306     def add(self, entry):  
    307 307         if self.os is None:  
     
    342 342         Archive.checkmagic(self)  
    343 343         self.LEVEL = struct.unpack('!i', self.lib.read(4))[0]  
    344            
      344  
    344 344 class PYZOwner(iu.Owner):  
    345 345     def __init__(self, path):  
     
    371 371         mod.__co__ = co  
    372 372         return mod  
    373            
      373  
    373 373 class PkgInPYZImporter:  
    374 374     def __init__(self, name, owner):  
     
    385 385     def getmod(self, nm):  
    386 386         return iu.DirOwner.getmod(self, self.prefix+'.'+nm)  
    387            
      387  
    387 387         #XXX this should also get moved out  
    388 388         ##iu._globalownertypes.insert(0, PYZOwner)  
  • trunk/GrabVersion.py

    r2 r5  
    12 12     vs  = versionInfo.decode(sys.argv[1])  
    13 13     print vs  
    14                                                
      14  
  • trunk/Configure.py

    r2 r5  
    166 166     print e, e.args  
    167 167 config['hasUPX'] = hasUPX  
    168            
      168  
    168 168 # now write out config, so Build can load  
    169 169 outf = open(configfile, 'w')  
  • trunk/carchive.py

    r2 r5  
    24 24 class CTOC:  
    25 25   """A class encapsulating the table of contents of a CArchive.  
    26      
      26  
    26 26      When written to disk, it is easily read from C."""  
    27 27   ENTRYSTRUCT = '!iiiibc' #(structlen, dpos, dlen, ulen, flag, typcd) followed by name  
    28 28   def __init__(self):  
    29 29     self.data = []  
    30      
      30  
    30 30   def frombinary(self, s):  
    31 31     """Decode the binary string into an in memory list.  
    32        
      32  
    32 32         S is a binary string."""  
    33 33     entrylen = struct.calcsize(self.ENTRYSTRUCT)  
    34 34     p = 0  
    35 35     while p<len(s):  
    36         (slen, dpos, dlen, ulen, flag, typcd) = struct.unpack(self.ENTRYSTRUCT,  
    37                                                     s[p:p+entrylen])  
    38         nmlen = slen - entrylen  
      36       (slen, dpos, dlen, ulen, flag, typcd) = struct.unpack(self.ENTRYSTRUCT,  
      37                                                   s[p:p+entrylen])  
      38       nmlen = slen - entrylen  
    39 39       p = p + entrylen  
    40 40       (nm,) = struct.unpack(`nmlen`+'s', s[p:p+nmlen])  
     
    53 53           self.data.append((dpos, dlen, ulen, flag, typcd, nm[:pos]))  
    54 54       #end version 5  
    55                              
      55  
    55 55  
    56 56   def tobinary(self):