<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import , print_function <EOL> import os <EOL> import salt . ext . six as six <EOL> try : <EOL> import msgpack <EOL> except ImportError : <EOL> import msgpack_pure as msgpack <EOL> from salt . exceptions import CommandExecutionError , SaltRenderError <EOL> import salt . utils <EOL> import salt . utils . gitfs <EOL> import logging <EOL> import salt . minion <EOL> import salt . loader <EOL> import salt . template <EOL> log = logging . getLogger ( __name__ ) <EOL> PER_REMOTE_OVERRIDES = ( '<STR_LIT>' , ) <EOL> def genrepo ( opts = None , fire_event = True ) : <EOL> '''<STR_LIT>''' <EOL> if opts is None : <EOL> opts = __opts__ <EOL> if '<STR_LIT>' in opts : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> winrepo_dir = opts [ '<STR_LIT>' ] <EOL> else : <EOL> winrepo_dir = opts [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in opts : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> winrepo_cachefile = opts [ '<STR_LIT>' ] <EOL> else : <EOL> winrepo_cachefile = opts [ '<STR_LIT>' ] <EOL> ret = { } <EOL> if not os . path . exists ( winrepo_dir ) : <EOL> os . makedirs ( winrepo_dir ) <EOL> renderers = salt . loader . render ( opts , __salt__ ) <EOL> for root , _ , files in os . walk ( winrepo_dir ) : <EOL> for name in files : <EOL> if name . endswith ( '<STR_LIT>' ) : <EOL> try : <EOL> config = salt . template . compile_template ( <EOL> os . path . join ( root , name ) , <EOL> renderers , <EOL> opts [ '<STR_LIT>' ] ) <EOL> except SaltRenderError as exc : <EOL> log . debug ( <EOL> '<STR_LIT>' . format ( <EOL> os . path . join ( root , name ) <EOL> ) <EOL> ) <EOL> log . debug ( '<STR_LIT>' . format ( exc ) ) <EOL> continue <EOL> if config : <EOL> revmap = { } <EOL> for pkgname , versions in six . iteritems ( config ) : <EOL> log . debug ( <EOL> '<STR_LIT>' <EOL> . format ( pkgname ) <EOL> ) <EOL> for version , repodata in six . iteritems ( versions ) : <EOL> log . debug ( <EOL> '<STR_LIT>' <EOL> . format ( pkgname , version ) <EOL> ) <EOL> if not isinstance ( version , six . string_types ) : <EOL> config [ pkgname ] [ str ( version ) ] = config [ pkgname ] . pop ( version ) <EOL> if not isinstance ( repodata , dict ) : <EOL> log . debug ( <EOL> '<STR_LIT>' . format ( <EOL> os . path . join ( root , name ) <EOL> ) <EOL> ) <EOL> if fire_event : <EOL> msg = '<STR_LIT>' . format ( <EOL> os . path . join ( root , name ) <EOL> ) <EOL> try : <EOL> __jid_event__ . fire_event ( <EOL> { '<STR_LIT:error>' : msg } , <EOL> '<STR_LIT>' <EOL> ) <EOL> except NameError : <EOL> log . error ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( msg ) <EOL> ) <EOL> continue <EOL> revmap [ repodata [ '<STR_LIT>' ] ] = pkgname <EOL> ret . setdefault ( '<STR_LIT>' , { } ) . update ( config ) <EOL> ret . setdefault ( '<STR_LIT>' , { } ) . update ( revmap ) <EOL> with salt . utils . fopen ( <EOL> os . path . join ( winrepo_dir , winrepo_cachefile ) , '<STR_LIT>' ) as repo : <EOL> repo . write ( msgpack . dumps ( ret ) ) <EOL> return ret <EOL> def update_git_repos ( opts = None , clean = False , masterless = False ) : <EOL> '''<STR_LIT>''' <EOL> if opts is None : <EOL> opts = __opts__ <EOL> if '<STR_LIT>' in opts : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> winrepo_dir = opts [ '<STR_LIT>' ] <EOL> else : <EOL> winrepo_dir = opts [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in opts : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> winrepo_remotes = opts [ '<STR_LIT>' ] <EOL> else : <EOL> winrepo_remotes = opts [ '<STR_LIT>' ] <EOL> winrepo_cfg = [ ( winrepo_remotes , winrepo_dir ) , <EOL> ( opts [ '<STR_LIT>' ] , opts [ '<STR_LIT>' ] ) ] <EOL> ret = { } <EOL> for remotes , base_dir in winrepo_cfg : <EOL> if not any ( ( salt . utils . gitfs . HAS_GITPYTHON , salt . utils . gitfs . HAS_PYGIT2 ) ) : <EOL> if not salt . utils . is_windows ( ) : <EOL> salt . utils . warn_until ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> salt . utils . gitfs . GITPYTHON_MINVER , <EOL> salt . utils . gitfs . PYGIT2_MINVER , <EOL> salt . utils . gitfs . LIBGIT2_MINVER , <EOL> base_dir <EOL> ) <EOL> ) <EOL> winrepo_result = { } <EOL> for remote_info in remotes : <EOL> if '<STR_LIT:/>' in remote_info : <EOL> targetname = remote_info . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> else : <EOL> targetname = remote_info <EOL> rev = '<STR_LIT>' <EOL> try : <EOL> rev , remote_url = remote_info . strip ( ) . split ( ) <EOL> except ValueError : <EOL> remote_url = remote_info <EOL> gittarget = os . path . join ( base_dir , targetname ) . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) <EOL> if masterless : <EOL> result = __salt__ [ '<STR_LIT>' ] ( '<STR_LIT>' , <EOL> name = remote_url , <EOL> rev = rev , <EOL> branch = '<STR_LIT>' , <EOL> target = gittarget , <EOL> force_checkout = True , <EOL> force_reset = True ) <EOL> if isinstance ( result , list ) : <EOL> raise CommandExecutionError ( <EOL> '<STR_LIT>' . format ( <EOL> '<STR_LIT:\n>' . join ( result ) <EOL> ) <EOL> ) <EOL> if '<STR_LIT:name>' not in result : <EOL> key = next ( iter ( result ) ) <EOL> result = result [ key ] <EOL> else : <EOL> mminion = salt . minion . MasterMinion ( opts ) <EOL> result = mminion . states [ '<STR_LIT>' ] ( remote_url , <EOL> rev = rev , <EOL> branch = '<STR_LIT>' , <EOL> target = gittarget , <EOL> force_checkout = True , <EOL> force_reset = True ) <EOL> winrepo_result [ result [ '<STR_LIT:name>' ] ] = result [ '<STR_LIT:result>' ] <EOL> ret . update ( winrepo_result ) <EOL> else : <EOL> try : <EOL> winrepo = salt . utils . gitfs . WinRepo ( opts , base_dir ) <EOL> winrepo . init_remotes ( remotes , PER_REMOTE_OVERRIDES ) <EOL> winrepo . fetch_remotes ( ) <EOL> if clean : <EOL> winrepo . clear_old_remotes ( ) <EOL> winrepo . checkout ( ) <EOL> except Exception as exc : <EOL> msg = '<STR_LIT>' . format ( exc ) <EOL> log . error ( msg , exc_info_on_loglevel = logging . DEBUG ) <EOL> return msg <EOL> ret . update ( winrepo . winrepo_dirs ) <EOL> return ret </s>
