def upload_config_channel(self, topdir, channel, directory_name): if not self.r.config_channel_exists(channel): die(6, "Error: config channel %s does not exist" % channel) if self.options.disable_selinux: selinux_ctx = '' else: selinux_ctx = None print "Using config channel %s" % channel channel_dir = utils.join_path(topdir, directory_name) if not os.path.exists(channel_dir): die(6, "Error: channel directory %s does not exist" % channel_dir) flist = list_files_recursive(channel_dir) for (dirname, filenames) in flist: assert dirname.startswith(channel_dir) remote_dirname = dirname[len(channel_dir):] for f in filenames: local_file = utils.join_path(dirname, f) remote_file = utils.join_path(remote_dirname, f) print "Uploading %s from %s" % (remote_file, local_file) try: self.r.put_file(channel, remote_file, local_file, is_first_revision=0, selinux_ctx = selinux_ctx) except cfg_exceptions.RepositoryFilePushError, e: log_error(e)
def run(self): log_debug(2) if self.options.dest_file and self.options.topdir: die(6, "Error: conflicting options --dest-file and --topdir") if len(self.args) == 0: die(0, "No files supplied (use --help for help)") channel = self.options.channel if not channel: die(6, "Config channel not specified") r = self.repository if not r.config_channel_exists(channel): die(6, "Error: config channel %s does not exist" % channel) files = map(utils.normalize_path, self.args) files_to_push = [] if self.options.dest_file: if len(files) != 1: die(7, "--dest-file accepts a single file") if not (self.options.dest_file[0] == os.sep): die(7, "--dest-file argument must begin with " + os.sep) files_to_push.append((files[0], self.options.dest_file)) elif self.options.topdir: if not os.path.isdir(self.options.topdir): die(8, "--topdir specified, but `%s' not a directory" % self.options.topdir) #5/11/05 wregglej - 141790 remove the trailing slash from topdir self.options.topdir = utils.rm_trailing_slash(self.options.topdir) for f in files: if not f.startswith(self.options.topdir): die(8, "--topdir %s specified, but file `%s' doesn't comply" % (self.options.topdir, f)) files_to_push.append((f, f[len(self.options.topdir):])) else: for f in files: #if a file is given w/o a full path, then use the abspath of the #file as name of the file to be uploaded into the channel if not (f[0] == os.sep): files_to_push.append((f, os.path.abspath(f))) else: files_to_push.append((f, f)) for (local_file, remote_file) in files_to_push: if not os.path.exists(local_file): if self.options.ignore_missing: files_to_push.remove((local_file,remote_file)) print "Local file %s does not exist. Ignoring file..." %(local_file) else: die(9, "No such file `%s'" % local_file) print "Pushing to channel %s:" % (channel, ) delim_start = self.options.delim_start delim_end = self.options.delim_end selinux_ctx = None if type(self.options.selinux_context) != None: selinux_ctx = self.options.selinux_context for (local_file, remote_file) in files_to_push: try: r.put_file(channel, remote_file, local_file, is_first_revision=self.is_first_revision, delim_start=delim_start, delim_end=delim_end, selinux_ctx=selinux_ctx) except cfg_exceptions.RepositoryFileExistsError, e: log_error("Error: %s is already in channel %s" % (remote_file, channel)) except cfg_exceptions.RepositoryFilePushError, e: log_error("Error pushing file: %s" % e)