Skip to content
Merged
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
7 changes: 7 additions & 0 deletions lieer/gmailieer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def main (self):
parser_pull.add_argument ('-d', '--dry-run', action='store_true',
default = False, help = 'do not make any changes')

parser_pull.add_argument ('-v', '--verbose', action='store_true',
default = False, help = 'print list of changes')

parser_pull.add_argument ('-f', '--force', action = 'store_true',
default = False, help = 'Force a full synchronization to be performed')

Expand All @@ -86,6 +89,9 @@ def main (self):
parser_push.add_argument ('-d', '--dry-run', action='store_true',
default = False, help = 'do not make any changes')

parser_push.add_argument ('-v', '--verbose', action='store_true',
default = False, help = 'print list of changes')

parser_push.add_argument ('-f', '--force', action = 'store_true',
default = False, help = 'Push even when there has been remote changes (might overwrite remote tag-changes)')

Expand Down Expand Up @@ -272,6 +278,7 @@ def setup (self, args, dry_run = False, load = False, block = False):
raise NotADirectoryError("error: %s is not a valid path!" % args.path)

self.dry_run = dry_run
self.verbose = args.verbose
self.HAS_TQDM = (not args.no_progress)
self.credentials_file = args.credentials

Expand Down
24 changes: 14 additions & 10 deletions lieer/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ def __init__ (self, g):
self.gmailieer = g
self.wd = os.getcwd ()
self.dry_run = g.dry_run
self.verbose = g.verbose

# config and state files for local repository
self.config_f = os.path.join (self.wd, '.gmailieer.json')
Expand Down Expand Up @@ -520,9 +521,9 @@ def remove (self, gid, db):
except LookupError:
nmsg = None

if self.dry_run:
print ("(dry-run) deleting %s: %s." % (gid, fname))
else:
self.print_changes ("deleting %s: %s." % (gid, fname))

if not self.dry_run:
if nmsg is not None:
db.remove(fname)
os.unlink (fname)
Expand Down Expand Up @@ -621,18 +622,16 @@ def update_tags (self, m, fname, db):
if not os.path.exists (fname):
raise Local.RepositoryException ("tried to update tags on non-existent file: %s" % fname)

else:
print ("(dry-run) tried to update tags on non-existent file: %s" % fname)
self.print_changes ("tried to update tags on non-existent file: %s" % fname)

try:
nmsg = db.get(fname)
except LookupError:
nmsg = None

if nmsg is None:
if self.dry_run:
print ("(dry-run) adding message: %s: %s, with tags: %s" % (gid, fname, str(labels)))
else:
self.print_changes ("adding message: %s: %s, with tags: %s" % (gid, fname, str(labels)))
if not self.dry_run:
try:
(nmsg, _) = db.add (fname, sync_flags = True)
except notmuch2.FileNotEmailError:
Expand Down Expand Up @@ -667,12 +666,17 @@ def update_tags (self, m, fname, db):
nmsg.tags.to_maildir_flags()
self.__update_cache__ (nmsg, (gid, fname))

else:
print ("(dry-run) changing tags on message: %s from: %s to: %s" % (gid, str(otags), str(labels)))
self.print_changes ("changing tags on message: %s from: %s to: %s" % (gid, str(otags), str(labels)))

return True
else:
return False

def print_changes (self, changes):
if self.dry_run:
print ("(dry-run) " + changes)
elif self.verbose:
print(changes)



9 changes: 8 additions & 1 deletion lieer/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def __init__ (self, g):
self.CLIENT_SECRET_FILE = g.credentials_file
self.account = g.local.config.account
self.dry_run = g.dry_run
self.verbose = g.verbose

self.ignore_labels = self.gmailieer.local.config.ignore_remote_labels

Expand Down Expand Up @@ -565,8 +566,8 @@ def update (self, gmsg, nmsg, last_hist, force):
print ("update: %s: Trying to add both SPAM and INBOX, dropping INBOX (add: %s, rem: %s)" % (gid, add, rem))
add.remove('INBOX')

self.print_changes ("gid: %s: add: %s, remove: %s" % (gid, str(add), str(rem)))
if self.dry_run:
print ("(dry-run) gid: %s: add: %s, remove: %s" % (gid, str(add), str(rem)))
return None
else:
return self.__push_tags__ (gid, add, rem)
Expand Down Expand Up @@ -739,3 +740,9 @@ def send (self, message, threadId = None):

return self.service.users().messages().send(userId = self.account, body = message).execute()

def print_changes (self, changes):
if self.dry_run:
print ("(dry-run) " + changes)
elif self.verbose:
print(changes)

1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class MockGmi:
dry_run = False
verbose = False

def __init__(self):
pass
Expand Down