#NEWLINE# def SplitJar( input_jar , output_directory , maximum_size = sys . maxint , include_predicate = ( lambda name : True ) ) : #NEWLINE# #INDENT# "Copies an input jar into a directory, splitting if necessary.\n\n  If its size is > maximum_size, then new jars will be created in\n  output_directory, called foo-0000.jar, foo-0001.jar, etc. The jar manifest\n  (META-INF/MANIFEST.MF) is not included in the split jars, and neither is the\n  index (INDEX.LIST) if any. Manifests are not heavily used at runtime, and\n  it's not clear what the correct manifest would be in each individual jar.\n\n  Args:\n    input_jar: a string that is the path to the jar to be copied.\n    output_directory: a string that is the directory to put the copy or copies.\n    maximum_size: the maximum allowed total uncompressed size of the files in\n      any given jar.\n    include_predicate: a function that is called once for each entry in the\n      input jar. It is given the name of the entry, and must return a true value\n      if the entry is to be included in the output jar(s).\n\n  Raises:\n    IOError: if the input jar cannot be read or the output jars cannot be\n      written.\n    ValueError: if input_jar does not end with '.jar'.\n    JarWriteError: if an entry in the input jar is bigger than maximum_size.\n  " #NEWLINE# if ( not input_jar . lower ( ) . endswith ( '.jar' ) ) : #NEWLINE# #INDENT# raise ValueError ( ( 'Does not end with .jar: %s' % input_jar ) ) #NEWLINE# #UNINDENT# base_name = os . path . splitext ( os . path . basename ( input_jar ) ) [ 0 ] #NEWLINE# with _Maker ( output_directory , base_name , maximum_size ) as maker : #NEWLINE# #INDENT# for ( name , contents ) in JarContents ( input_jar ) : #NEWLINE# #INDENT# if ( ( name != 'META-INF/MANIFEST.MF' ) and ( name != 'INDEX.LIST' ) and include_predicate ( name ) ) : #NEWLINE# #INDENT# size = len ( contents ) #NEWLINE# if ( size > maximum_size ) : #NEWLINE# #INDENT# raise JarWriteError ( ( 'Entry %s in %s has size %d which is bigger than the maximum jar size %d' % ( name , input_jar , size , maximum_size ) ) ) #NEWLINE# #UNINDENT# maker . WriteStr ( name , contents )