예제 #1
0
    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)

        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 utils.startswith(dirname, 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)
                except cfg_exceptions.RepositoryFilePushError, e:
                    log_error(e)
예제 #2
0
    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)

        topdir = self.options.topdir
        revision = self.options.revision

        files_to_diff = []

        files = map(utils.normalize_path, self.args)
        files_count = len(files)

        if files_count != 1 and revision is not None:
            die(8, "--revision can only be used with a single file")

        if self.options.dest_file:
            if files_count != 1:
                die(7, "--dest-file accepts a single file")

            files_to_diff.append((files[0], self.options.dest_file))

        elif topdir:
            if not os.path.isdir(topdir):
                die(8, "--topdir specified, but `%s' not a directory" %
                    topdir)

            #5/11/04 wregglej - 141790 remove trailing slash in topdir, if present.
            topdir = utils.rm_trailing_slash(topdir)

            for f in files:
                if not utils.startswith(f, topdir):
                    die(8, "--topdir %s specified, but file `%s' doesn't comply"
                        % (topdir, f))
                if os.path.isdir(f) and not os.path.islink(f):
                    die(8, "Cannot diff %s; it is a directory" % f)
                files_to_diff.append((f, f[len(topdir):]))
        else:
            for f in files:
                if os.path.isdir(f) and not os.path.islink(f):
                    die(8, "Cannot diff %s; it is a directory" % f)
                files_to_diff.append((f, f))

        for (local_file, remote_file) in files_to_diff:
            sys.stdout.write(
                self.diff_file(channel, remote_file, local_file, revision))
예제 #3
0
    def diff_file(self, channel, path, local_file, revision):
        r = self.repository
        try:
            #5/11/05 wregglej - 157066 dirs_created is returned by get_file_info, now.
            temp_file, info, dirs_created = r.get_file_info(channel, path, revision=revision)
        except cfg_exceptions.RepositoryFileMissingError:
            die(2, "Error: no such file %s (revision %s) in config channel %s"
                % (path, revision, channel))
        if os.path.islink(local_file) and info['filetype'] != 'symlink' :
             die(8, "Cannot diff %s; the file on the system is a symbolic link while the file in the channel is not. " % local_file)
        if  info['filetype'] == 'symlink' and not os.path.islink(local_file) :
             die(8, "Cannot diff %s; the file on the system is not a symbolic link while the file in the channel is. " % local_file)             
        if info['filetype'] == 'symlink':
            src_link = info['symlink']
            dest_link = os.readlink(local_file)
            if src_link != os.readlink(local_file):
                return "Symbolic links differ. Channel: '%s' -> '%s'   System: '%s' -> '%s' \n " % (path,src_link, path, dest_link) 
            return ""    
        # Test -u option to diff
        diffcmd = "/usr/bin/diff -u"
        pipe = os.popen("%s %s %s 2>/dev/null" % (diffcmd, temp_file, local_file))
        pipe.read()  # Read the output so GNU diff is happy
        ret = pipe.close()
        if ret == None: ret = 0
        ret = ret/256  # Return code in upper byte
        if ret == 2:  # error in diff call
            diffcmd = "/usr/bin/diff -c"

        pipe = os.popen("%s %s %s" % (diffcmd, temp_file, local_file))
        first_row = pipe.readline()
        if not first_row:
            return ""
        elif utils.startswith(first_row, "---"):
            first_row = "--- %s\tconfig_channel: %s\trevision: %s\n" % (
                path, channel, info['revision']
            )
        elif utils.startswith(first_row, "***"):
            # This happens when we drop back to "diff -c"
            first_row = "*** %s\tconfig_channel: %s\trevision: %s\n" % (
                path, channel, info['revision']
            )
        return first_row + pipe.read()
예제 #4
0
    def run(self):
        log_debug(2)
        r = self.repository

        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_remove = []
        if self.options.topdir:
            if not os.path.isdir(self.options.topdir):
                die(8, "--topdir specified, but `%s' not a directory" %
                    self.options.topdir)
            for f in files:
                if not utils.startswith(f, self.options.topdir):
                    die(8, "--topdir %s specified, but file `%s' doesn't comply"
                        % (self.options.topdir, f))
                files_to_remove.append((f, f[len(self.options.topdir):]))
        else:
            for f in files:
                files_to_remove.append((f, f))

        print "Removing from config channel %s" % channel
        for (local_file, remote_file) in files_to_remove:
            try:
                r.remove_file(channel, remote_file)
            except repository.rpclib.Fault, e:
                if e.faultCode == -4011:
                    print "%s does not exist" % remote_file
                    continue
                raise e
            else:
                print "%s removed" % remote_file
예제 #5
0
    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 utils.startswith(f, 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):
                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
        
        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)
            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)