diff --git a/README.rst b/README.rst index db114dc..3b4d300 100644 --- a/README.rst +++ b/README.rst @@ -535,6 +535,12 @@ Synchronisation is performed by comparing the date and time of source and destination files. Files are copied if the source is newer than the destination. +Synchronisation can be configured to ignore files such as documents, +usually to conserve space on the destination. This is done by means +of a file named .rsync-ignore. This should comprise a list of files +and/or subdirectories with each item on a separate line. If such a +file is found in a source directory, items found in the file's +directory that match its contents will not be synchronised. shell ----- diff --git a/rshell/main.py b/rshell/main.py index 5bb5b7a..3a3a80c 100755 --- a/rshell/main.py +++ b/rshell/main.py @@ -147,6 +147,8 @@ RTS = '' DTR = '' +IGFILE_NAME = '.rshell-ignore' + # It turns out that just because pyudev is installed doesn't mean that # it can actually be used. So we only bother to try if we're running # under linux. @@ -875,6 +877,21 @@ def rsync(src_dir, dst_dir, mirror, dry_run, print_func, recursed, sync_hidden): for name, stat in src_files: d_src[name] = stat + # Check source for an ignore file + all_src = auto(listdir_stat, src_dir, show_hidden=True) + igfiles = [x for x in all_src if x[0] == IGFILE_NAME] + set_ignore = set() + if len(igfiles): + igfile, mode = igfiles[0] + if mode_isfile(stat_mode(mode)): + with open(src_dir + '/' + igfile, 'r') as f: + for line in f.readlines(): + line = line.strip() + if line: + set_ignore.add(line) + else: + print_err('Ignore file "{:s}" is not a file'.format(IGFILE_NAME)) + d_dst = {} dst_files = auto(listdir_stat, dst_dir, show_hidden=sync_hidden) if dst_files is None: # Directory does not exist @@ -885,7 +902,7 @@ def rsync(src_dir, dst_dir, mirror, dry_run, print_func, recursed, sync_hidden): d_dst[name] = stat set_dst = set(d_dst.keys()) - set_src = set(d_src.keys()) + set_src = set(d_src.keys()) - set_ignore to_add = set_src - set_dst # Files to copy to dest to_del = set_dst - set_src # To delete from dest to_upd = set_dst.intersection(set_src) # In both: may need updating @@ -2647,6 +2664,9 @@ def do_shell(self, line): ), ) + def complete_rsync(self, text, line, begidx, endidx): + return self.filename_complete(text, line, begidx, endidx) + def do_rsync(self, line): """rsync [-m|--mirror] [-n|--dry-run] [-q|--quiet] SRC_DIR DEST_DIR