Ejemplo n.º 1
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 = [utils.normalize_path(x) for x in 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 f.startswith(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))
Ejemplo n.º 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 = [utils.normalize_path(x) for x in 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 f.startswith(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))
Ejemplo n.º 3
0
def mtime_upload(action_id, params, cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})

    action_type = 'configfiles.mtime_upload'
    if not _local_permission_check(action_type):
        log_to_file(0, "permissions error: " + str(action_type))
        return _perm_error(action_type)

    _init()

    file_matches = []
    now = time.time()
    upload_contents = None
    ignore_dirs = {'/proc': None, '/dev': None}

    if params['info']['import_contents'] == 'Y':
        upload_contents = 1

    for to_ignore in params['ignore']:
        ignore_dirs[utils.normalize_path(to_ignore)] = 1

    for search_path in params['search']:
        for dirname, dirs, names in os.walk(utils.normalize_path(search_path)):
            _visit_dir(
                {
                    'matches': file_matches,
                    'info': params['info'],
                    'ignore': ignore_dirs,
                    'now': now,
                }, dirname, names)

    if not file_matches:
        return 0, "No files found", {}

    r = rpc_cli_repository.ClientRepository()
    result = r.put_files(action_id,
                         file_matches,
                         upload_contents=upload_contents)

    formatted_result = format_result(result, file_matches)
    log_to_file(0, formatted_result)
    return formatted_result
Ejemplo n.º 4
0
def mtime_upload(action_id, params, cache_only=None):
    if cache_only:
        return (0, "no-ops for caching", {})

    action_type = 'configfiles.mtime_upload'
    if not _local_permission_check(action_type):
        log_to_file(0, "permissions error: " + str(action_type))
        return _perm_error(action_type)

    _init()

    file_matches = []
    now = time.time()
    upload_contents = None
    ignore_dirs = {'/proc':None, '/dev':None}

    if params['info']['import_contents'] == 'Y':
        upload_contents = 1

    for to_ignore in params['ignore']:
        ignore_dirs[utils.normalize_path(to_ignore)] = 1

    for search_path in params['search']:
        for dirname, dirs, names in os.walk(utils.normalize_path(search_path)):
             _visit_dir({
                'matches' : file_matches,
                'info' : params['info'],
                'ignore' : ignore_dirs,
                'now' : now,
                }, dirname, names)

    if not file_matches:
        return 0, "No files found", {}

    r = rpc_cli_repository.ClientRepository()
    result = r.put_files(action_id, file_matches, upload_contents=upload_contents)

    formatted_result = format_result(result, file_matches)
    log_to_file(0, formatted_result)
    return formatted_result
