def _update_repo(ret, target, clean, user, rev, opts): """ Update the repo to a given revision. Using clean passes -C to the hg up """ log.debug("target {0} is found, " '"hg pull && hg up is probably required"'.format(target)) current_rev = __salt__["hg.revision"](target, user=user) if not current_rev: return _fail(ret, "Seems that {0} is not a valid hg repo".format(target)) if __opts__["test"]: test_result = ("Repository {0} update is probably required (current " "revision is {1})").format( target, current_rev ) return _neutral_test(ret, test_result) pull_out = __salt__["hg.pull"](target, user=user, opts=opts) if rev: __salt__["hg.update"](target, rev, force=clean, user=user) else: __salt__["hg.update"](target, "tip", force=clean, user=user) new_rev = __salt__["hg.revision"](cwd=target, user=user) if current_rev != new_rev: revision_text = "{0} => {1}".format(current_rev, new_rev) log.info("Repository {0} updated: {1}".format(target, revision_text)) ret["comment"] = "Repository {0} updated.".format(target) ret["changes"]["revision"] = revision_text elif "error:" in pull_out: return _fail(ret, "An error was thrown by hg:\n{0}".format(pull_out)) return ret
def _update_repo(ret, target, clean, user, rev, opts): ''' Update the repo to a given revision. Using clean passes -C to the hg up ''' log.debug('target {0} is found, ' '"hg pull && hg up is probably required"'.format(target)) current_rev = __salt__['hg.revision'](target, user=user) if not current_rev: return _fail(ret, 'Seems that {0} is not a valid hg repo'.format(target)) if __opts__['test']: test_result = ('Repository {0} update is probably required (current ' 'revision is {1})').format(target, current_rev) return _neutral_test(ret, test_result) pull_out = __salt__['hg.pull'](target, user=user, opts=opts) if rev: __salt__['hg.update'](target, rev, force=clean, user=user) else: __salt__['hg.update'](target, 'tip', force=clean, user=user) new_rev = __salt__['hg.revision'](cwd=target, user=user) if current_rev != new_rev: revision_text = '{0} => {1}'.format(current_rev, new_rev) log.info('Repository {0} updated: {1}'.format(target, revision_text)) ret['comment'] = 'Repository {0} updated.'.format(target) ret['changes']['revision'] = revision_text elif 'error:' in pull_out: return _fail(ret, 'An error was thrown by hg:\n{0}'.format(pull_out)) return ret
def _clone_repo(ret, target, name, user, identity, rev, opts): try: result = __salt__['hg.clone'](target, name, user=user, identity=identity, opts=opts) except CommandExecutionError as err: ret['result'] = False ret['comment'] = err return ret if not os.path.isdir(target): return _fail(ret, result) if rev: try: __salt__['hg.update'](target, rev, user=user) except CommandExecutionError as err: ret['result'] = False ret['comment'] = err return ret new_rev = __salt__['hg.revision'](cwd=target, user=user) message = 'Repository {0} cloned to {1}'.format(name, target) log.info(message) ret['comment'] = message ret['changes']['new'] = name ret['changes']['revision'] = new_rev return ret
def _clone_repo(ret, target, name, user, identity, rev, opts): try: result = __salt__["hg.clone"](target, name, user=user, identity=identity, opts=opts) except CommandExecutionError as err: ret["result"] = False ret["comment"] = err return ret if not os.path.isdir(target): return _fail(ret, result) if rev: try: __salt__["hg.update"](target, rev, user=user) except CommandExecutionError as err: ret["result"] = False ret["comment"] = err return ret new_rev = __salt__["hg.revision"](cwd=target, user=user) message = "Repository {} cloned to {}".format(name, target) log.info(message) ret["comment"] = message ret["changes"]["new"] = name ret["changes"]["revision"] = new_rev return ret
def latest(name, rev=None, target=None, clean=False, user=None, force=False, opts=False): ''' Make sure the repository is cloned to the given directory and is up to date name Address of the remote repository as passed to "hg clone" rev The remote branch, tag, or revision hash to clone/pull target Name of the target directory where repository is about to be cloned clean Force a clean update with -C (Default: False) user Name of the user performing repository management operations .. versionadded: 0.17.0 force Force hg to clone into pre-existing directories (deletes contents) opts Include additional arguments and options to the hg command line ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, '"target option is required') is_repository = ( os.path.isdir(target) and os.path.isdir('{0}/.hg'.format(target))) if is_repository: ret = _update_repo(ret, name, target, clean, user, rev, opts) else: if os.path.isdir(target): fail = _handle_existing(ret, target, force) if fail is not None: return fail else: log.debug( 'target {0} is not found, "hg clone" is required'.format( target)) if __opts__['test']: return _neutral_test( ret, 'Repository {0} is about to be cloned to {1}'.format( name, target)) _clone_repo(ret, target, name, user, rev, opts) return ret
def _update_repo(ret, target, clean, user, rev, opts): ''' Update the repo to a given revision. Using clean passes -C to the hg up ''' log.debug( 'target {0} is found, ' '"hg pull && hg up is probably required"'.format(target) ) current_rev = __salt__['hg.revision'](target, user=user, state_ret=ret) if not current_rev: return _fail( ret, 'Seems that {0} is not a valid hg repo'.format(target)) if __opts__['test']: test_result = ( 'Repository {0} update is probably required (current ' 'revision is {1})').format(target, current_rev) return _neutral_test( ret, test_result) pull_out = __salt__['hg.pull'](target, user=user, opts=opts, state_ret=ret) if rev: __salt__['hg.update'](target, rev, force=clean, user=user, state_ret=ret) else: __salt__['hg.update'](target, 'tip', force=clean, user=user, state_ret=ret) new_rev = __salt__['hg.revision'](cwd=target, user=user, state_ret=ret) if current_rev != new_rev: revision_text = '{0} => {1}'.format(current_rev, new_rev) log.info( 'Repository {0} updated: {1}'.format( target, revision_text) ) ret['comment'] = 'Repository {0} updated.'.format(target) ret['changes']['revision'] = revision_text elif 'error:' in pull_out: return _fail( ret, 'An error was thrown by hg:\n{0}'.format(pull_out) ) return ret
def dirty(name, target, user=None, ignore_unversioned=False): ''' Determine if the working directory has been changed. ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} return _fail(ret, 'This function is not implemented yet.')
def latest(name, rev=None, target=None, clean=False, user=None, force=False, opts=False): ''' Make sure the repository is cloned to the given directory and is up to date name Address of the remote repository as passed to "hg clone" rev The remote branch, tag, or revision hash to clone/pull target Name of the target directory where repository is about to be cloned clean Force a clean update with -C (Default: False) user Name of the user performing repository management operations .. versionadded: 0.17.0 force Force hg to clone into pre-existing directories (deletes contents) opts Include additional arguments and options to the hg command line ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, '"target option is required') is_repository = (os.path.isdir(target) and os.path.isdir('{0}/.hg'.format(target))) if is_repository: ret = _update_repo(ret, target, clean, user, rev, opts) else: if os.path.isdir(target): fail = _handle_existing(ret, target, force) if fail is not None: return fail else: log.debug('target {0} is not found, "hg clone" is required'.format( target)) if __opts__['test']: return _neutral_test( ret, 'Repository {0} is about to be cloned to {1}'.format( name, target)) _clone_repo(ret, target, name, user, rev, opts) return ret
def _handle_existing(ret, target, force): not_empty = os.listdir(target) if not not_empty: log.debug("target {0} found, but directory is empty, automatically " "deleting".format(target)) shutil.rmtree(target) elif force: log.debug("target {0} found and is not empty. Since force option is" " in use, deleting anyway.".format(target)) shutil.rmtree(target) else: return _fail(ret, "Directory exists, and is not empty")
def dirty(name, target, user=None, username=None, password=None, ignore_unversioned=False): ''' Determine if the working directory has been changed. ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} return _fail(ret, 'This function is not implemented yet.')
def dirty(name, target, user=None, username=None, password=None, ignore_unversioned=False): """ Determine if the working directory has been changed. """ ret = {"name": name, "result": True, "comment": "", "changes": {}} return _fail(ret, "This function is not implemented yet.")
def _handle_existing(ret, target, force): not_empty = os.listdir(target) if not not_empty: log.debug('target {0} found, but directory is empty, automatically ' 'deleting'.format(target)) shutil.rmtree(target) elif force: log.debug('target {0} found and is not empty. Since force option is' ' in use, deleting anyway.'.format(target)) shutil.rmtree(target) else: return _fail(ret, 'Directory exists, and is not empty')
def _handle_existing(ret, target, force): is_empty = os.listdir(target) if is_empty: log.debug( 'target {0} found, but directory is empty, automatically ' 'deleting'.format(target)) shutil.rmtree(target) elif force: log.debug( 'target {0} found and is not empty. Since force option is' ' in use, deleting anyway.'.format(target)) shutil.rmtree(target) else: return _fail(ret, 'Directory exists, and is not empty')
def _handle_existing(ret, target, force): not_empty = os.listdir(target) if not not_empty: log.debug( "target %s found, but directory is empty, automatically deleting", target) shutil.rmtree(target) elif force: log.debug( "target %s found and is not empty. " "Since force option is in use, deleting anyway.", target, ) shutil.rmtree(target) else: return _fail(ret, "Directory exists, and is not empty")
def latest(name, rev=None, target=None, runas=None, force=False, ): ''' Make sure the repository is cloned to to given directory and is up to date name Address of the remote repository as passed to "hg clone" rev The remote branch, tag, or revision hash to clone/pull target Name of the target directory where repository is about to be cloned runas Name of the user performing repository management operations force Force hg to clone into pre-existing directories (deletes contents) ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, '"target option is required') is_repository = ( os.path.isdir(target) and os.path.isdir('{0}/.hg'.format(target))) if is_repository: ret = _update_repo(ret, target, runas, rev) else: if os.path.isdir(target): fail = _handle_existing(ret, target, force) if fail is not None: return fail else: log.debug( 'target {0} is not found, "hg clone" is required'.format( target)) if __opts__['test']: return _neutral_test( ret, 'Repository {0} is about to be cloned to {1}'.format( name, target)) _clone_repo(ret, target, name, runas, rev) return ret
def _clone_repo(ret, target, name, user, rev, opts): result = __salt__['hg.clone'](target, name, user=user, opts=opts) if not os.path.isdir(target): return _fail(ret, result) if rev: __salt__['hg.update'](target, rev, user=user) new_rev = __salt__['hg.revision'](cwd=target, user=user) message = 'Repository {0} cloned to {1}'.format(name, target) log.info(message) ret['comment'] = message ret['changes']['new'] = name ret['changes']['revision'] = new_rev return ret
def _clone_repo(ret, target, name, runas, rev): result = __salt__['hg.clone'](target, name, user=runas) if not os.path.isdir(target): return _fail(ret, result) if rev: __salt__['hg.update'](target, rev, user=runas) new_rev = __salt__['hg.revision'](cwd=target, user=runas) message = 'Repository {0} cloned to {1}'.format(name, target) log.info(message) ret['comment'] = message ret['changes']['new'] = name ret['changes']['revision'] = new_rev return ret
def _clone_repo(ret, target, name, user, rev, opts): result = __salt__["hg.clone"](target, name, user=user, opts=opts) if not os.path.isdir(target): return _fail(ret, result) if rev: __salt__["hg.update"](target, rev, user=user) new_rev = __salt__["hg.revision"](cwd=target, user=user) message = "Repository {0} cloned to {1}".format(name, target) log.info(message) ret["comment"] = message ret["changes"]["new"] = name ret["changes"]["revision"] = new_rev return ret
def latest( name, rev=None, target=None, runas=None, force=False, ): ''' Make sure the repository is cloned to to given directory and is up to date name Address of the remote repository as passed to "hg clone" rev The remote branch, tag, or revision hash to clone/pull target Name of the target directory where repository is about to be cloned runas Name of the user performing repository management operations force Force hg to clone into pre-existing directories (deletes contents) ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, '"target option is required') is_repository = (os.path.isdir(target) and os.path.isdir('{0}/.hg'.format(target))) if is_repository: ret = _update_repo(ret, target, runas, rev) else: if os.path.isdir(target): fail = _handle_existing(ret, target, force) if fail is not None: return fail else: log.debug('target {0} is not found, "hg clone" is required'.format( target)) if __opts__['test']: return _neutral_test( ret, 'Repository {0} is about to be cloned to {1}'.format( name, target)) _clone_repo(ret, target, name, runas, rev) return ret
def _update_repo(ret, name, target, clean, user, identity, rev, opts, update_head): ''' Update the repo to a given revision. Using clean passes -C to the hg up ''' log.debug('target {0} is found, ' '"hg pull && hg up is probably required"'.format(target)) current_rev = __salt__['hg.revision'](target, user=user, rev='.') if not current_rev: return _fail(ret, 'Seems that {0} is not a valid hg repo'.format(target)) if __opts__['test']: test_result = ('Repository {0} update is probably required (current ' 'revision is {1})').format(target, current_rev) return _neutral_test(ret, test_result) try: pull_out = __salt__['hg.pull'](target, user=user, identity=identity, opts=opts, repository=name) except CommandExecutionError as err: ret['result'] = False ret['comment'] = err return ret if update_head is False: changes = 'no changes found' not in pull_out if changes: ret['comment'] = 'Update is probably required but update_head=False so we will skip updating.' else: ret['comment'] = 'No changes found and update_head=False so will skip updating.' return ret if rev: try: __salt__['hg.update'](target, rev, force=clean, user=user) except CommandExecutionError as err: ret['result'] = False ret['comment'] = err return ret else: try: __salt__['hg.update'](target, 'tip', force=clean, user=user) except CommandExecutionError as err: ret['result'] = False ret['comment'] = err return ret new_rev = __salt__['hg.revision'](cwd=target, user=user, rev='.') if current_rev != new_rev: revision_text = '{0} => {1}'.format(current_rev, new_rev) log.info('Repository {0} updated: {1}'.format(target, revision_text)) ret['comment'] = 'Repository {0} updated.'.format(target) ret['changes']['revision'] = revision_text elif 'error:' in pull_out: return _fail(ret, 'An error was thrown by hg:\n{0}'.format(pull_out)) return ret
def _update_repo(ret, name, target, clean, user, identity, rev, opts, update_head): """ Update the repo to a given revision. Using clean passes -C to the hg up """ log.debug('target %s is found, "hg pull && hg up is probably required"', target) current_rev = __salt__["hg.revision"](target, user=user, rev=".") if not current_rev: return _fail(ret, "Seems that {0} is not a valid hg repo".format(target)) if __opts__["test"]: test_result = ("Repository {0} update is probably required (current " "revision is {1})").format(target, current_rev) return _neutral_test(ret, test_result) try: pull_out = __salt__["hg.pull"](target, user=user, identity=identity, opts=opts, repository=name) except CommandExecutionError as err: ret["result"] = False ret["comment"] = err return ret if update_head is False: changes = "no changes found" not in pull_out if changes: ret["comment"] = "Update is probably required but update_head=False so we will skip updating." else: ret["comment"] = "No changes found and update_head=False so will skip updating." return ret if rev: try: __salt__["hg.update"](target, rev, force=clean, user=user) except CommandExecutionError as err: ret["result"] = False ret["comment"] = err return ret else: try: __salt__["hg.update"](target, "tip", force=clean, user=user) except CommandExecutionError as err: ret["result"] = False ret["comment"] = err return ret new_rev = __salt__["hg.revision"](cwd=target, user=user, rev=".") if current_rev != new_rev: revision_text = "{0} => {1}".format(current_rev, new_rev) log.info("Repository %s updated: %s", target, revision_text) ret["comment"] = "Repository {0} updated.".format(target) ret["changes"]["revision"] = revision_text elif "error:" in pull_out: return _fail(ret, "An error was thrown by hg:\n{0}".format(pull_out)) return ret
def latest( name, rev=None, target=None, clean=False, user=None, identity=None, force=False, opts=False, update_head=True, ): """ Make sure the repository is cloned to the given directory and is up to date name Address of the remote repository as passed to "hg clone" rev The remote branch, tag, or revision hash to clone/pull target Target destination directory path on minion to clone into clean Force a clean update with -C (Default: False) user Name of the user performing repository management operations .. versionadded:: 0.17.0 identity Private SSH key on the minion server for authentication (ssh://) .. versionadded:: 2015.5.0 force Force hg to clone into pre-existing directories (deletes contents) opts Include additional arguments and options to the hg command line update_head Should we update the head if new changes are found? Defaults to True .. versionadded:: 2017.7.0 """ ret = {"name": name, "result": True, "comment": "", "changes": {}} if not target: return _fail(ret, '"target option is required') is_repository = os.path.isdir(target) and os.path.isdir( "{0}/.hg".format(target)) if is_repository: ret = _update_repo(ret, name, target, clean, user, identity, rev, opts, update_head) else: if os.path.isdir(target): fail = _handle_existing(ret, target, force) if fail is not None: return fail else: log.debug('target %s is not found, "hg clone" is required', target) if __opts__["test"]: return _neutral_test( ret, "Repository {0} is about to be cloned to {1}".format( name, target)) _clone_repo(ret, target, name, user, identity, rev, opts) return ret
def latest( name, target=None, rev=None, user=None, username=None, password=None, force=False, externals=True, trust=False, trust_failures=None, ): """ Checkout or update the working directory to the latest revision from the remote repository. name Address of the name repository as passed to "svn checkout" target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user password Connect to the Subversion server with this password .. versionadded:: 0.17.0 force : False Continue if conflicts are encountered externals : True Change to False to not checkout or update externals trust : False Automatically trust the remote server. SVN's --trust-server-cert trust_failures : None Comma-separated list of certificate trust failures, that shall be ignored. This can be used if trust=True is not sufficient. The specified string is passed to SVN's --trust-server-cert-failures option as-is. .. versionadded:: 2019.2.0 """ ret = {"name": name, "result": True, "comment": "", "changes": {}} if not target: return _fail(ret, "Target option is required") svn_cmd = "svn.checkout" cwd, basename = os.path.split(target) opts = tuple() if os.path.exists(target) and not os.path.isdir(target): return _fail( ret, 'The path "{}" exists and is not a directory.'.format(target)) if __opts__["test"]: if rev: new_rev = str(rev) else: new_rev = "HEAD" if not os.path.exists(target): return _neutral_test( ret, "{} doesn't exist and is set to be checked out at revision {}." .format(target, new_rev), ) try: current_info = __salt__["svn.info"](cwd, target, user=user, username=username, password=password, fmt="dict") svn_cmd = "svn.diff" except exceptions.CommandExecutionError: return _fail( ret, "{} exists but is not a svn working copy.".format(target)) current_rev = current_info[0]["Revision"] opts += ("-r", "{}:{}".format(current_rev, new_rev)) if trust: opts += ("--trust-server-cert", ) if trust_failures: opts += ("--trust-server-cert-failures", trust_failures) out = __salt__[svn_cmd](cwd, target, user, username, password, *opts) return _neutral_test(ret, out) try: current_info = __salt__["svn.info"](cwd, target, user=user, username=username, password=password, fmt="dict") svn_cmd = "svn.update" except exceptions.CommandExecutionError: pass if rev: opts += ("-r", str(rev)) if force: opts += ("--force", ) if externals is False: opts += ("--ignore-externals", ) if trust: opts += ("--trust-server-cert", ) if trust_failures: opts += ("--trust-server-cert-failures", trust_failures) if svn_cmd == "svn.update": out = __salt__[svn_cmd](cwd, basename, user, username, password, *opts) current_rev = current_info[0]["Revision"] new_rev = __salt__["svn.info"]( cwd=target, targets=None, user=user, username=username, password=password, fmt="dict", )[0]["Revision"] if current_rev != new_rev: ret["changes"]["revision"] = "{} => {}".format( current_rev, new_rev) else: out = __salt__[svn_cmd](cwd, name, basename, user, username, password, *opts) ret["changes"]["new"] = name ret["changes"]["revision"] = __salt__["svn.info"]( cwd=target, targets=None, user=user, username=username, password=password, fmt="dict", )[0]["Revision"] ret["comment"] = out return ret
def latest(name, target=None, rev=None, user=None, username=None, force=False, externals=True): ''' Checkout or update the working directory to the latest revision from the remote repository. name Address of the name repository as passed to "svn checkout" target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user force : False Continue if conflicts are encountered externals : True Change to False to not checkout or update externals ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, 'Target option is required') svn_cmd = 'svn.checkout' cwd, basename = os.path.split(target) opts = tuple() if os.path.exists(target) and not os.path.isdir(target): return _fail(ret, 'The path "{0}" exists and is not ' 'a directory.'.format(target) ) try: __salt__['svn.info']('.', target, user=user) svn_cmd = 'svn.update' except exceptions.CommandExecutionError: pass if rev: opts += ('-r', str(rev)) if force: opts += ('--force',) if externals is False: opts += ('--ignore-externals',) if svn_cmd == 'svn.update': out = __salt__[svn_cmd](cwd, basename, user, *opts) else: out = __salt__[svn_cmd](cwd, name, basename, user, username, *opts) ret['comment'] = out return ret
def export( name, target=None, rev=None, user=None, username=None, password=None, force=False, overwrite=False, externals=True, trust=False, trust_failures=None, ): """ Export a file or directory from an SVN repository name Address and path to the file or directory to be exported. target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user password Connect to the Subversion server with this password .. versionadded:: 0.17.0 force : False Continue if conflicts are encountered overwrite : False Overwrite existing target externals : True Change to False to not checkout or update externals trust : False Automatically trust the remote server. SVN's --trust-server-cert trust_failures : None Comma-separated list of certificate trust failures, that shall be ignored. This can be used if trust=True is not sufficient. The specified string is passed to SVN's --trust-server-cert-failures option as-is. .. versionadded:: 2019.2.0 """ ret = {"name": name, "result": True, "comment": "", "changes": {}} if not target: return _fail(ret, "Target option is required") svn_cmd = "svn.export" cwd, basename = os.path.split(target) opts = () if not overwrite and os.path.exists(target) and not os.path.isdir(target): return _fail( ret, 'The path "{}" exists and is not a directory.'.format(target)) if __opts__["test"]: if not os.path.exists(target): return _neutral_test( ret, "{} doesn't exist and is set to be checked out.".format( target)) svn_cmd = "svn.list" rev = "HEAD" out = __salt__[svn_cmd](cwd, target, user, username, password, *opts) return _neutral_test(ret, out) if not rev: rev = "HEAD" if force: opts += ("--force", ) if externals is False: opts += ("--ignore-externals", ) if trust: opts += ("--trust-server-cert", ) if trust_failures: opts += ("--trust-server-cert-failures", trust_failures) out = __salt__[svn_cmd](cwd, name, basename, user, username, password, rev, *opts) ret["changes"]["new"] = name ret["changes"]["comment"] = "{} was Exported to {}".format(name, target) ret["comment"] = out return ret
def latest(name, target=None, rev=None, user=None, username=None, password=None, force=False, externals=True, trust=False): ''' Checkout or update the working directory to the latest revision from the remote repository. name Address of the name repository as passed to "svn checkout" target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user password Connect to the Subversion server with this password .. versionadded:: 0.17.0 force : False Continue if conflicts are encountered externals : True Change to False to not checkout or update externals trust : False Automatically trust the remote server. SVN's --trust-server-cert ''' ret = { 'name': name, 'result': True, 'comment': '', 'changes': {}, 'state_stdout': '' } if not target: return _fail(ret, 'Target option is required') svn_cmd = 'svn.checkout' cwd, basename = os.path.split(target) opts = tuple() if os.path.exists(target) and not os.path.isdir(target): return _fail( ret, 'The path "{0}" exists and is not ' 'a directory.'.format(target)) if __opts__['test']: if not os.path.exists(target): return _neutral_test( ret, ('{0} doesn\'t exist and is set to be checked out.' ).format(target)) svn_cmd = 'svn.diff' opts += ('-r', 'HEAD') out = __salt__[svn_cmd](cwd, target, user, username, password, *opts, state_ret=ret) return _neutral_test(ret, ('{0}').format(out)) try: current_info = __salt__['svn.info'](cwd, target, user=user, username=username, password=password, fmt='dict') svn_cmd = 'svn.update' except exceptions.CommandExecutionError: pass if rev: opts += ('-r', str(rev)) if force: opts += ('--force', ) if externals is False: opts += ('--ignore-externals', ) if trust: opts += ('--trust-server-cert', ) try: if svn_cmd == 'svn.update': out = __salt__[svn_cmd](cwd, basename, user, username, password, *opts, state_ret=ret) current_rev = current_info[0]['Revision'] new_rev = __salt__['svn.info'](cwd=target, targets=None, user=user, username=username, password=password, fmt='dict')[0]['Revision'] if current_rev != new_rev: ret['changes']['revision'] = "{0} => {1}".format( current_rev, new_rev) else: out = __salt__[svn_cmd](cwd, name, basename, user, username, password, *opts, state_ret=ret) ret['changes']['new'] = name ret['changes']['revision'] = __salt__['svn.info']( cwd=target, targets=None, user=user, username=username, password=password, fmt='dict')[0]['Revision'] ret['comment'] = 'Repository %s cloned to %s' % (name, target) except Exception, e: ret['result'] = False ret['comment'] = 'Checkout svn repository {0} failed'.format(name) ret['state_stdout'] = str(e)
def latest(name, target=None, rev=None, user=None, username=None, password=None, force=False, externals=True, trust=False): ''' Checkout or update the working directory to the latest revision from the remote repository. name Address of the name repository as passed to "svn checkout" target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user password Connect to the Subversion server with this password .. versionadded:: 0.17.0 force : False Continue if conflicts are encountered externals : True Change to False to not checkout or update externals trust : False Automatically trust the remote server. SVN's --trust-server-cert ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, 'Target option is required') svn_cmd = 'svn.checkout' cwd, basename = os.path.split(target) opts = tuple() if os.path.exists(target) and not os.path.isdir(target): return _fail(ret, 'The path "{0}" exists and is not ' 'a directory.'.format(target) ) if __opts__['test']: if not os.path.exists(target): return _neutral_test( ret, ('{0} doesn\'t exist and is set to be checked out.').format(target)) svn_cmd = 'svn.diff' opts += ('-r', 'HEAD') out = __salt__[svn_cmd](cwd, target, user, username, password, *opts) return _neutral_test( ret, ('{0}').format(out)) try: current_info = __salt__['svn.info'](cwd, target, user=user, username=username, password=password, fmt='dict') svn_cmd = 'svn.update' except exceptions.CommandExecutionError: pass if rev: opts += ('-r', str(rev)) if force: opts += ('--force',) if externals is False: opts += ('--ignore-externals',) if trust: opts += ('--trust-server-cert',) if svn_cmd == 'svn.update': out = __salt__[svn_cmd](cwd, basename, user, username, password, *opts) current_rev = current_info[0]['Revision'] new_rev = __salt__['svn.info'](cwd=target, targets=None, user=user, username=username, password=password, fmt='dict')[0]['Revision'] if current_rev != new_rev: ret['changes']['revision'] = "{0} => {1}".format(current_rev, new_rev) else: out = __salt__[svn_cmd](cwd, name, basename, user, username, password, *opts) ret['changes']['new'] = name ret['changes']['revision'] = __salt__['svn.info'](cwd=target, targets=None, user=user, username=username, password=password, fmt='dict')[0]['Revision'] ret['comment'] = out return ret
def _update_repo(ret, name, target, clean, user, identity, rev, opts, update_head): ''' Update the repo to a given revision. Using clean passes -C to the hg up ''' log.debug( 'target {0} is found, ' '"hg pull && hg up is probably required"'.format(target) ) current_rev = __salt__['hg.revision'](target, user=user, rev='.') if not current_rev: return _fail( ret, 'Seems that {0} is not a valid hg repo'.format(target)) if __opts__['test']: test_result = ( 'Repository {0} update is probably required (current ' 'revision is {1})').format(target, current_rev) return _neutral_test( ret, test_result) try: pull_out = __salt__['hg.pull'](target, user=user, identity=identity, opts=opts, repository=name) except CommandExecutionError as err: ret['result'] = False ret['comment'] = err return ret if update_head is False: changes = 'no changes found' not in pull_out if changes: ret['comment'] = 'Update is probably required but update_head=False so we will skip updating.' else: ret['comment'] = 'No changes found and update_head=False so will skip updating.' return ret if rev: try: __salt__['hg.update'](target, rev, force=clean, user=user) except CommandExecutionError as err: ret['result'] = False ret['comment'] = err return ret else: try: __salt__['hg.update'](target, 'tip', force=clean, user=user) except CommandExecutionError as err: ret['result'] = False ret['comment'] = err return ret new_rev = __salt__['hg.revision'](cwd=target, user=user, rev='.') if current_rev != new_rev: revision_text = '{0} => {1}'.format(current_rev, new_rev) log.info( 'Repository {0} updated: {1}'.format( target, revision_text) ) ret['comment'] = 'Repository {0} updated.'.format(target) ret['changes']['revision'] = revision_text elif 'error:' in pull_out: return _fail( ret, 'An error was thrown by hg:\n{0}'.format(pull_out) ) return ret
def latest(name, target=None, rev=None, user=None, username=None, password=None, force=False, externals=True, trust=False, trust_failures=None): ''' Checkout or update the working directory to the latest revision from the remote repository. name Address of the name repository as passed to "svn checkout" target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user password Connect to the Subversion server with this password .. versionadded:: 0.17.0 force : False Continue if conflicts are encountered externals : True Change to False to not checkout or update externals trust : False Automatically trust the remote server. SVN's --trust-server-cert trust_failures : None Comma-separated list of certificate trust failures, that shall be ignored. This can be used if trust=True is not sufficient. The specified string is passed to SVN's --trust-server-cert-failures option as-is. .. versionadded:: Fluorine ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, 'Target option is required') svn_cmd = 'svn.checkout' cwd, basename = os.path.split(target) opts = tuple() if os.path.exists(target) and not os.path.isdir(target): return _fail( ret, 'The path "{0}" exists and is not ' 'a directory.'.format(target)) if __opts__['test']: if rev: new_rev = six.text_type(rev) else: new_rev = 'HEAD' if not os.path.exists(target): return _neutral_test( ret, ('{0} doesn\'t exist and is set to be checked out at revision ' + new_rev + '.').format(target)) try: current_info = __salt__['svn.info'](cwd, target, user=user, username=username, password=password, fmt='dict') svn_cmd = 'svn.diff' except exceptions.CommandExecutionError: return _fail( ret, ('{0} exists but is not a svn working copy.').format(target)) current_rev = current_info[0]['Revision'] opts += ('-r', current_rev + ':' + new_rev) if trust: opts += ('--trust-server-cert', ) out = __salt__[svn_cmd](cwd, target, user, username, password, *opts) return _neutral_test(ret, ('{0}').format(out)) try: current_info = __salt__['svn.info'](cwd, target, user=user, username=username, password=password, fmt='dict') svn_cmd = 'svn.update' except exceptions.CommandExecutionError: pass if rev: opts += ('-r', six.text_type(rev)) if force: opts += ('--force', ) if externals is False: opts += ('--ignore-externals', ) if trust: opts += ('--trust-server-cert', ) if trust_failures: opts += ('--trust-server-cert-failures', trust_failures) if svn_cmd == 'svn.update': out = __salt__[svn_cmd](cwd, basename, user, username, password, *opts) current_rev = current_info[0]['Revision'] new_rev = __salt__['svn.info'](cwd=target, targets=None, user=user, username=username, password=password, fmt='dict')[0]['Revision'] if current_rev != new_rev: ret['changes']['revision'] = "{0} => {1}".format( current_rev, new_rev) else: out = __salt__[svn_cmd](cwd, name, basename, user, username, password, *opts) ret['changes']['new'] = name ret['changes']['revision'] = __salt__['svn.info']( cwd=target, targets=None, user=user, username=username, password=password, fmt='dict')[0]['Revision'] ret['comment'] = out return ret
def latest(name, rev=None, target=None, clean=False, runas=None, user=None, force=False, opts=False): """ Make sure the repository is cloned to the given directory and is up to date name Address of the remote repository as passed to "hg clone" rev The remote branch, tag, or revision hash to clone/pull target Name of the target directory where repository is about to be cloned clean Force a clean update with -C (Default: False) runas Name of the user performing repository management operations .. deprecated:: 0.17.0 user Name of the user performing repository management operations .. versionadded: 0.17.0 force Force hg to clone into pre-existing directories (deletes contents) opts Include additional arguments and options to the hg command line """ ret = {"name": name, "result": True, "comment": "", "changes": {}} salt.utils.warn_until( "Lithium", "Please remove 'runas' support at this stage. 'user' support was " "added in 0.17.0", _dont_call_warnings=True, ) if runas: # Warn users about the deprecation ret.setdefault("warnings", []).append( "The 'runas' argument is being deprecated in favor of 'user', " "please update your state files." ) if user is not None and runas is not None: # user wins over runas but let warn about the deprecation. ret.setdefault("warnings", []).append( "Passed both the 'runas' and 'user' arguments. Please don't. " "'runas' is being ignored in favor of 'user'." ) runas = None elif runas is not None: # Support old runas usage user = runas runas = None if not target: return _fail(ret, '"target option is required') is_repository = os.path.isdir(target) and os.path.isdir("{0}/.hg".format(target)) if is_repository: ret = _update_repo(ret, target, clean, user, rev, opts) else: if os.path.isdir(target): fail = _handle_existing(ret, target, force) if fail is not None: return fail else: log.debug('target {0} is not found, "hg clone" is required'.format(target)) if __opts__["test"]: return _neutral_test(ret, "Repository {0} is about to be cloned to {1}".format(name, target)) _clone_repo(ret, target, name, user, rev, opts) return ret
def export(name, target=None, rev=None, user=None, username=None, password=None, force=False, overwrite=False, externals=True, trust=False, trust_failures=None): ''' Export a file or directory from an SVN repository name Address and path to the file or directory to be exported. target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user password Connect to the Subversion server with this password .. versionadded:: 0.17.0 force : False Continue if conflicts are encountered overwrite : False Overwrite existing target externals : True Change to False to not checkout or update externals trust : False Automatically trust the remote server. SVN's --trust-server-cert trust_failures : None Comma-separated list of certificate trust failures, that shall be ignored. This can be used if trust=True is not sufficient. The specified string is passed to SVN's --trust-server-cert-failures option as-is. .. versionadded:: Fluorine ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, 'Target option is required') svn_cmd = 'svn.export' cwd, basename = os.path.split(target) opts = tuple() if not overwrite and os.path.exists(target) and not os.path.isdir(target): return _fail( ret, 'The path "{0}" exists and is not ' 'a directory.'.format(target)) if __opts__['test']: if not os.path.exists(target): return _neutral_test( ret, ('{0} doesn\'t exist and is set to be checked out.' ).format(target)) svn_cmd = 'svn.list' rev = 'HEAD' out = __salt__[svn_cmd](cwd, target, user, username, password, *opts) return _neutral_test(ret, ('{0}').format(out)) if not rev: rev = 'HEAD' if force: opts += ('--force', ) if externals is False: opts += ('--ignore-externals', ) if trust: opts += ('--trust-server-cert', ) if trust_failures: opts += ('--trust-server-cert-failures', trust_failures) out = __salt__[svn_cmd](cwd, name, basename, user, username, password, rev, *opts) ret['changes']['new'] = name ret['changes']['comment'] = name + ' was Exported to ' + target ret['comment'] = out return ret
def latest(name, rev=None, target=None, clean=False, runas=None, user=None, force=False, opts=False): ''' Make sure the repository is cloned to the given directory and is up to date name Address of the remote repository as passed to "hg clone" rev The remote branch, tag, or revision hash to clone/pull target Name of the target directory where repository is about to be cloned clean Force a clean update with -C (Default: False) runas Name of the user performing repository management operations .. deprecated:: 0.17.0 user Name of the user performing repository management operations .. versionadded: 0.17.0 force Force hg to clone into pre-existing directories (deletes contents) opts Include additional arguments and options to the hg command line ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} salt.utils.warn_until( 'Lithium', 'Please remove \'runas\' support at this stage. \'user\' support was ' 'added in 0.17.0', _dont_call_warnings=True) if runas: # Warn users about the deprecation ret.setdefault('warnings', []).append( 'The \'runas\' argument is being deprecated in favor of \'user\', ' 'please update your state files.') if user is not None and runas is not None: # user wins over runas but let warn about the deprecation. ret.setdefault('warnings', []).append( 'Passed both the \'runas\' and \'user\' arguments. Please don\'t. ' '\'runas\' is being ignored in favor of \'user\'.') runas = None elif runas is not None: # Support old runas usage user = runas runas = None if not target: return _fail(ret, '"target option is required') is_repository = (os.path.isdir(target) and os.path.isdir('{0}/.hg'.format(target))) if is_repository: ret = _update_repo(ret, target, clean, user, rev, opts) else: if os.path.isdir(target): fail = _handle_existing(ret, target, force) if fail is not None: return fail else: log.debug('target {0} is not found, "hg clone" is required'.format( target)) if __opts__['test']: return _neutral_test( ret, 'Repository {0} is about to be cloned to {1}'.format( name, target)) _clone_repo(ret, target, name, user, rev, opts) return ret
def latest(name, rev=None, target=None, clean=False, runas=None, user=None, force=False, opts=False): ''' Make sure the repository is cloned to the given directory and is up to date name Address of the remote repository as passed to "hg clone" rev The remote branch, tag, or revision hash to clone/pull target Name of the target directory where repository is about to be cloned clean Force a clean update with -C (Default: False) runas Name of the user performing repository management operations .. deprecated:: 0.17.0 user Name of the user performing repository management operations .. versionadded: 0.17.0 force Force hg to clone into pre-existing directories (deletes contents) opts Include additional arguments and options to the hg command line ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}, 'state_stdout': ''} salt.utils.warn_until( 'Hydrogen', 'Please remove \'runas\' support at this stage. \'user\' support was ' 'added in 0.17.0', _dont_call_warnings=True ) if runas: # Warn users about the deprecation ret.setdefault('warnings', []).append( 'The \'runas\' argument is being deprecated in favor of \'user\', ' 'please update your state files.' ) if user is not None and runas is not None: # user wins over runas but let warn about the deprecation. ret.setdefault('warnings', []).append( 'Passed both the \'runas\' and \'user\' arguments. Please don\'t. ' '\'runas\' is being ignored in favor of \'user\'.' ) runas = None elif runas is not None: # Support old runas usage user = runas runas = None if not target: return _fail(ret, '"target option is required') is_repository = ( os.path.isdir(target) and os.path.isdir('{0}/.hg'.format(target))) if is_repository: ret = _update_repo(ret, target, clean, user, rev, opts) else: if os.path.isdir(target): fail = _handle_existing(ret, target, force) if fail is not None: return fail else: log.debug( 'target {0} is not found, "hg clone" is required'.format( target)) if __opts__['test']: return _neutral_test( ret, 'Repository {0} is about to be cloned to {1}'.format( name, target)) _clone_repo(ret, target, name, user, rev, opts) return ret
def latest(name, target=None, rev=None, user=None, username=None, force=False, externals=True): ''' Checkout or update the working directory to the latest revision from the remote repository. name Address of the name repository as passed to "svn checkout" target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user force : False Continue if conflicts are encountered externals : True Change to False to not checkout or update externals ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, 'Target option is required') svn_cmd = 'svn.checkout' cwd, basename = os.path.split(target) opts = tuple() if os.path.exists(target) and not os.path.isdir(target): return _fail( ret, 'The path "{0}" exists and is not ' 'a directory.'.format(target)) try: __salt__['svn.info']('.', target, user=user) svn_cmd = 'svn.update' except exceptions.CommandExecutionError: pass if rev: opts += ('-r', str(rev)) if force: opts += ('--force', ) if externals is False: opts += ('--ignore-externals', ) if svn_cmd == 'svn.update': out = __salt__[svn_cmd](cwd, basename, user, *opts) else: out = __salt__[svn_cmd](cwd, name, basename, user, username, *opts) ret['comment'] = out return ret
def export(name, target=None, rev=None, user=None, username=None, password=None, force=False, externals=True, trust=False): ''' Export a file or directory from an SVN repository name Address and path to the file or directory to be exported. target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user password Connect to the Subversion server with this password .. versionadded:: 0.17.0 force : False Continue if conflicts are encountered externals : True Change to False to not checkout or update externals trust : False Automatically trust the remote server. SVN's --trust-server-cert ''' ret = { 'name': name, 'result': True, 'comment': '', 'changes': {}, 'state_stdout': '' } if not target: return _fail(ret, 'Target option is required') svn_cmd = 'svn.export' cwd, basename = os.path.split(target) opts = tuple() if os.path.exists(target) and not os.path.isdir(target): return _fail( ret, 'The path "{0}" exists and is not ' 'a directory.'.format(target)) if __opts__['test']: if not os.path.exists(target): return _neutral_test( ret, ('{0} doesn\'t exist and is set to be checked out.' ).format(target)) svn_cmd = 'svn.list' opts += ('-r', 'HEAD') out = __salt__[svn_cmd](cwd, target, user, username, password, *opts, state_ret=ret) return _neutral_test(ret, ('{0}').format(out)) if rev: opts += ('-r', str(rev)) if force: opts += ('--force', ) if externals is False: opts += ('--ignore-externals', ) if trust: opts += ('--trust-server-cert', ) try: out = __salt__[svn_cmd](cwd, name, basename, user, username, password, *opts, state_ret=ret) ret['changes'] = name + ' was Exported to ' + target ret['comment'] = 'Repository %s exported to %s' % (name, target) except: ret['result'] = False return ret
def export(name, target=None, rev=None, user=None, username=None, password=None, force=False, overwrite=False, externals=True, trust=False): ''' Export a file or directory from an SVN repository name Address and path to the file or directory to be exported. target Name of the target directory where the checkout will put the working directory rev : None The name revision number to checkout. Enable "force" if the directory already exists. user : None Name of the user performing repository management operations username : None The user to access the name repository with. The svn default is the current user password Connect to the Subversion server with this password .. versionadded:: 0.17.0 force : False Continue if conflicts are encountered overwrite : False Overwrite existing target externals : True Change to False to not checkout or update externals trust : False Automatically trust the remote server. SVN's --trust-server-cert ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if not target: return _fail(ret, 'Target option is required') svn_cmd = 'svn.export' cwd, basename = os.path.split(target) opts = tuple() if not overwrite and os.path.exists(target) and not os.path.isdir(target): return _fail(ret, 'The path "{0}" exists and is not ' 'a directory.'.format(target) ) if __opts__['test']: if not os.path.exists(target): return _neutral_test( ret, ('{0} doesn\'t exist and is set to be checked out.').format(target)) svn_cmd = 'svn.list' rev = 'HEAD' out = __salt__[svn_cmd](cwd, target, user, username, password, *opts) return _neutral_test( ret, ('{0}').format(out)) if not rev: rev = 'HEAD' if force: opts += ('--force',) if externals is False: opts += ('--ignore-externals',) if trust: opts += ('--trust-server-cert',) out = __salt__[svn_cmd](cwd, name, basename, user, username, password, rev, *opts) ret['changes'] = name + ' was Exported to ' + target return ret