def pyminify(options, files):
global name_generator<EOL>if not is_iterable(files):<EOL><INDENT>print(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>if options.pyz:<EOL><INDENT>if len(files) > <NUM_LIT:1>:<EOL><INDENT>print("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>print("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>sys.exit(<NUM_LIT:1>)<EOL><DEDENT>compression.zip_pack(files, options)<EOL>return None <EOL><DEDENT>prepend = None<EOL>if options.prepend:<EOL><INDENT>try:<EOL><INDENT>prepend = open(options.prepend).read()<EOL><DEDENT>except Exception as err:<EOL><INDENT>print("<STR_LIT>" % options.prepend)<EOL>print(err)<EOL><DEDENT><DEDENT>obfuscations = (options.obfuscate, options.obf_classes,<EOL>options.obf_functions, options.obf_variables,<EOL>options.obf_builtins, options.obf_import_methods)<EOL>if options.use_nonlatin and not any(obfuscations):<EOL><INDENT>options.obfuscate = True<EOL><DEDENT>if len(files) > <NUM_LIT:1>: <EOL><INDENT>name_generator = None <EOL>if any(obfuscations):<EOL><INDENT>identifier_length = int(options.replacement_length)<EOL>if options.use_nonlatin:<EOL><INDENT>if sys.version_info[<NUM_LIT:0>] == <NUM_LIT:3>:<EOL><INDENT>name_generator = obfuscate.obfuscation_machine(<EOL>use_unicode=True, identifier_length=identifier_length<EOL>)<EOL><DEDENT>else:<EOL><INDENT>print(<EOL>"<STR_LIT>")<EOL>sys.exit(<NUM_LIT:2>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>name_generator = obfuscate.obfuscation_machine(<EOL>identifier_length=identifier_length)<EOL><DEDENT>table =[{}]<EOL><DEDENT>cumulative_size = <NUM_LIT:0> <EOL>cumulative_new = <NUM_LIT:0> <EOL>for sourcefile in files:<EOL><INDENT>filesize = os.path.getsize(sourcefile)<EOL>cumulative_size += filesize<EOL>module = os.path.split(sourcefile)[<NUM_LIT:1>]<EOL>module = "<STR_LIT:.>".join(module.split('<STR_LIT:.>')[:-<NUM_LIT:1>])<EOL>source = open(sourcefile).read()<EOL>tokens = token_utils.listified_tokenizer(source)<EOL>if not options.nominify: <EOL><INDENT>source = minification.minify(tokens, options)<EOL><DEDENT>tokens = token_utils.listified_tokenizer(source)<EOL>if name_generator:<EOL><INDENT>obfuscate.obfuscate(<EOL>module,<EOL>tokens,<EOL>options,<EOL>name_generator=name_generator,<EOL>table=table<EOL>)<EOL><DEDENT>result = '<STR_LIT>'<EOL>if prepend:<EOL><INDENT>result += prepend<EOL><DEDENT>result += token_utils.untokenize(tokens)<EOL>if options.bzip2:<EOL><INDENT>result = compression.bz2_pack(result)<EOL><DEDENT>elif options.gzip:<EOL><INDENT>result = compression.gz_pack(result)<EOL><DEDENT>elif lzma and options.lzma:<EOL><INDENT>result = compression.lzma_pack(result)<EOL><DEDENT>result += (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>if not os.path.exists(options.destdir):<EOL><INDENT>os.mkdir(options.destdir)<EOL><DEDENT>filepath = os.path.split(sourcefile)[<NUM_LIT:1>]<EOL>path = options.destdir + '<STR_LIT:/>' + filepath <EOL>f = open(path, '<STR_LIT:w>')<EOL>f.write(result)<EOL>f.close()<EOL>new_filesize = os.path.getsize(path)<EOL>cumulative_new += new_filesize<EOL>percent_saved = round((float(new_filesize) / float(filesize)) * <NUM_LIT:100>, <NUM_LIT:2>) if float(filesize)!=<NUM_LIT:0> else <NUM_LIT:0><EOL>print((<EOL>"<STR_LIT>"<EOL>"<STR_LIT>").format(**locals()))<EOL><DEDENT>p_saved = round(<EOL>(float(cumulative_new) / float(cumulative_size) * <NUM_LIT:100>), <NUM_LIT:2>)<EOL>print("<STR_LIT>".format(p_saved))<EOL><DEDENT>else:<EOL><INDENT>_file = files[<NUM_LIT:0>]<EOL>module = os.path.split(_file)[<NUM_LIT:1>]<EOL>module = "<STR_LIT:.>".join(module.split('<STR_LIT:.>')[:-<NUM_LIT:1>])<EOL>filesize = os.path.getsize(_file)<EOL>source = open(_file).read()<EOL>tokens = token_utils.listified_tokenizer(source)<EOL>if not options.nominify: <EOL><INDENT>source = minification.minify(tokens, options)<EOL>tokens = token_utils.listified_tokenizer(source)<EOL><DEDENT>if options.obfuscate or options.obf_classes or options.obf_functionsor options.obf_variables or options.obf_builtinsor options.obf_import_methods:<EOL><INDENT>identifier_length = int(options.replacement_length)<EOL>name_generator = obfuscate.obfuscation_machine(<EOL>identifier_length=identifier_length)<EOL>obfuscate.obfuscate(module, tokens, options)<EOL><DEDENT>result = '<STR_LIT>'<EOL>if prepend:<EOL><INDENT>result += prepend<EOL><DEDENT>result += token_utils.untokenize(tokens)<EOL>if options.bzip2:<EOL><INDENT>result = compression.bz2_pack(result)<EOL><DEDENT>elif options.gzip:<EOL><INDENT>result = compression.gz_pack(result)<EOL><DEDENT>elif lzma and options.lzma:<EOL><INDENT>result = compression.lzma_pack(result)<EOL><DEDENT>result += (<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL>if options.outfile:<EOL><INDENT>f = io.open(options.outfile, '<STR_LIT:w>', encoding='<STR_LIT:utf-8>')<EOL>f.write(result)<EOL>f.close()<EOL>new_filesize = os.path.getsize(options.outfile)<EOL>percent_saved = round(float(new_filesize)/float(filesize) * <NUM_LIT:100>, <NUM_LIT:2>)<EOL>print((<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(**locals())))<EOL><DEDENT>else:<EOL><INDENT>print(result)<EOL><DEDENT><DEDENT>
Given an *options* object (from `optparse.OptionParser` or similar),
performs minification and/or obfuscation on the given *files* (any iterable
containing file paths) based on said *options*.

All accepted options can　be listed by running ``python __main__.py -h`` or
examining the :py:func:`__init__.main` function.