Ejemplo n.º 5
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 = [utils.normalize_path(x) for x in 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 f.startswith(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 xmlrpclib.Fault:
                e = sys.exc_info()[1]
                if e.faultCode == -4011:
                    print("%s does not exist" % remote_file)
                    continue
                raise
            else:
                print("%s removed" % remote_file)
    def run(self):
        log_debug(2)
        #5/12/05 wregglej - 149034 changed r into a instance variable
        self.r = self.repository

        topdir = self.options.topdir
        if not topdir:
            die(7, "--topdir not specified")

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

        topdir = utils.normalize_path(topdir)

        #5/12/05 wregglej - 149034 allowing the channel name and the directory name to vary independently.
        if not self.options.channel is None:
            #Get the list of channels with leading and trailing whitespace removed.
            channels = [
                x.strip() for x in self.options.channel.split(',') if x
            ]

            #Get the list of directories to upload. At this point it's the list of arguments.
            dirs = self.args
        elif not self.args:
            #If we get to this point, then --channel wasn't used and nothing was included as arguments.
            #Assumes that the directories in topdir are the ones we want to upload, and since no channels were
            #specified that each directory is it's own channel.
            channels = os.listdir(topdir)
            dirs = None
            print("No config channels specified, using %s" % channels)
        else:
            #At this point, --channel wasn't used but there was something included as an argument.
            #The name of the channel is assumed to be the same as the name of the directory.
            channels = self.args
            dirs = None

        #If dirs isn't None, then each directory needs to be uploaded into each channel.
        if dirs:
            for channel in channels:
                for directory in dirs:
                    self.upload_config_channel(topdir, channel, directory)
        #If dirs is None, then each channel is it's own channel.
        else:
            for channel in channels:
                self.upload_config_channel(topdir, channel, channel)
Ejemplo n.º 7
0
    def run(self):
        log_debug(2)
        #5/12/05 wregglej - 149034 changed r into a instance variable
        self.r = self.repository

        topdir = self.options.topdir
        if not topdir:
            die(7, "--topdir not specified")

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

        topdir = utils.normalize_path(topdir)

        #5/12/05 wregglej - 149034 allowing the channel name and the directory name to vary independently.
        if not self.options.channel is None:
            #Get the list of channels with leading and trailing whitespace removed.
            channels = map(string.strip, string.split(self.options.channel,','))

            #Get the list of directories to upload. At this point it's the list of arguments.
            dirs = self.args
        elif not self.args:
            #If we get to this point, then --channel wasn't used and nothing was included as arguments.
            #Assumes that the directories in topdir are the ones we want to upload, and since no channels were
            #specified that each directory is it's own channel.
            channels = os.listdir(topdir)
            dirs = None
            print "No config channels specified, using %s" % channels
        else:
            #At this point, --channel wasn't used but there was something included as an argument.
            #The name of the channel is assumed to be the same as the name of the directory.
            channels = self.args
            dirs = None

        #If dirs isn't None, then each directory needs to be uploaded into each channel.
        if dirs:
            for channel in channels:
                for directory in dirs:
                    self.upload_config_channel(topdir, channel, directory)
        #If dirs is None, then each channel is it's own channel.
        else:
            for channel in channels:
                self.upload_config_channel(topdir, channel, channel)
Ejemplo n.º 8
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 = [utils.normalize_path(x) for x in 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 f.startswith(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 xmlrpclib.Fault:
                e = sys.exc_info()[1]
                if e.faultCode == -4011:
                    print("%s does not exist" % remote_file)
                    continue
                raise
            else:
                print("%s removed" % remote_file)
Ejemplo n.º 9
0
 def _normalize_path_to_root(self, path):
     if self.transaction_root:
         path = utils.normalize_path(self.transaction_root + os.sep + path)
     return path
Ejemplo n.º 10
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 = [utils.normalize_path(x) for x in 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 = sys.exc_info()[1]
                log_error("Error: %s is already in channel %s" %
                          (remote_file, channel))
            except cfg_exceptions.RepositoryFilePushError:
                e = sys.exc_info()[1]
                log_error("Error pushing file:  %s" % e)
            else:
                print("Local file %s -> remote file %s" % (local_file, remote_file))
Ejemplo n.º 11
0
 def _normalize_path_to_root(self, path):
     if self.transaction_root:
         path = utils.normalize_path(self.transaction_root + os.sep + path)
     return path
Ejemplo n.º 12
0
 def get_dest_file(self, file):
     target_dir = self.options.topdir or os.sep
     return utils.normalize_path(target_dir + os.sep + file)
Ejemplo n.º 13
0
 def get_dest_file(self, file):
     target_dir = os.sep
     return utils.normalize_path(target_dir + os.sep + file)
Ejemplo n.º 14
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 = [utils.normalize_path(x) for x in 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 = sys.exc_info()[1]
                log_error("Error: %s is already in channel %s" %
                          (remote_file, channel))
            except cfg_exceptions.RepositoryFilePushError:
                e = sys.exc_info()[1]
                log_error("Error pushing file:  %s" % e)
            else:
                print("Local file %s -> remote file %s" %
                      (local_file, remote_file))
Ejemplo n.º 15
0
 def get_dest_file(self, file):
     target_dir = self.options.topdir or os.sep
     return utils.normalize_path(target_dir + os.sep + file)
Ejemplo n.º 16
0
 def get_dest_file(self, file):
     target_dir = os.sep
     return utils.normalize_path(target_dir + os.sep + file)