Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement .rsync-ignore file #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 .rshell-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
-----
Expand Down
22 changes: 21 additions & 1 deletion rshell/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down