Add simple magic-folder leave command
authorDavid Stainton <dstainton415@gmail.com>
Thu, 5 Nov 2015 16:24:52 +0000 (17:24 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Wed, 2 Dec 2015 15:21:11 +0000 (15:21 +0000)
src/allmydata/scripts/magic_folder_cli.py

index 7b63a70d5b73c14df54fa8743a772941a4aaa121..098b2fcc42a22c1cb00da6f1861e38707f7f525f 100644 (file)
@@ -166,11 +166,28 @@ def join(options):
                    % (options.local_dir.encode('utf-8'),), mode="ab")
     return 0
 
+class LeaveOptions(BasedirOptions):
+    synopsis = ""
+    def parseArgs(self):
+        BasedirOptions.parseArgs(self)
+
+def leave(options):
+    dmd_cap_file = os.path.join(options["node-directory"], u"private", u"magic_folder_dircap")
+    collective_readcap_file = os.path.join(options["node-directory"], u"private", u"collective_dircap")
+    magic_folder_db_file = os.path.join(options["node-directory"], u"private", u"magicfolderdb.sqlite")
+    for f in [dmd_cap_file, collective_readcap_file, magic_folder_db_file]:
+        try:
+            os.remove(f)
+        except OSError,e:
+            pass
+    return 0
+
 class MagicFolderCommand(BaseOptions):
     subCommands = [
         ["create", None, CreateOptions, "Create a Magic Folder."],
         ["invite", None, InviteOptions, "Invite someone to a Magic Folder."],
         ["join", None, JoinOptions, "Join a Magic Folder."],
+        ["leave", None, LeaveOptions, "Leave a Magic Folder."],
     ]
     def postOptions(self):
         if not hasattr(self, 'subOptions'):
@@ -189,6 +206,7 @@ subDispatch = {
     "create": create,
     "invite": invite,
     "join": join,
+    "leave": leave,
 }
 
 def do_magic_folder(options):