<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import , print_function <EOL> import base64 <EOL> import copy <EOL> import getpass <EOL> import json <EOL> import logging <EOL> import multiprocessing <EOL> import subprocess <EOL> import hashlib <EOL> import tarfile <EOL> import os <EOL> import re <EOL> import sys <EOL> import time <EOL> import yaml <EOL> import uuid <EOL> import tempfile <EOL> import binascii <EOL> import sys <EOL> import salt . client . ssh . shell <EOL> import salt . client . ssh . wrapper <EOL> import salt . config <EOL> import salt . exceptions <EOL> import salt . defaults . exitcodes <EOL> import salt . log <EOL> import salt . loader <EOL> import salt . minion <EOL> import salt . roster <EOL> import salt . serializers . yaml <EOL> import salt . state <EOL> import salt . utils <EOL> import salt . utils . args <EOL> import salt . utils . event <EOL> import salt . utils . atomicfile <EOL> import salt . utils . thin <EOL> import salt . utils . url <EOL> import salt . utils . verify <EOL> import salt . utils . network <EOL> from salt . utils import is_windows <EOL> from salt . utils . process import MultiprocessingProcess <EOL> import salt . ext . six as six <EOL> from salt . ext . six . moves import input <EOL> try : <EOL> import zmq <EOL> HAS_ZMQ = True <EOL> except ImportError : <EOL> HAS_ZMQ = False <EOL> DEFAULT_THIN_DIR = '<STR_LIT>' <EOL> RSTR = '<STR_LIT>' <EOL> RSTR_RE = r'<STR_LIT>' + RSTR + '<STR_LIT>' <EOL> SSH_SH_SHIM = '<STR_LIT:\n>' . join ( <EOL> [ s . strip ( ) for s in r'''<STR_LIT>''' . format ( <EOL> EX_THIN_PYTHON_INVALID = salt . defaults . exitcodes . EX_THIN_PYTHON_INVALID , <EOL> ) . split ( '<STR_LIT:\n>' ) ] ) <EOL> if not is_windows ( ) : <EOL> shim_file = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> if not os . path . exists ( shim_file ) : <EOL> shim_file += "<STR_LIT:c>" <EOL> with salt . utils . fopen ( shim_file ) as ssh_py_shim : <EOL> SSH_PY_SHIM = ssh_py_shim . read ( ) <EOL> log = logging . getLogger ( __name__ ) <EOL> class SSH ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , opts ) : <EOL> pull_sock = os . path . join ( opts [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> if os . path . isfile ( pull_sock ) and HAS_ZMQ : <EOL> self . event = salt . utils . event . get_event ( <EOL> '<STR_LIT>' , <EOL> opts [ '<STR_LIT>' ] , <EOL> opts [ '<STR_LIT>' ] , <EOL> opts = opts , <EOL> listen = False ) <EOL> else : <EOL> self . event = None <EOL> self . opts = opts <EOL> if not salt . utils . which ( '<STR_LIT>' ) : <EOL> raise salt . exceptions . SaltSystemExit ( '<STR_LIT>' ) <EOL> self . opts [ '<STR_LIT>' ] = ssh_version ( ) <EOL> self . tgt_type = self . opts [ '<STR_LIT>' ] if self . opts [ '<STR_LIT>' ] else '<STR_LIT>' <EOL> self . roster = salt . roster . Roster ( opts , opts . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . targets = self . roster . targets ( <EOL> self . opts [ '<STR_LIT>' ] , <EOL> self . tgt_type ) <EOL> if '<STR_LIT>' in self . opts : <EOL> if self . opts [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) and os . path . isfile ( os . path . expanduser ( '<STR_LIT>' ) ) : <EOL> priv = os . path . expanduser ( '<STR_LIT>' ) <EOL> else : <EOL> priv = self . opts [ '<STR_LIT>' ] . get ( <EOL> '<STR_LIT>' , <EOL> os . path . join ( <EOL> self . opts [ '<STR_LIT>' ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> else : <EOL> priv = self . opts . get ( <EOL> '<STR_LIT>' , <EOL> os . path . join ( <EOL> self . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> if priv != '<STR_LIT>' : <EOL> if not os . path . isfile ( priv ) : <EOL> try : <EOL> salt . client . ssh . shell . gen_key ( priv ) <EOL> except OSError : <EOL> raise salt . exceptions . SaltClientError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . defaults = { <EOL> '<STR_LIT:user>' : self . opts . get ( <EOL> '<STR_LIT>' , <EOL> salt . config . DEFAULT_MASTER_OPTS [ '<STR_LIT>' ] <EOL> ) , <EOL> '<STR_LIT:port>' : self . opts . get ( <EOL> '<STR_LIT>' , <EOL> salt . config . DEFAULT_MASTER_OPTS [ '<STR_LIT>' ] <EOL> ) , <EOL> '<STR_LIT>' : self . opts . get ( <EOL> '<STR_LIT>' , <EOL> salt . config . DEFAULT_MASTER_OPTS [ '<STR_LIT>' ] <EOL> ) , <EOL> '<STR_LIT>' : priv , <EOL> '<STR_LIT>' : self . opts . get ( <EOL> '<STR_LIT>' , <EOL> salt . config . DEFAULT_MASTER_OPTS [ '<STR_LIT>' ] <EOL> ) + self . opts . get ( <EOL> '<STR_LIT>' , <EOL> salt . config . DEFAULT_MASTER_OPTS [ '<STR_LIT>' ] <EOL> ) , <EOL> '<STR_LIT>' : self . opts . get ( <EOL> '<STR_LIT>' , <EOL> salt . config . DEFAULT_MASTER_OPTS [ '<STR_LIT>' ] <EOL> ) , <EOL> '<STR_LIT>' : self . opts . get ( <EOL> '<STR_LIT>' , <EOL> salt . config . DEFAULT_MASTER_OPTS [ '<STR_LIT>' ] <EOL> ) , <EOL> } <EOL> if self . opts . get ( '<STR_LIT>' ) : <EOL> self . defaults [ '<STR_LIT>' ] = os . path . join ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' . format ( uuid . uuid4 ( ) . hex [ : <NUM_LIT:6> ] ) ) <EOL> self . opts [ '<STR_LIT>' ] = '<STR_LIT:True>' <EOL> self . serial = salt . payload . Serial ( opts ) <EOL> self . returners = salt . loader . returners ( self . opts , { } ) <EOL> self . fsclient = salt . fileclient . FSClient ( self . opts ) <EOL> self . thin = salt . utils . thin . gen_thin ( self . opts [ '<STR_LIT>' ] , <EOL> python2_bin = self . opts [ '<STR_LIT>' ] , <EOL> python3_bin = self . opts [ '<STR_LIT>' ] ) <EOL> self . mods = mod_data ( self . fsclient ) <EOL> def get_pubkey ( self ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in self . opts and self . opts [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) and os . path . isfile ( os . path . expanduser ( '<STR_LIT>' ) ) : <EOL> priv = os . path . expanduser ( '<STR_LIT>' ) <EOL> else : <EOL> priv = self . opts . get ( <EOL> '<STR_LIT>' , <EOL> os . path . join ( <EOL> self . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> ) <EOL> pub = '<STR_LIT>' . format ( priv ) <EOL> with salt . utils . fopen ( pub , '<STR_LIT:r>' ) as fp_ : <EOL> return '<STR_LIT>' . format ( fp_ . read ( ) . split ( ) [ <NUM_LIT:1> ] ) <EOL> def key_deploy ( self , host , ret ) : <EOL> '''<STR_LIT>''' <EOL> if not isinstance ( ret [ host ] , dict ) or self . opts . get ( '<STR_LIT>' ) : <EOL> target = self . targets [ host ] <EOL> if '<STR_LIT>' in target or self . opts [ '<STR_LIT>' ] : <EOL> self . _key_deploy_run ( host , target , False ) <EOL> return ret <EOL> if ret [ host ] . get ( '<STR_LIT>' , '<STR_LIT>' ) . count ( '<STR_LIT>' ) : <EOL> target = self . targets [ host ] <EOL> print ( ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( host ) ) <EOL> deploy = input ( '<STR_LIT>' ) <EOL> if deploy . startswith ( ( '<STR_LIT:n>' , '<STR_LIT:N>' ) ) : <EOL> return ret <EOL> target [ '<STR_LIT>' ] = getpass . getpass ( <EOL> '<STR_LIT>' . format ( target [ '<STR_LIT:user>' ] , host ) <EOL> ) <EOL> return self . _key_deploy_run ( host , target , True ) <EOL> return ret <EOL> def _key_deploy_run ( self , host , target , re_run = True ) : <EOL> '''<STR_LIT>''' <EOL> argv = [ <EOL> '<STR_LIT>' , <EOL> target . get ( '<STR_LIT:user>' , '<STR_LIT:root>' ) , <EOL> self . get_pubkey ( ) , <EOL> ] <EOL> single = Single ( <EOL> self . opts , <EOL> argv , <EOL> host , <EOL> mods = self . mods , <EOL> fsclient = self . fsclient , <EOL> thin = self . thin , <EOL> ** target ) <EOL> if salt . utils . which ( '<STR_LIT>' ) : <EOL> stdout , stderr , retcode = single . shell . copy_id ( ) <EOL> else : <EOL> stdout , stderr , retcode = single . run ( ) <EOL> if re_run : <EOL> target . pop ( '<STR_LIT>' ) <EOL> single = Single ( <EOL> self . opts , <EOL> self . opts [ '<STR_LIT>' ] , <EOL> host , <EOL> mods = self . mods , <EOL> fsclient = self . fsclient , <EOL> thin = self . thin , <EOL> ** target ) <EOL> stdout , stderr , retcode = single . cmd_block ( ) <EOL> try : <EOL> data = salt . utils . find_json ( stdout ) <EOL> return { host : data . get ( '<STR_LIT>' , data ) } <EOL> except Exception : <EOL> if stderr : <EOL> return { host : stderr } <EOL> return { host : '<STR_LIT>' } <EOL> if salt . defaults . exitcodes . EX_OK != retcode : <EOL> return { host : stderr } <EOL> return { host : stdout } <EOL> def handle_routine ( self , que , opts , host , target , mine = False ) : <EOL> '''<STR_LIT>''' <EOL> opts = copy . deepcopy ( opts ) <EOL> single = Single ( <EOL> opts , <EOL> opts [ '<STR_LIT>' ] , <EOL> host , <EOL> mods = self . mods , <EOL> fsclient = self . fsclient , <EOL> thin = self . thin , <EOL> mine = mine , <EOL> ** target ) <EOL> ret = { '<STR_LIT:id>' : single . id } <EOL> stdout , stderr , retcode = single . run ( ) <EOL> try : <EOL> data = salt . utils . find_json ( stdout ) <EOL> if len ( data ) < <NUM_LIT:2> and '<STR_LIT>' in data : <EOL> ret [ '<STR_LIT>' ] = data [ '<STR_LIT>' ] <EOL> else : <EOL> ret [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : stdout , <EOL> '<STR_LIT>' : stderr , <EOL> '<STR_LIT>' : retcode , <EOL> } <EOL> except Exception : <EOL> ret [ '<STR_LIT>' ] = { <EOL> '<STR_LIT>' : stdout , <EOL> '<STR_LIT>' : stderr , <EOL> '<STR_LIT>' : retcode , <EOL> } <EOL> que . put ( ret ) <EOL> def handle_ssh ( self , mine = False ) : <EOL> '''<STR_LIT>''' <EOL> que = multiprocessing . Queue ( ) <EOL> running = { } <EOL> target_iter = self . targets . __iter__ ( ) <EOL> returned = set ( ) <EOL> rets = set ( ) <EOL> init = False <EOL> if not self . targets : <EOL> raise salt . exceptions . SaltClientError ( '<STR_LIT>' ) <EOL> while True : <EOL> if len ( running ) < self . opts . get ( '<STR_LIT>' , <NUM_LIT> ) and not init : <EOL> try : <EOL> host = next ( target_iter ) <EOL> except StopIteration : <EOL> init = True <EOL> continue <EOL> for default in self . defaults : <EOL> if default not in self . targets [ host ] : <EOL> self . targets [ host ] [ default ] = self . defaults [ default ] <EOL> args = ( <EOL> que , <EOL> self . opts , <EOL> host , <EOL> self . targets [ host ] , <EOL> mine , <EOL> ) <EOL> routine = MultiprocessingProcess ( <EOL> target = self . handle_routine , <EOL> args = args ) <EOL> routine . start ( ) <EOL> running [ host ] = { '<STR_LIT>' : routine } <EOL> continue <EOL> ret = { } <EOL> try : <EOL> ret = que . get ( False ) <EOL> if '<STR_LIT:id>' in ret : <EOL> returned . add ( ret [ '<STR_LIT:id>' ] ) <EOL> yield { ret [ '<STR_LIT:id>' ] : ret [ '<STR_LIT>' ] } <EOL> except Exception : <EOL> pass <EOL> for host in running : <EOL> if not running [ host ] [ '<STR_LIT>' ] . is_alive ( ) : <EOL> if host not in returned : <EOL> try : <EOL> while True : <EOL> ret = que . get ( False ) <EOL> if '<STR_LIT:id>' in ret : <EOL> returned . add ( ret [ '<STR_LIT:id>' ] ) <EOL> yield { ret [ '<STR_LIT:id>' ] : ret [ '<STR_LIT>' ] } <EOL> except Exception : <EOL> pass <EOL> if host not in returned : <EOL> error = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( host ) <EOL> ret = { '<STR_LIT:id>' : host , <EOL> '<STR_LIT>' : error } <EOL> log . error ( error ) <EOL> yield { ret [ '<STR_LIT:id>' ] : ret [ '<STR_LIT>' ] } <EOL> running [ host ] [ '<STR_LIT>' ] . join ( ) <EOL> rets . add ( host ) <EOL> for host in rets : <EOL> if host in running : <EOL> running . pop ( host ) <EOL> if len ( rets ) >= len ( self . targets ) : <EOL> break <EOL> if len ( running ) >= self . opts . get ( '<STR_LIT>' , <NUM_LIT> ) or len ( self . targets ) >= len ( running ) : <EOL> time . sleep ( <NUM_LIT:0.1> ) <EOL> def run_iter ( self , mine = False , jid = None ) : <EOL> '''<STR_LIT>''' <EOL> fstr = '<STR_LIT>' . format ( self . opts [ '<STR_LIT>' ] ) <EOL> jid = self . returners [ fstr ] ( passed_jid = jid or self . opts . get ( '<STR_LIT>' , None ) ) <EOL> argv = self . opts [ '<STR_LIT>' ] <EOL> if self . opts . get ( '<STR_LIT>' , False ) : <EOL> fun = '<STR_LIT>' <EOL> args = argv <EOL> else : <EOL> fun = argv [ <NUM_LIT:0> ] if argv else '<STR_LIT>' <EOL> args = argv [ <NUM_LIT:1> : ] <EOL> job_load = { <EOL> '<STR_LIT>' : jid , <EOL> '<STR_LIT>' : self . tgt_type , <EOL> '<STR_LIT>' : self . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT:user>' : self . opts [ '<STR_LIT:user>' ] , <EOL> '<STR_LIT>' : fun , <EOL> '<STR_LIT>' : args , <EOL> } <EOL> self . returners [ '<STR_LIT>' . format ( self . opts [ '<STR_LIT>' ] ) ] ( jid , job_load ) <EOL> for ret in self . handle_ssh ( mine = mine ) : <EOL> host = next ( six . iterkeys ( ret ) ) <EOL> self . cache_job ( jid , host , ret [ host ] , fun ) <EOL> if self . event : <EOL> self . event . fire_event ( <EOL> ret , <EOL> salt . utils . event . tagify ( <EOL> [ jid , '<STR_LIT>' , host ] , <EOL> '<STR_LIT>' ) ) <EOL> yield ret <EOL> def cache_job ( self , jid , id_ , ret , fun ) : <EOL> '''<STR_LIT>''' <EOL> self . returners [ '<STR_LIT>' . format ( self . opts [ '<STR_LIT>' ] ) ] ( { '<STR_LIT>' : jid , <EOL> '<STR_LIT:id>' : id_ , <EOL> '<STR_LIT>' : ret , <EOL> '<STR_LIT>' : fun } ) <EOL> def run ( self , jid = None ) : <EOL> '''<STR_LIT>''' <EOL> fstr = '<STR_LIT>' . format ( self . opts [ '<STR_LIT>' ] ) <EOL> jid = self . returners [ fstr ] ( passed_jid = jid or self . opts . get ( '<STR_LIT>' , None ) ) <EOL> argv = self . opts [ '<STR_LIT>' ] <EOL> if self . opts . get ( '<STR_LIT>' , False ) : <EOL> fun = '<STR_LIT>' <EOL> args = argv <EOL> else : <EOL> fun = argv [ <NUM_LIT:0> ] if argv else '<STR_LIT>' <EOL> args = argv [ <NUM_LIT:1> : ] <EOL> job_load = { <EOL> '<STR_LIT>' : jid , <EOL> '<STR_LIT>' : self . tgt_type , <EOL> '<STR_LIT>' : self . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT:user>' : self . opts [ '<STR_LIT:user>' ] , <EOL> '<STR_LIT>' : fun , <EOL> '<STR_LIT>' : args , <EOL> } <EOL> try : <EOL> if isinstance ( jid , bytes ) : <EOL> jid = jid . decode ( '<STR_LIT:utf-8>' ) <EOL> if self . opts [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> self . returners [ '<STR_LIT>' . format ( self . opts [ '<STR_LIT>' ] ) ] ( jid , job_load , minions = self . targets . keys ( ) ) <EOL> else : <EOL> self . returners [ '<STR_LIT>' . format ( self . opts [ '<STR_LIT>' ] ) ] ( jid , job_load ) <EOL> except Exception as exc : <EOL> log . exception ( exc ) <EOL> log . error ( '<STR_LIT>' . format ( self . opts [ '<STR_LIT>' ] , exc ) ) <EOL> if self . opts . get ( '<STR_LIT>' ) : <EOL> msg = '<STR_LIT>' . format ( jid ) <EOL> print ( msg ) <EOL> print ( '<STR_LIT:->' * len ( msg ) + '<STR_LIT:\n>' ) <EOL> print ( '<STR_LIT>' ) <EOL> sret = { } <EOL> outputter = self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> final_exit = <NUM_LIT:0> <EOL> for ret in self . handle_ssh ( ) : <EOL> host = next ( six . iterkeys ( ret ) ) <EOL> if isinstance ( ret [ host ] , dict ) : <EOL> host_ret = ret [ host ] . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> if host_ret != <NUM_LIT:0> : <EOL> final_exit = <NUM_LIT:1> <EOL> else : <EOL> final_exit = <NUM_LIT:1> <EOL> self . cache_job ( jid , host , ret [ host ] , fun ) <EOL> ret = self . key_deploy ( host , ret ) <EOL> if isinstance ( ret [ host ] , dict ) and ret [ host ] . get ( '<STR_LIT>' , '<STR_LIT>' ) . startswith ( '<STR_LIT>' ) : <EOL> ret [ host ] = ret [ host ] [ '<STR_LIT>' ] <EOL> if not isinstance ( ret [ host ] , dict ) : <EOL> p_data = { host : ret [ host ] } <EOL> elif '<STR_LIT>' not in ret [ host ] : <EOL> p_data = ret <EOL> else : <EOL> outputter = ret [ host ] . get ( '<STR_LIT>' , self . opts . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> p_data = { host : ret [ host ] . get ( '<STR_LIT>' , { } ) } <EOL> if self . opts . get ( '<STR_LIT>' ) : <EOL> sret . update ( p_data ) <EOL> else : <EOL> salt . output . display_output ( <EOL> p_data , <EOL> outputter , <EOL> self . opts ) <EOL> if self . event : <EOL> self . event . fire_event ( <EOL> ret , <EOL> salt . utils . event . tagify ( <EOL> [ jid , '<STR_LIT>' , host ] , <EOL> '<STR_LIT>' ) ) <EOL> if self . opts . get ( '<STR_LIT>' ) : <EOL> salt . output . display_output ( <EOL> sret , <EOL> outputter , <EOL> self . opts ) <EOL> if final_exit : <EOL> sys . exit ( salt . defaults . exitcodes . EX_AGGREGATE ) <EOL> class Single ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( <EOL> self , <EOL> opts , <EOL> argv , <EOL> id_ , <EOL> host , <EOL> user = None , <EOL> port = None , <EOL> passwd = None , <EOL> priv = None , <EOL> timeout = <NUM_LIT:30> , <EOL> sudo = False , <EOL> tty = False , <EOL> mods = None , <EOL> fsclient = None , <EOL> thin = None , <EOL> mine = False , <EOL> minion_opts = None , <EOL> identities_only = False , <EOL> ** kwargs ) : <EOL> self . mine = mine <EOL> self . mine_functions = kwargs . get ( '<STR_LIT>' ) <EOL> self . cmd_umask = kwargs . get ( '<STR_LIT>' , None ) <EOL> self . opts = opts <EOL> self . tty = tty <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> self . wipe = '<STR_LIT:False>' <EOL> else : <EOL> if self . opts . get ( '<STR_LIT>' ) : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> self . wipe = '<STR_LIT:True>' <EOL> self . wipe = '<STR_LIT:True>' if self . opts . get ( '<STR_LIT>' ) else '<STR_LIT:False>' <EOL> if kwargs . get ( '<STR_LIT>' ) : <EOL> self . thin_dir = kwargs [ '<STR_LIT>' ] <EOL> else : <EOL> if user : <EOL> thin_dir = DEFAULT_THIN_DIR . replace ( '<STR_LIT>' , user ) <EOL> else : <EOL> thin_dir = DEFAULT_THIN_DIR . replace ( '<STR_LIT>' , '<STR_LIT:root>' ) <EOL> self . thin_dir = thin_dir . replace ( <EOL> '<STR_LIT>' , <EOL> uuid . uuid3 ( uuid . NAMESPACE_DNS , <EOL> salt . utils . network . get_fqhostname ( ) ) . hex [ : <NUM_LIT:6> ] <EOL> ) <EOL> self . opts [ '<STR_LIT>' ] = self . thin_dir <EOL> self . fsclient = fsclient <EOL> self . context = { '<STR_LIT>' : self . opts , <EOL> '<STR_LIT>' : self . fsclient } <EOL> if isinstance ( argv , six . string_types ) : <EOL> self . argv = [ argv ] <EOL> else : <EOL> self . argv = argv <EOL> self . fun , self . args , self . kwargs = self . __arg_comps ( ) <EOL> self . id = id_ <EOL> self . mods = mods if isinstance ( mods , dict ) else { } <EOL> args = { '<STR_LIT:host>' : host , <EOL> '<STR_LIT:user>' : user , <EOL> '<STR_LIT:port>' : port , <EOL> '<STR_LIT>' : passwd , <EOL> '<STR_LIT>' : priv , <EOL> '<STR_LIT>' : timeout , <EOL> '<STR_LIT>' : sudo , <EOL> '<STR_LIT>' : tty , <EOL> '<STR_LIT>' : self . mods , <EOL> '<STR_LIT>' : identities_only } <EOL> self . minion_opts = { <EOL> '<STR_LIT>' : True , <EOL> } <EOL> self . minion_opts . update ( opts . get ( '<STR_LIT>' , { } ) ) <EOL> if minion_opts is not None : <EOL> self . minion_opts . update ( minion_opts ) <EOL> self . minion_opts . update ( { <EOL> '<STR_LIT>' : os . path . join ( self . thin_dir , '<STR_LIT>' ) , <EOL> '<STR_LIT:id>' : self . id , <EOL> '<STR_LIT>' : '<STR_LIT:/>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } ) <EOL> self . minion_config = salt . serializers . yaml . serialize ( self . minion_opts ) <EOL> self . target = kwargs <EOL> self . target . update ( args ) <EOL> self . serial = salt . payload . Serial ( opts ) <EOL> self . wfuncs = salt . loader . ssh_wrapper ( opts , None , self . context ) <EOL> self . shell = salt . client . ssh . shell . Shell ( opts , ** args ) <EOL> self . thin = thin if thin else salt . utils . thin . thin_path ( opts [ '<STR_LIT>' ] ) <EOL> def __arg_comps ( self ) : <EOL> '''<STR_LIT>''' <EOL> fun = self . argv [ <NUM_LIT:0> ] if self . argv else '<STR_LIT>' <EOL> parsed = salt . utils . args . parse_input ( self . argv [ <NUM_LIT:1> : ] , condition = False ) <EOL> args = parsed [ <NUM_LIT:0> ] <EOL> kws = parsed [ <NUM_LIT:1> ] <EOL> return fun , args , kws <EOL> def _escape_arg ( self , arg ) : <EOL> '''<STR_LIT>''' <EOL> return '<STR_LIT>' . join ( [ '<STR_LIT:\\>' + char if re . match ( r'<STR_LIT>' , char ) else char for char in arg ] ) <EOL> def deploy ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . shell . send ( <EOL> self . thin , <EOL> os . path . join ( self . thin_dir , '<STR_LIT>' ) , <EOL> ) <EOL> self . deploy_ext ( ) <EOL> return True <EOL> def deploy_ext ( self ) : <EOL> '''<STR_LIT>''' <EOL> if self . mods . get ( '<STR_LIT:file>' ) : <EOL> self . shell . send ( <EOL> self . mods [ '<STR_LIT:file>' ] , <EOL> os . path . join ( self . thin_dir , '<STR_LIT>' ) , <EOL> ) <EOL> return True <EOL> def run ( self , deploy_attempted = False ) : <EOL> '''<STR_LIT>''' <EOL> stdout = stderr = retcode = None <EOL> if self . opts . get ( '<STR_LIT>' , False ) : <EOL> cmd_str = '<STR_LIT:U+0020>' . join ( [ self . _escape_arg ( arg ) for arg in self . argv ] ) <EOL> stdout , stderr , retcode = self . shell . exec_cmd ( cmd_str ) <EOL> elif self . fun in self . wfuncs or self . mine : <EOL> stdout , retcode = self . run_wfunc ( ) <EOL> else : <EOL> stdout , stderr , retcode = self . cmd_block ( ) <EOL> return stdout , stderr , retcode <EOL> def run_wfunc ( self ) : <EOL> '''<STR_LIT>''' <EOL> data_cache = False <EOL> data = None <EOL> cdir = os . path . join ( self . opts [ '<STR_LIT>' ] , '<STR_LIT>' , self . id ) <EOL> if not os . path . isdir ( cdir ) : <EOL> os . makedirs ( cdir ) <EOL> datap = os . path . join ( cdir , '<STR_LIT>' ) <EOL> refresh = False <EOL> if not os . path . isfile ( datap ) : <EOL> refresh = True <EOL> else : <EOL> passed_time = ( time . time ( ) - os . stat ( datap ) . st_mtime ) / <NUM_LIT> <EOL> if passed_time > self . opts . get ( '<STR_LIT>' , <NUM_LIT> ) : <EOL> refresh = True <EOL> if self . opts . get ( '<STR_LIT>' ) : <EOL> refresh = True <EOL> conf_grains = { } <EOL> if '<STR_LIT>' in self . opts : <EOL> conf_grains = self . opts [ '<STR_LIT>' ] <EOL> if not data_cache : <EOL> refresh = True <EOL> if refresh : <EOL> pre_wrapper = salt . client . ssh . wrapper . FunctionWrapper ( <EOL> self . opts , <EOL> self . id , <EOL> fsclient = self . fsclient , <EOL> minion_opts = self . minion_opts , <EOL> ** self . target ) <EOL> opts_pkg = pre_wrapper [ '<STR_LIT>' ] ( ) <EOL> opts_pkg [ '<STR_LIT>' ] = self . opts [ '<STR_LIT>' ] <EOL> opts_pkg [ '<STR_LIT>' ] = self . opts [ '<STR_LIT>' ] <EOL> opts_pkg [ '<STR_LIT>' ] = self . opts [ '<STR_LIT>' ] <EOL> opts_pkg [ '<STR_LIT>' ] = self . opts [ '<STR_LIT>' ] <EOL> opts_pkg [ '<STR_LIT>' ] = self . opts [ '<STR_LIT>' ] <EOL> opts_pkg [ '<STR_LIT>' ] = self . context [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in self . opts : <EOL> opts_pkg [ '<STR_LIT>' ] = self . opts [ '<STR_LIT>' ] <EOL> else : <EOL> opts_pkg [ '<STR_LIT>' ] = self . opts [ '<STR_LIT>' ] <EOL> opts_pkg [ '<STR_LIT:id>' ] = self . id <EOL> retcode = <NUM_LIT:0> <EOL> if '<STR_LIT>' in opts_pkg : <EOL> retcode = opts_pkg [ '<STR_LIT>' ] <EOL> ret = json . dumps ( { '<STR_LIT>' : opts_pkg [ '<STR_LIT>' ] } ) <EOL> return ret , retcode <EOL> pillar = salt . pillar . Pillar ( <EOL> opts_pkg , <EOL> opts_pkg [ '<STR_LIT>' ] , <EOL> opts_pkg [ '<STR_LIT:id>' ] , <EOL> opts_pkg . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> pillar_dirs = { } <EOL> pillar_data = pillar . compile_pillar ( pillar_dirs = pillar_dirs ) <EOL> data = { '<STR_LIT>' : opts_pkg , <EOL> '<STR_LIT>' : opts_pkg [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : pillar_data } <EOL> if data_cache : <EOL> with salt . utils . fopen ( datap , '<STR_LIT>' ) as fp_ : <EOL> fp_ . write ( <EOL> self . serial . dumps ( data ) <EOL> ) <EOL> if not data and data_cache : <EOL> with salt . utils . fopen ( datap , '<STR_LIT:rb>' ) as fp_ : <EOL> data = self . serial . load ( fp_ ) <EOL> opts = data . get ( '<STR_LIT>' , { } ) <EOL> opts [ '<STR_LIT>' ] = data . get ( '<STR_LIT>' ) <EOL> for grain in conf_grains : <EOL> opts [ '<STR_LIT>' ] [ grain ] = conf_grains [ grain ] <EOL> if '<STR_LIT>' in self . target : <EOL> for grain in self . target [ '<STR_LIT>' ] : <EOL> opts [ '<STR_LIT>' ] [ grain ] = self . target [ '<STR_LIT>' ] [ grain ] <EOL> opts [ '<STR_LIT>' ] = data . get ( '<STR_LIT>' ) <EOL> wrapper = salt . client . ssh . wrapper . FunctionWrapper ( <EOL> opts , <EOL> self . id , <EOL> fsclient = self . fsclient , <EOL> minion_opts = self . minion_opts , <EOL> ** self . target ) <EOL> self . wfuncs = salt . loader . ssh_wrapper ( opts , wrapper , self . context ) <EOL> wrapper . wfuncs = self . wfuncs <EOL> if self . mine : <EOL> mine_args = None <EOL> if self . mine_functions and self . fun in self . mine_functions : <EOL> mine_args = self . mine_functions [ self . fun ] <EOL> elif opts [ '<STR_LIT>' ] and self . fun in opts [ '<STR_LIT>' ] . get ( '<STR_LIT>' , { } ) : <EOL> mine_args = opts [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ self . fun ] <EOL> elif self . fun in self . context [ '<STR_LIT>' ] . get ( '<STR_LIT>' , { } ) : <EOL> mine_args = self . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ self . fun ] <EOL> if isinstance ( mine_args , dict ) : <EOL> self . args = [ ] <EOL> self . kwargs = mine_args <EOL> elif isinstance ( mine_args , list ) : <EOL> self . args = mine_args <EOL> self . kwargs = { } <EOL> try : <EOL> if self . mine : <EOL> result = wrapper [ self . fun ] ( * self . args , ** self . kwargs ) <EOL> else : <EOL> result = self . wfuncs [ self . fun ] ( * self . args , ** self . kwargs ) <EOL> except TypeError as exc : <EOL> result = '<STR_LIT>' . format ( self . fun , exc ) <EOL> log . error ( result , exc_info_on_loglevel = logging . DEBUG ) <EOL> retcode = <NUM_LIT:1> <EOL> except Exception as exc : <EOL> result = '<STR_LIT>' . format ( self . fun , exc ) <EOL> log . error ( result , exc_info_on_loglevel = logging . DEBUG ) <EOL> retcode = <NUM_LIT:1> <EOL> if isinstance ( result , dict ) and '<STR_LIT>' in result : <EOL> ret = json . dumps ( { '<STR_LIT>' : result [ '<STR_LIT>' ] } ) <EOL> else : <EOL> ret = json . dumps ( { '<STR_LIT>' : { '<STR_LIT>' : result } } ) <EOL> return ret , retcode <EOL> def _cmd_str ( self ) : <EOL> '''<STR_LIT>''' <EOL> sudo = '<STR_LIT>' if self . target [ '<STR_LIT>' ] else '<STR_LIT>' <EOL> if '<STR_LIT>' in self . opts : <EOL> cachedir = self . opts [ '<STR_LIT>' ] <EOL> else : <EOL> cachedir = self . opts [ '<STR_LIT>' ] <EOL> thin_sum = salt . utils . thin . thin_sum ( cachedir , '<STR_LIT>' ) <EOL> debug = '<STR_LIT>' <EOL> if not self . opts . get ( '<STR_LIT>' ) : <EOL> self . opts [ '<STR_LIT>' ] = '<STR_LIT:info>' <EOL> if salt . log . LOG_LEVELS [ '<STR_LIT>' ] >= salt . log . LOG_LEVELS [ self . opts . get ( '<STR_LIT>' , '<STR_LIT:info>' ) ] : <EOL> debug = '<STR_LIT:1>' <EOL> arg_str = '''<STR_LIT>''' . format ( self . minion_config , <EOL> RSTR , <EOL> self . thin_dir , <EOL> thin_sum , <EOL> '<STR_LIT>' , <EOL> salt . version . __version__ , <EOL> self . mods . get ( '<STR_LIT:version>' , '<STR_LIT>' ) , <EOL> self . wipe , <EOL> self . tty , <EOL> self . cmd_umask , <EOL> self . argv ) <EOL> py_code = SSH_PY_SHIM . replace ( '<STR_LIT>' , arg_str ) <EOL> if six . PY2 : <EOL> py_code_enc = py_code . encode ( '<STR_LIT>' ) <EOL> else : <EOL> py_code_enc = base64 . encodebytes ( py_code . encode ( '<STR_LIT:utf-8>' ) ) . decode ( '<STR_LIT:utf-8>' ) <EOL> cmd = SSH_SH_SHIM . format ( <EOL> DEBUG = debug , <EOL> SUDO = sudo , <EOL> SSH_PY_CODE = py_code_enc , <EOL> HOST_PY_MAJOR = sys . version_info [ <NUM_LIT:0> ] , <EOL> ) <EOL> return cmd <EOL> def shim_cmd ( self , cmd_str ) : <EOL> '''<STR_LIT>''' <EOL> if not self . tty : <EOL> return self . shell . exec_cmd ( cmd_str ) <EOL> with tempfile . NamedTemporaryFile ( mode = '<STR_LIT:w>' , <EOL> prefix = '<STR_LIT>' , <EOL> delete = False ) as shim_tmp_file : <EOL> shim_tmp_file . write ( cmd_str ) <EOL> target_shim_file = '<STR_LIT>' . format ( binascii . hexlify ( os . urandom ( <NUM_LIT:6> ) ) ) <EOL> self . shell . send ( shim_tmp_file . name , target_shim_file ) <EOL> try : <EOL> os . remove ( shim_tmp_file . name ) <EOL> except IOError : <EOL> pass <EOL> ret = self . shell . exec_cmd ( '<STR_LIT>' . format ( target_shim_file ) ) <EOL> self . shell . exec_cmd ( '<STR_LIT>' . format ( target_shim_file ) ) <EOL> return ret <EOL> def cmd_block ( self , is_retry = False ) : <EOL> '''<STR_LIT>''' <EOL> self . argv = _convert_args ( self . argv ) <EOL> log . debug ( '<STR_LIT>' . format ( '<STR_LIT:U+0020>' . join ( self . argv ) ) ) <EOL> cmd_str = self . _cmd_str ( ) <EOL> stdout , stderr , retcode = self . shim_cmd ( cmd_str ) <EOL> log . trace ( '<STR_LIT>' . format ( stdout , self . target [ '<STR_LIT:host>' ] ) ) <EOL> log . trace ( '<STR_LIT>' . format ( stderr , self . target [ '<STR_LIT:host>' ] ) ) <EOL> log . debug ( '<STR_LIT>' . format ( retcode , self . target [ '<STR_LIT:host>' ] ) ) <EOL> error = self . categorize_shim_errors ( stdout , stderr , retcode ) <EOL> if error : <EOL> if error == '<STR_LIT>' : <EOL> self . deploy ( ) <EOL> stdout , stderr , retcode = self . shim_cmd ( cmd_str ) <EOL> if not re . search ( RSTR_RE , stdout ) or not re . search ( RSTR_RE , stderr ) : <EOL> return '<STR_LIT>' . format ( stdout ) , stderr , retcode <EOL> while re . search ( RSTR_RE , stdout ) : <EOL> stdout = re . split ( RSTR_RE , stdout , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> while re . search ( RSTR_RE , stderr ) : <EOL> stderr = re . split ( RSTR_RE , stderr , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> else : <EOL> return '<STR_LIT>' . format ( error ) , stderr , retcode <EOL> while re . search ( RSTR_RE , stdout ) : <EOL> stdout = re . split ( RSTR_RE , stdout , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> if re . search ( RSTR_RE , stderr ) : <EOL> while re . search ( RSTR_RE , stderr ) : <EOL> stderr = re . split ( RSTR_RE , stderr , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> else : <EOL> shim_command = re . split ( r'<STR_LIT>' , stdout , <NUM_LIT:1> ) [ <NUM_LIT:0> ] . strip ( ) <EOL> log . debug ( '<STR_LIT>' . format ( retcode , shim_command ) ) <EOL> if '<STR_LIT>' == shim_command and retcode == salt . defaults . exitcodes . EX_THIN_DEPLOY : <EOL> self . deploy ( ) <EOL> stdout , stderr , retcode = self . shim_cmd ( cmd_str ) <EOL> if not re . search ( RSTR_RE , stdout ) or not re . search ( RSTR_RE , stderr ) : <EOL> if not self . tty : <EOL> return '<STR_LIT>' . format ( stdout , stderr ) , stderr , retcode <EOL> elif not re . search ( RSTR_RE , stdout ) : <EOL> return '<STR_LIT>' . format ( stdout , stderr ) , stderr , retcode <EOL> while re . search ( RSTR_RE , stdout ) : <EOL> stdout = re . split ( RSTR_RE , stdout , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> if self . tty : <EOL> stderr = '<STR_LIT>' <EOL> else : <EOL> while re . search ( RSTR_RE , stderr ) : <EOL> stderr = re . split ( RSTR_RE , stderr , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> elif '<STR_LIT>' == shim_command : <EOL> self . deploy_ext ( ) <EOL> stdout , stderr , retcode = self . shim_cmd ( cmd_str ) <EOL> if not re . search ( RSTR_RE , stdout ) or not re . search ( RSTR_RE , stderr ) : <EOL> return '<STR_LIT>' . format ( stdout ) , stderr , retcode <EOL> while re . search ( RSTR_RE , stdout ) : <EOL> stdout = re . split ( RSTR_RE , stdout , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> while re . search ( RSTR_RE , stderr ) : <EOL> stderr = re . split ( RSTR_RE , stderr , <NUM_LIT:1> ) [ <NUM_LIT:1> ] . strip ( ) <EOL> return stdout , stderr , retcode <EOL> def categorize_shim_errors ( self , stdout , stderr , retcode ) : <EOL> if re . search ( RSTR_RE , stdout ) and stdout != RSTR + '<STR_LIT:\n>' : <EOL> return None <EOL> if re . search ( RSTR_RE , stderr ) : <EOL> return '<STR_LIT>' <EOL> if stderr . startswith ( '<STR_LIT>' ) : <EOL> return None <EOL> perm_error_fmt = '<STR_LIT>' '<STR_LIT>' <EOL> errors = [ <EOL> ( <EOL> ( ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , <EOL> ( <EOL> ( salt . defaults . exitcodes . EX_THIN_PYTHON_INVALID , ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , <EOL> ( <EOL> ( salt . defaults . exitcodes . EX_THIN_CHECKSUM , ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , <EOL> ( <EOL> ( salt . defaults . exitcodes . EX_SCP_NOT_FOUND , ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , <EOL> ( <EOL> ( salt . defaults . exitcodes . EX_CANTCREAT , ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + stderr , <EOL> ) , <EOL> ( <EOL> ( ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) , <EOL> ( <EOL> ( ) , <EOL> '<STR_LIT>' , <EOL> perm_error_fmt . format ( stderr ) <EOL> ) , <EOL> ( <EOL> ( ) , <EOL> '<STR_LIT>' , <EOL> perm_error_fmt . format ( stderr ) <EOL> ) , <EOL> ( <EOL> ( ) , <EOL> '<STR_LIT>' , <EOL> perm_error_fmt . format ( stderr ) <EOL> ) , <EOL> ( <EOL> ( salt . defaults . exitcodes . EX_SOFTWARE , ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + stderr , <EOL> ) , <EOL> ] <EOL> for error in errors : <EOL> if retcode in error [ <NUM_LIT:0> ] or re . search ( error [ <NUM_LIT:1> ] , stderr ) : <EOL> return error [ <NUM_LIT:2> ] <EOL> return None <EOL> def check_refresh ( self , data , ret ) : <EOL> '''<STR_LIT>''' <EOL> return <EOL> def module_refresh ( self ) : <EOL> '''<STR_LIT>''' <EOL> return <EOL> def lowstate_file_refs ( chunks ) : <EOL> '''<STR_LIT>''' <EOL> refs = { } <EOL> for chunk in chunks : <EOL> saltenv = '<STR_LIT>' <EOL> crefs = [ ] <EOL> for state in chunk : <EOL> if state == '<STR_LIT>' : <EOL> saltenv = chunk [ state ] <EOL> elif state == '<STR_LIT>' : <EOL> saltenv = chunk [ state ] <EOL> elif state . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> crefs . extend ( salt_refs ( chunk [ state ] ) ) <EOL> if crefs : <EOL> if saltenv not in refs : <EOL> refs [ saltenv ] = [ ] <EOL> refs [ saltenv ] . append ( crefs ) <EOL> return refs <EOL> def salt_refs ( data ) : <EOL> '''<STR_LIT>''' <EOL> proto = '<STR_LIT>' <EOL> ret = [ ] <EOL> if isinstance ( data , str ) : <EOL> if data . startswith ( proto ) : <EOL> return [ data ] <EOL> if isinstance ( data , list ) : <EOL> for comp in data : <EOL> if isinstance ( comp , str ) : <EOL> if comp . startswith ( proto ) : <EOL> ret . append ( comp ) <EOL> return ret <EOL> def mod_data ( fsclient ) : <EOL> '''<STR_LIT>''' <EOL> sync_refs = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> ret = { } <EOL> envs = fsclient . envs ( ) <EOL> ver_base = '<STR_LIT>' <EOL> for env in envs : <EOL> files = fsclient . file_list ( env ) <EOL> for ref in sync_refs : <EOL> mods_data = { } <EOL> pref = '<STR_LIT>' . format ( ref ) <EOL> for fn_ in sorted ( files ) : <EOL> if fn_ . startswith ( pref ) : <EOL> if fn_ . endswith ( ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> full = salt . utils . url . create ( fn_ ) <EOL> mod_path = fsclient . cache_file ( full , env ) <EOL> if not os . path . isfile ( mod_path ) : <EOL> continue <EOL> mods_data [ os . path . basename ( fn_ ) ] = mod_path <EOL> chunk = salt . utils . get_hash ( mod_path ) <EOL> ver_base += chunk <EOL> if mods_data : <EOL> if ref in ret : <EOL> ret [ ref ] . update ( mods_data ) <EOL> else : <EOL> ret [ ref ] = mods_data <EOL> if not ret : <EOL> return { } <EOL> ver = hashlib . sha1 ( ver_base ) . hexdigest ( ) <EOL> ext_tar_path = os . path . join ( <EOL> fsclient . opts [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' . format ( ver ) ) <EOL> mods = { '<STR_LIT:version>' : ver , <EOL> '<STR_LIT:file>' : ext_tar_path } <EOL> if os . path . isfile ( ext_tar_path ) : <EOL> return mods <EOL> tfp = tarfile . open ( ext_tar_path , '<STR_LIT>' ) <EOL> verfile = os . path . join ( fsclient . opts [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> with salt . utils . fopen ( verfile , '<STR_LIT>' ) as fp_ : <EOL> fp_ . write ( ver ) <EOL> tfp . add ( verfile , '<STR_LIT>' ) <EOL> for ref in ret : <EOL> for fn_ in ret [ ref ] : <EOL> tfp . add ( ret [ ref ] [ fn_ ] , os . path . join ( ref , fn_ ) ) <EOL> tfp . close ( ) <EOL> return mods <EOL> def ssh_version ( ) : <EOL> '''<STR_LIT>''' <EOL> ret = subprocess . Popen ( <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE ) . communicate ( ) <EOL> try : <EOL> version_parts = ret [ <NUM_LIT:1> ] . split ( b'<STR_LIT:U+002C>' ) [ <NUM_LIT:0> ] . split ( b'<STR_LIT:_>' ) [ <NUM_LIT:1> ] <EOL> parts = [ ] <EOL> for part in version_parts : <EOL> try : <EOL> parts . append ( int ( part ) ) <EOL> except ValueError : <EOL> return tuple ( parts ) <EOL> return tuple ( parts ) <EOL> except IndexError : <EOL> return ( <NUM_LIT:2> , <NUM_LIT:0> ) <EOL> def _convert_args ( args ) : <EOL> '''<STR_LIT>''' <EOL> converted = [ ] <EOL> for arg in args : <EOL> if isinstance ( arg , dict ) : <EOL> for key in list ( arg . keys ( ) ) : <EOL> if key == '<STR_LIT>' : <EOL> continue <EOL> converted . append ( '<STR_LIT>' . format ( key , arg [ key ] ) ) <EOL> else : <EOL> converted . append ( arg ) <EOL> return converted </s>
