#NEWLINE# def _source( b , r , dirname , old_cwd ) : #NEWLINE# #INDENT# tmpname = os . path . join ( os . getcwd ( ) , dirname [ 1 : ] . replace ( '/' , '-' ) ) #NEWLINE# exclude = [ ] #NEWLINE# pattern_pip = re . compile ( '\\.egg-info/installed-files.txt$' ) #NEWLINE# pattern_egg = re . compile ( '\\.egg(?:-info)?(?:/|$)' ) #NEWLINE# pattern_pth = re . compile ( 'lib/python[^/]+/(?:dist|site)-packages/easy-install.pth$' ) #NEWLINE# pattern_bin = re . compile ( 'EASY-INSTALL(?:-ENTRY)?-SCRIPT|This file was generated by RubyGems' ) #NEWLINE# for ( dirpath , dirnames , filenames ) in os . walk ( dirname ) : #NEWLINE# #INDENT# if dirpath . startswith ( tmpname ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ignored = r . ignore_file ( dirpath ) #NEWLINE# dirpath2 = os . path . normpath ( os . path . join ( tmpname , os . path . relpath ( dirpath , dirname ) ) ) #NEWLINE# os . mkdir ( dirpath2 ) #NEWLINE# s = os . lstat ( dirpath ) #NEWLINE# try : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . lchown ( dirpath2 , s . st_uid , s . st_gid ) #NEWLINE# #UNINDENT# except OverflowError : #NEWLINE# #INDENT# logging . warning ( '{0} has uid:gid {1}:{2} - using chown(1)' . format ( dirpath , s . st_uid , s . st_gid ) ) #NEWLINE# p = subprocess . Popen ( [ 'chown' , '{0}:{1}' . format ( s . st_uid , s . st_gid ) , dirpath2 ] , close_fds = True ) #NEWLINE# p . communicate ( ) #NEWLINE# #UNINDENT# os . chmod ( dirpath2 , s . st_mode ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# logging . warning ( '{0} caused {1} - try running as root' . format ( dirpath , errno . errorcode [ e . errno ] ) ) #NEWLINE# return #NEWLINE# #UNINDENT# for filename in filenames : #NEWLINE# #INDENT# pathname = os . path . join ( dirpath , filename ) #NEWLINE# if r . ignore_source ( pathname , ignored ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# pathname2 = os . path . join ( dirpath2 , filename ) #NEWLINE# for globname in ( os . path . join ( '/usr/lib/ruby/gems/*/gems/rubygems-update-*/lib' , pathname [ 1 : ] ) , os . path . join ( '/var/lib/gems/*/gems/rubygems-update-*/lib' , pathname [ 1 : ] ) ) : #NEWLINE# #INDENT# if ( 0 < len ( glob . glob ( globname ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# if pattern_pip . search ( pathname ) : #NEWLINE# #INDENT# exclude . extend ( [ os . path . join ( dirpath2 , line . rstrip ( ) ) for line in open ( pathname ) ] ) #NEWLINE# #UNINDENT# if pattern_egg . search ( pathname ) : #NEWLINE# #INDENT# exclude . append ( pathname2 ) #NEWLINE# #UNINDENT# if pattern_pth . search ( pathname ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if pathname . startswith ( '/usr/local/bin/' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if pattern_bin . search ( open ( pathname ) . read ( ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# except IOError as e : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# if ( '/usr/local/share/applications/mimeinfo.cache' == pathname ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# s = os . lstat ( pathname ) #NEWLINE# if stat . S_ISLNK ( s . st_mode ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . stat ( pathname ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# if ( errno . ENOENT == e . errno ) : #NEWLINE# #INDENT# logging . warning ( 'ignored dangling symbolic link {0}' . format ( pathname ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# os . link ( pathname , pathname2 ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# logging . warning ( '{0} caused {1} - try running as root' . format ( pathname , errno . errorcode [ e . errno ] ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for pathname in exclude : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . unlink ( pathname ) #NEWLINE# #UNINDENT# except OSError as e : #NEWLINE# #INDENT# if ( e . errno not in ( errno . EISDIR , errno . ENOENT ) ) : #NEWLINE# #INDENT# raise e #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for ( dirpath , dirnames , filenames ) in os . walk ( tmpname , topdown = False ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# os . rmdir ( dirpath ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# s = os . lstat ( os . path . join ( dirname , os . path . relpath ( dirpath , tmpname ) ) ) #NEWLINE# os . utime ( dirpath , ( s . st_atime , s . st_mtime ) ) #NEWLINE# #UNINDENT# #UNINDENT# try : #NEWLINE# #INDENT# tar = tarfile . open ( 'tmp.tar' , 'w' ) #NEWLINE# tar . add ( tmpname , '.' ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# tar . close ( ) #NEWLINE# #UNINDENT# sha1 = hashlib . sha1 ( ) #NEWLINE# f = open ( 'tmp.tar' , 'r' ) #NEWLINE# [ sha1 . update ( buf ) for buf in iter ( ( lambda : f . read ( 4096 ) ) , '' ) ] #NEWLINE# f . close ( ) #NEWLINE# tarname = '{0}.tar' . format ( sha1 . hexdigest ( ) ) #NEWLINE# shutil . move ( 'tmp.tar' , os . path . join ( old_cwd , tarname ) ) #NEWLINE# b . add_source ( dirname , tarname )