def run(self, filename): """Run processing on a given file, with results being written back to same filename.""" # make a tempdir so I can use a file-like object # instead of an OS-level handle (like with mkstemp) tdir = make_tempdir() tname = os.path.join(tdir,'process.out') #print "TEMPDIR = ",tdir #print "TEMPFILE = ",tname f_out = open(tname,'wb') f_in = open(filename,'rb') # process in->out self.process(f_out, f_in) del f_out del f_in # copy tempfile -> filename #print "COPY %s -> %s" % (tname,filename) # I think this is secure ... since caller owns filename # there isn't a race, right? (unlike writing into a tempdir # which could have malicious symlinks in it) copy2( tname, filename ) #print "RMDIR %s" % tname # clean up tempdir unlink(tname) os.rmdir(tdir)
def remake_MANIFEST(): print "Creating MANIFEST ..." # create empty MANIFEST unlink('MANIFEST') open('MANIFEST', 'w').write('') # create real MANIFEST, including MANIFEST in listing # (yes, it's weird, but works best this way) os.system('%s setup.py sdist --manifest-only' % sys.executable)
def get_pyver_from_exe( exename ): """ Given a python executable, find out its version. Returns version as 3-item list: (os.name, sys.platform, version) Where version is a 3-element list, e.g. [2,1,3] Returns None if can't get version. """ # hack: when running a win32-native Python from a cygwin shell, # with cygwin Python installed, you'll see cygwin symlinks to the # real cygwin Python, but NTVDM.exe will crash when trying to run # the symlinks. Of course, to win32, they aren't links, so I can't # just filter them with islink(). Instead, I check if the binary # looks too small to be real. if os.stat(exename)[ST_SIZE] < 1000: return None # this is required to work on Python 1.5.2 # note that splitting sys.version doesn't work on .0 releases, so # I try sys.version_info first, but it isn't available on 1.5.2. # Don't insert any lefthand spaces! pycmd = """ import sys, string, os try: v = sys.version_info[0],sys.version_info[1],sys.version_info[2] except: v = map(int,string.split(string.split(sys.version)[0],'.')) open('lineout','w').write('%s %s %s %s %s\\n' % (os.name,sys.platform,v[0],v[1],v[2])) """ # the most portable thing to do is write pycmd to a file, and # have pycmd write its results to a file as well. so make # a temp directory to run from. savedir = os.getcwd() tempdir = make_tempdir() os.chdir(tempdir) f = open('test.py','w') f.write( pycmd ) del f # explicit close seems to be needed under win32 (i.e. open().write() fails) os.system('%s test.py' % exename) if not os.path.isfile('lineout'): return None # failed to run f = open('lineout','r') line = f.readline() del f # explicitly, for win32 unlink('lineout') unlink('test.py') os.chdir(savedir) os.rmdir(tempdir) p = line.split() return (p[0], p[1], list(map( int, p[2:] )))
print "Cleaning tree ..." # remove .pyc, *~, coredumps, .md5envelope files patts = "*.pyc,*~,core,*.md5envelope" os.system('%s disthelper/scripts/rmfind.py -v -R "%s" .' % \ (sys.executable,patts)) # rm -rf build & dist rmtree('build') rmtree('dist') # remove some test output files that may be around gxpt = os.path.join('gnosis', 'xml', 'pickle', 'test') names = glob(os.path.join(gxpt, 'TESTS.OUT-*')) for name in names: unlink(name) unlink(os.path.join(gxpt, 'aaa.xml')) unlink('MANIFEST') unlink('PKG-INFO') # setup will complain if MANIFEST missing, so just regenerate remake_MANIFEST() sys.exit(0) if 'taball' in sys.argv: "Convert spaces->tabs in all .py files" #os.system('%s disthelper/scripts/tabtree.py -v -x py -r .' % \ # sys.executable) sys.exit(0)
def process_one_file(self, fullname, opts): "Called for each matched file." if opts.verbose: print "rm", fullname unlink(fullname)