<s> """<STR_LIT>""" <EOL> import getpass <EOL> import logging <EOL> import os <EOL> import platform <EOL> import time <EOL> from grr . client import client_plugins <EOL> from grr . lib import build <EOL> from grr . lib import builders <EOL> from grr . lib import config_lib <EOL> from grr . lib import flags <EOL> from grr . lib import startup <EOL> from grr . lib . builders import signing <EOL> try : <EOL> from grr . lib . builders import component <EOL> except ImportError : <EOL> component = None <EOL> parser = flags . PARSER <EOL> if platform . architecture ( ) [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> default_arch = "<STR_LIT>" <EOL> else : <EOL> default_arch = "<STR_LIT>" <EOL> default_platform = platform . system ( ) . lower ( ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , choices = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> default = default_platform , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" % platform . system ( ) ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , choices = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> default = default_arch , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> if default_platform == "<STR_LIT>" : <EOL> distro = platform . linux_distribution ( ) [ <NUM_LIT:0> ] <EOL> if distro in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> default_package = "<STR_LIT>" <EOL> elif distro in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> default_package = "<STR_LIT>" <EOL> else : <EOL> default_package = None <EOL> elif default_platform == "<STR_LIT>" : <EOL> default_package = "<STR_LIT>" <EOL> elif default_platform == "<STR_LIT>" : <EOL> default_package = "<STR_LIT>" <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , choices = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> default = default_package , <EOL> help = "<STR_LIT>" ) <EOL> subparsers = parser . add_subparsers ( <EOL> title = "<STR_LIT>" , dest = "<STR_LIT>" , description = "<STR_LIT>" ) <EOL> parser_build = subparsers . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser_build . add_argument ( "<STR_LIT>" , default = None , <EOL> help = "<STR_LIT>" ) <EOL> parser_repack = subparsers . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_repack . add_argument ( "<STR_LIT>" , default = None , <EOL> help = "<STR_LIT>" ) <EOL> parser_repack . add_argument ( "<STR_LIT>" , default = None , <EOL> help = "<STR_LIT>" ) <EOL> parser_repack . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_repack . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser_repack . add_argument ( "<STR_LIT>" , "<STR_LIT>" , default = [ ] , nargs = "<STR_LIT:+>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_deploy = subparsers . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser_deploy . add_argument ( "<STR_LIT>" , default = None , <EOL> help = "<STR_LIT>" ) <EOL> parser_deploy . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_deploy . add_argument ( "<STR_LIT>" , default = None , <EOL> help = "<STR_LIT>" ) <EOL> parser_deploy . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_deploy . add_argument ( "<STR_LIT>" , "<STR_LIT>" , default = [ ] , nargs = "<STR_LIT:+>" , <EOL> help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_deploy . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser_buildanddeploy = subparsers . add_parser ( <EOL> "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser_buildanddeploy . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" , help = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> parser_buildanddeploy . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> default = False , help = "<STR_LIT>" ) <EOL> if component : <EOL> parser_build_component = subparsers . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser_build_component . add_argument ( <EOL> "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser_build_component . add_argument ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser_build_components = subparsers . add_parser ( <EOL> "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser_build_components . add_argument ( <EOL> "<STR_LIT>" , default = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( ) <EOL> def GetBuilder ( context ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if "<STR_LIT>" in context : <EOL> builder_class = builders . DarwinClientBuilder <EOL> elif "<STR_LIT>" in context : <EOL> builder_class = builders . WindowsClientBuilder <EOL> elif "<STR_LIT>" in context : <EOL> builder_class = builders . LinuxClientBuilder <EOL> elif "<STR_LIT>" in context : <EOL> builder_class = builders . CentosClientBuilder <EOL> else : <EOL> parser . error ( "<STR_LIT>" % context ) <EOL> except AttributeError : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" % args . platform ) <EOL> return builder_class ( context = context ) <EOL> def GetDeployer ( context , signer = None ) : <EOL> """<STR_LIT>""" <EOL> if "<STR_LIT>" in context : <EOL> deployer_class = build . DarwinClientDeployer <EOL> elif "<STR_LIT>" in context : <EOL> deployer_class = build . WindowsClientDeployer <EOL> elif "<STR_LIT>" in context : <EOL> deployer_class = build . LinuxClientDeployer <EOL> elif "<STR_LIT>" in context : <EOL> deployer_class = build . CentosClientDeployer <EOL> else : <EOL> parser . error ( "<STR_LIT>" % context ) <EOL> return deployer_class ( context = context , signer = signer ) <EOL> def GetSigner ( context ) : <EOL> if args . subparser_name in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> if args . platform == "<STR_LIT>" : <EOL> print "<STR_LIT>" <EOL> passwd = getpass . getpass ( ) <EOL> cert = config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = context ) <EOL> key = config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = context ) <EOL> app_name = config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = context ) <EOL> return signing . WindowsCodeSigner ( cert , key , passwd , app_name ) <EOL> elif args . platform == "<STR_LIT>" and args . package_format == "<STR_LIT>" : <EOL> pub_keyfile = config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = context ) <EOL> gpg_name = config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = context ) <EOL> print "<STR_LIT>" % ( gpg_name ) <EOL> passwd = getpass . getpass ( ) <EOL> return signing . RPMCodeSigner ( passwd , pub_keyfile , gpg_name ) <EOL> else : <EOL> parser . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def TemplateInputFilename ( context ) : <EOL> """<STR_LIT>""" <EOL> if args . templatedir : <EOL> filename = config_lib . CONFIG . Get ( "<STR_LIT>" , <EOL> context = context ) <EOL> return os . path . join ( args . templatedir , filename ) <EOL> return None <EOL> def BuildAndDeployWindows ( signer = None ) : <EOL> """<STR_LIT>""" <EOL> build_combos = [ <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : True } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : False } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : True } , <EOL> { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : False } ] <EOL> timestamp = time . strftime ( "<STR_LIT>" , time . gmtime ( ) ) <EOL> args . package_format = "<STR_LIT>" <EOL> context_orig = SetOSContextFromArgs ( [ ] ) <EOL> context = list ( context_orig ) <EOL> for argset in build_combos : <EOL> for key , value in argset . items ( ) : <EOL> setattr ( args , key , value ) <EOL> context = SetArchContextFromArgs ( context ) <EOL> context = SetDebugContextFromArgs ( context ) <EOL> print "<STR_LIT>" % context <EOL> BuildAndDeploy ( context , timestamp = timestamp , signer = signer ) <EOL> context = list ( context_orig ) <EOL> def BuildAndDeploy ( context , signer = None , timestamp = None ) : <EOL> """<STR_LIT>""" <EOL> timestamp = timestamp or time . strftime ( "<STR_LIT>" , time . gmtime ( ) ) <EOL> if args . plugins : <EOL> config_lib . CONFIG . Set ( "<STR_LIT>" , args . plugins ) <EOL> spec = "<STR_LIT:_>" . join ( ( args . platform , args . arch , args . package_format ) ) <EOL> output_dir = os . path . join ( config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = context ) , timestamp , spec ) <EOL> if args . templatedir : <EOL> template_path = TemplateInputFilename ( context ) <EOL> else : <EOL> component . BuildComponents ( output_dir = output_dir ) <EOL> template_path = os . path . join ( output_dir , config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = context ) ) <EOL> builder_obj = GetBuilder ( context ) <EOL> builder_obj . MakeExecutableTemplate ( output_file = template_path ) <EOL> context_list = config_lib . CONFIG . Get ( "<STR_LIT>" ) <EOL> logging . info ( "<STR_LIT>" , context_list ) <EOL> deployed_list = [ ] <EOL> for deploycontext in context_list : <EOL> for newcontext in deploycontext . split ( "<STR_LIT:U+002C>" ) : <EOL> context . append ( newcontext ) <EOL> try : <EOL> deployer = GetDeployer ( context , signer = signer ) <EOL> if not config_lib . CONFIG . MatchBuildContext ( args . platform , args . arch , <EOL> args . package_format , <EOL> context = deployer . context ) : <EOL> continue <EOL> context_filename = deploycontext . replace ( <EOL> "<STR_LIT>" , "<STR_LIT>" ) . replace ( "<STR_LIT:U+002C>" , "<STR_LIT:_>" ) . replace ( "<STR_LIT:U+0020>" , "<STR_LIT:_>" ) <EOL> deployed_list . append ( context_filename ) <EOL> output_filename = os . path . join ( <EOL> output_dir , context_filename , <EOL> config_lib . CONFIG . Get ( "<STR_LIT>" , <EOL> context = deployer . context ) ) <EOL> logging . info ( "<STR_LIT>" , deploycontext , <EOL> config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = deployer . context ) , <EOL> config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = deployer . context ) ) <EOL> deployer . MakeDeployableBinary ( template_path , output_filename ) <EOL> finally : <EOL> for newcontext in deploycontext . split ( "<STR_LIT:U+002C>" ) : <EOL> context . remove ( newcontext ) <EOL> logging . info ( "<STR_LIT>" , deployed_list , <EOL> output_dir ) <EOL> def Deploy ( context , signer = None ) : <EOL> """<STR_LIT>""" <EOL> if args . plugins : <EOL> config_lib . CONFIG . Set ( "<STR_LIT>" , args . plugins ) <EOL> deployer = GetDeployer ( context , signer = signer ) <EOL> template_path = ( args . template or TemplateInputFilename ( deployer . context ) or <EOL> config_lib . CONFIG . Get ( "<STR_LIT>" , <EOL> context = deployer . context ) ) <EOL> output = None <EOL> if args . output : <EOL> output = args . output <EOL> elif args . outputdir : <EOL> filename = "<STR_LIT:.>" . join ( <EOL> ( config_lib . CONFIG . Get ( "<STR_LIT>" , <EOL> context = deployer . context ) , "<STR_LIT>" ) ) <EOL> output = os . path . join ( args . outputdir , filename ) <EOL> deployer . MakeDeployableBinary ( template_path , output ) <EOL> def Repack ( context , signer = None ) : <EOL> """<STR_LIT>""" <EOL> if args . plugins : <EOL> config_lib . CONFIG . Set ( "<STR_LIT>" , args . plugins ) <EOL> deployer = GetDeployer ( context , signer = signer ) <EOL> output_filename = os . path . join ( <EOL> args . outputdir , config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = deployer . context ) ) <EOL> deployer . RepackInstaller ( open ( args . template , "<STR_LIT:rb>" ) . read ( ) , args . output or <EOL> output_filename ) <EOL> def SetOSContextFromArgs ( context ) : <EOL> """<STR_LIT>""" <EOL> context . append ( "<STR_LIT>" ) <EOL> if args . platform == "<STR_LIT>" : <EOL> context = [ "<STR_LIT>" , "<STR_LIT>" ] + context <EOL> elif args . platform == "<STR_LIT>" : <EOL> context = [ "<STR_LIT>" , "<STR_LIT>" ] + context <EOL> elif args . platform == "<STR_LIT>" : <EOL> context = [ "<STR_LIT>" , "<STR_LIT>" ] + context <EOL> if args . package_format == "<STR_LIT>" : <EOL> context = [ "<STR_LIT>" ] + context <EOL> elif args . package_format == "<STR_LIT>" : <EOL> context = [ "<STR_LIT>" ] + context <EOL> else : <EOL> parser . error ( "<STR_LIT>" % <EOL> platform . linux_distribution ( ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> parser . error ( "<STR_LIT>" % args . platform ) <EOL> return context <EOL> def SetArchContextFromArgs ( context ) : <EOL> if args . arch == "<STR_LIT>" : <EOL> context . append ( "<STR_LIT>" ) <EOL> else : <EOL> context . append ( "<STR_LIT>" ) <EOL> return context <EOL> def SetDebugContextFromArgs ( context ) : <EOL> if args . subparser_name != "<STR_LIT>" and getattr ( args , "<STR_LIT>" , None ) : <EOL> context += [ "<STR_LIT>" ] <EOL> return context <EOL> def SetContextFromArgs ( context ) : <EOL> context = SetArchContextFromArgs ( context ) <EOL> context = SetDebugContextFromArgs ( context ) <EOL> return SetOSContextFromArgs ( context ) <EOL> def main ( _ ) : <EOL> """<STR_LIT>""" <EOL> config_lib . CONFIG . AddContext ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> startup . ClientInit ( ) <EOL> for secondconfig in config_lib . CONFIG [ "<STR_LIT>" ] : <EOL> config_lib . CONFIG . LoadSecondaryConfig ( secondconfig ) <EOL> logger = logging . getLogger ( ) <EOL> handler = logging . StreamHandler ( ) <EOL> handler . setLevel ( logging . INFO ) <EOL> logger . handlers = [ handler ] <EOL> context = flags . FLAGS . context <EOL> context = SetContextFromArgs ( context ) <EOL> signer = None <EOL> if args . sign : <EOL> if not args . templatedir : <EOL> raise RuntimeError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> signer = GetSigner ( context ) <EOL> if args . subparser_name == "<STR_LIT>" : <EOL> template_path = None <EOL> if flags . FLAGS . output : <EOL> template_path = os . path . join ( flags . FLAGS . output , config_lib . CONFIG . Get ( <EOL> "<STR_LIT>" , context = context ) ) <EOL> builder_obj = GetBuilder ( context ) <EOL> builder_obj . MakeExecutableTemplate ( output_file = template_path ) <EOL> elif args . subparser_name == "<STR_LIT>" : <EOL> Repack ( context , signer = signer ) <EOL> elif args . subparser_name == "<STR_LIT>" : <EOL> Deploy ( context , signer = signer ) <EOL> elif args . subparser_name == "<STR_LIT>" : <EOL> if args . platform == "<STR_LIT>" : <EOL> BuildAndDeployWindows ( signer = signer ) <EOL> else : <EOL> BuildAndDeploy ( context , signer = signer ) <EOL> elif args . subparser_name == "<STR_LIT>" : <EOL> component . BuildComponents ( output_dir = flags . FLAGS . output ) <EOL> elif args . subparser_name == "<STR_LIT>" : <EOL> component . BuildComponent ( flags . FLAGS . setup_file , <EOL> output_dir = flags . FLAGS . output ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> flags . StartMain ( main ) </s>
