def deploy_files(topdir, repository, files, excludes = None, config_channel = None): topdir = topdir or os.sep if not excludes: excludes = [] dep_trans = DeployTransaction(transaction_root=topdir) dep_trans.deploy_callback(deploy_msg_callback) for path in files: if path in excludes: print("Excluding %s" % path) else: try: if config_channel: args = (config_channel, path) else: args = (path, ) kwargs = {'auto_delete': 0, 'dest_directory': topdir} finfo = repository.get_file_info(*args, **kwargs) except cfg_exceptions.DirectoryEntryIsFile: e = sys.exc_info()[1] print("Error: unable to deploy directory %s, as it is already a file on disk" % e[0]) continue if finfo is None: # File disappeared since we called the function continue (processed_path, file_info, dirs_created) = finfo try: dep_trans.add_preprocessed(path, processed_path, file_info, dirs_created) except cfg_exceptions.UserNotFound: e = sys.exc_info()[1] print("Error: unable to deploy file %s, information on user '%s' could not be found." % (path,e[0])) continue except cfg_exceptions.GroupNotFound: e = sys.exc_info()[1] print("Error: unable to deploy file %s, information on group '%s' could not be found." % (path, e[0])) continue try: dep_trans.deploy() #5/3/05 wregglej - 136415 added missing user exception stuff. except cfg_exceptions.UserNotFound: e = sys.exc_info()[1] try_rollback(dep_trans, "Error unable to deploy file, information on user '%s' could not be found" % e[0]) except cfg_exceptions.GroupNotFound: e = sys.exc_info()[1] try_rollback(dep_trans, "Error: unable to deploy file, information on group '%s' could not be found" % e[0]) except cfg_exceptions.FileEntryIsDirectory: e = sys.exc_info()[1] try_rollback(dep_trans, "Error: unable to deploy file %s, as it is already a directory on disk" % e[0]) except cfg_exceptions.DirectoryEntryIsFile: e = sys.exc_info()[1] try_rollback(dep_trans, "Error: unable to deploy directory %s, as it is already a file on disk" % e[0]) except Exception: try: try_rollback(dep_trans, "Deploy failed, rollback successful") except: print("Failed rollback") raise
def run(self): topdir = self.options.topdir or os.sep dep_trans = DeployTransaction(transaction_root=topdir) dep_trans.deploy_callback(deploying_mesg_callback) # Setup the excludes hash excludes = {} if self.options.exclude is not None: for exclude in enumerate(self.options.exclude): excludes[exclude[1]] = None for path in self.get_valid_files(): (directory, filename) = os.path.split(path) directory = os.path.normpath("%s%s%s" % (topdir, os.sep, directory)) try: finfo = self.repository.get_file_info(path, auto_delete=0, dest_directory=directory) except cfg_exceptions.DirectoryEntryIsFile, e: print "Error: unable to deploy directory %s, as it is already a file on disk" % (e[0], ) continue if finfo is None: # File disappeared since we called the function continue (processed_path, file_info, dirs_created) = finfo if excludes.has_key(path): print "Excluding %s" % path else: try: dep_trans.add_preprocessed(path, processed_path, file_info, dirs_created) except cfg_exceptions.UserNotFound, e: print "Error: unable to deploy file %s, information on user '%s' could not be found." % (path,e[0]) continue except cfg_exceptions.GroupNotFound, e: print "Error: unable to deploy file %s, information on group '%s' could not be found." % (path, e[0]) continue
def run(self): log_debug(2) r = self.repository channel = self.options.channel if not channel: die(6, "Config channel not specified") topdir = self.options.topdir if topdir: if not os.path.isdir(self.options.topdir): die( 8, "--topdir specified, but `%s' not a directory" % self.options.topdir) if not self.args: die(7, "No files specified") revision = self.options.revision if revision: if len(self.args) > 1: die(9, "--revision specified with multiple files") dep_trans = None if topdir: dep_trans = DeployTransaction(transaction_root=topdir) dep_trans.deploy_callback(deploying_mesg_callback) for f in self.args: try: directory = topdir or tempfile.gettempdir() #5/11/05 wregglej - 157066 dirs_created is returned from get_file_info. (temp_file, info, dirs_created) = r.get_file_info(channel, f, revision=revision, auto_delete=0, dest_directory=directory) except cfg_exceptions.RepositoryFileMissingError: if revision is not None: die( 2, "Error: file %s (revision %s) not in config " "channel %s" % (f, revision, channel)) else: die( 2, "Error: file %s not in config channel %s" % (f, channel)) if topdir: #5/11/05 wregglej - 157066 dirs_created now gets passed into add_preprocessed. dep_trans.add_preprocessed(f, temp_file, info, dirs_created, strict_ownership=0) continue elif info.get('filetype') == 'symlink': print("%s -> %s" % (info['path'], info['symlink'])) continue elif info.get('filetype') == 'directory': print("%s is a directory entry, nothing to get" % info['path']) continue else: print(open(temp_file).read()) os.unlink(temp_file) if topdir: try: dep_trans.deploy() except Exception: try: dep_trans.rollback() except FailedRollback: raise_with_tb(FailedRollback("FAILED ROLLBACK: "), sys.exc_info()[2]) #5/3/05 wregglej - 136415 Added exception stuff for missing user info. except cfg_exceptions.UserNotFound: raise #5/5/05 wregglej - 136415 Added exception handling for unknown group. except cfg_exceptions.GroupNotFound: raise else: raise_with_tb( Exception("Deploy failed, rollback successful: "), sys.exc_info()[2])
def run(self): log_debug(2) r = self.repository channel = self.options.channel if not channel: die(6, "Config channel not specified") topdir = self.options.topdir if topdir: if not os.path.isdir(self.options.topdir): die(8, "--topdir specified, but `%s' not a directory" % self.options.topdir) if not self.args: die(7, "No files specified") revision = self.options.revision if revision: if len(self.args) > 1: die(9, "--revision specified with multiple files") dep_trans = None if topdir: dep_trans = DeployTransaction(transaction_root=topdir) dep_trans.deploy_callback(deploying_mesg_callback) for f in self.args: try: directory = topdir or tempfile.gettempdir() # 5/11/05 wregglej - 157066 dirs_created is returned from get_file_info. (temp_file, info, dirs_created) = r.get_file_info( channel, f, revision=revision, auto_delete=0, dest_directory=directory ) except cfg_exceptions.RepositoryFileMissingError: if revision is not None: die(2, "Error: file %s (revision %s) not in config " "channel %s" % (f, revision, channel)) else: die(2, "Error: file %s not in config channel %s" % (f, channel)) if topdir: # 5/11/05 wregglej - 157066 dirs_created now gets passed into add_preprocessed. dep_trans.add_preprocessed(f, temp_file, info, dirs_created, strict_ownership=0) continue elif info.get("filetype") == "symlink": print "%s -> %s" % (info["path"], info["symlink"]) continue elif info.get("filetype") == "directory": print "%s is a directory entry, nothing to get" % info["path"] continue else: print open(temp_file).read() os.unlink(temp_file) if topdir: try: dep_trans.deploy() except Exception, e: try: dep_trans.rollback() except FailedRollback, e2: raise e2, "FAILED ROLLBACK: ", sys.exc_info()[2] # 5/3/05 wregglej - 136415 Added exception stuff for missing user info. except cfg_exceptions.UserNotFound, f: raise
def deploy_files(topdir, repository, files, excludes=None, config_channel=None): topdir = topdir or os.sep if not excludes: excludes = [] dep_trans = DeployTransaction(transaction_root=topdir) dep_trans.deploy_callback(deploy_msg_callback) for path in files: if path in excludes: print("Excluding %s" % path) else: try: if config_channel: args = (config_channel, path) else: args = (path, ) kwargs = {'auto_delete': 0, 'dest_directory': topdir} finfo = repository.get_file_info(*args, **kwargs) except cfg_exceptions.DirectoryEntryIsFile: e = sys.exc_info()[1] print( "Error: unable to deploy directory %s, as it is already a file on disk" % e[0]) continue if finfo is None: # File disappeared since we called the function continue (processed_path, file_info, dirs_created) = finfo try: dep_trans.add_preprocessed(path, processed_path, file_info, dirs_created) except cfg_exceptions.UserNotFound: e = sys.exc_info()[1] print( "Error: unable to deploy file %s, information on user '%s' could not be found." % (path, e[0])) continue except cfg_exceptions.GroupNotFound: e = sys.exc_info()[1] print( "Error: unable to deploy file %s, information on group '%s' could not be found." % (path, e[0])) continue try: dep_trans.deploy() #5/3/05 wregglej - 136415 added missing user exception stuff. except cfg_exceptions.UserNotFound: e = sys.exc_info()[1] try_rollback( dep_trans, "Error unable to deploy file, information on user '%s' could not be found" % e[0]) except cfg_exceptions.GroupNotFound: e = sys.exc_info()[1] try_rollback( dep_trans, "Error: unable to deploy file, information on group '%s' could not be found" % e[0]) except cfg_exceptions.FileEntryIsDirectory: e = sys.exc_info()[1] try_rollback( dep_trans, "Error: unable to deploy file %s, as it is already a directory on disk" % e[0]) except cfg_exceptions.DirectoryEntryIsFile: e = sys.exc_info()[1] try_rollback( dep_trans, "Error: unable to deploy directory %s, as it is already a file on disk" % e[0]) except Exception: try: try_rollback(dep_trans, "Deploy failed, rollback successful") except: print("Failed rollback") raise