Oben Sonne avatar Oben Sonne committed 325da7c

Whitespace cleanup

Comments (0)

Files changed (1)

 
 class preset:
     """Preset user input. Used for non-interactive testing mode."""
-    
+
     proceed = None
     password = None
     epath = None
        %prog --add ENCFS-PATH MOUNT-POINT
        %prog --edit MOUNT-POINT
        %prog --remove MOUNT-POINT"""
-       
+
 DESCRIPTION = """Painlessly mount and manage EncFS folders using GNOME's
 keyring."""
 
 
 def _options():
     """Parse command line options."""
-    
+
     op = optparse.OptionParser(usage=USAGE, version=VERSION,
                                description=DESCRIPTION, epilog=EPILOG)
-    
+
     op.add_option("-l", "--list", action="store_true", default=False,
                   help="list all EncFS items stored in keyring")
     op.add_option("-m", "--mount", action="store_true", default=False,
                   help="edit an EncFS item in keyring")
     op.add_option("-r", "--remove", action="store_true", default=False,
                   help="remove an EncFS item from keyring")
-    
+
     og = optparse.OptionGroup(op, "Non-interactive")
     og.add_option("", "--proceed", default=None,
                   help="Input for proceed question")
     og.add_option("", "--amount", default=None,
                   help="Input for auto mount question")
     op.add_option_group(og)
-    
+
     opts, args = op.parse_args()
-    
+
     try:
         args.remove("autostart")
         opts.autostart = True
         opts.mount = True
     except ValueError:
         opts.autostart = False
-    
+
     if opts.list + opts.mount + opts.add + opts.edit + opts.remove != 1:
         op.print_help()
         op.exit(1)
-    
+
     # normalize paths
     args = [_pathify(a) for a in args]
-    
+
     opts.p1 = args and args.pop(0) or None
     opts.p2 = args and args.pop(0) or None
-    
+
     if opts.add and not (opts.p1 and opts.p2):
         op.error("add needs an EncFS path and a moint point")
         op.print_help()
         op.exit(1)
-        
+
     if opts.remove and not opts.p1:
         op.error("remove needs a moint point")
         op.print_help()
         op.exit(1)
-    
+
     preset.proceed = opts.proceed
     preset.password = opts.password
     preset.epath = opts.epath
     preset.mpoint = opts.mpoint
     preset.amount = opts.amount
-    
+
     return opts
 
 def _exit(ec):
     """Exit with additional check if autostart file is still needed."""
-    
+
     _autostart(_get_items(amount="y"))
     sys.exit(ec)
 
         _exit(2)
 
 def _pathify(path):
-    
+
     path = os.path.expanduser(path)
     path = os.path.expandvars(path)
     path = os.path.abspath(path)
 
 def _is_mounted(mpoint):
     """Check of something is mounted at given mount point."""
-    
+
     p = subprocess.Popen(["mount"], stdout=subprocess.PIPE)
     mount = p.communicate()[0]
     lines = mount.strip('\n').split('\n')
 
 def _is_encfs(epath):
     """Check if 'epath' points to an EncFS directory."""
-    
+
     p = subprocess.Popen(["encfsctl", "info", epath], stdout=subprocess.PIPE,
                          stderr=subprocess.PIPE)
     p.communicate()
 
 def _get_items(mpoint=None, epath=None, anypath=None, amount=None):
     """Get all EncFS items or those matching given attributes."""
-    
+
     global _items_cached
-    
+
     if _items_cached is None:
         try:
             _items_cached = gk.find_items_sync(ITYPE, GENCFS_ATTR)
         except gk.NoMatchError:
             _items_cached = []
-    
+
     match = []
     for item in _items_cached:
         if mpoint and item.attributes["mount-point"] != mpoint:
         if amount and item.attributes["auto-mount"] != amount:
             continue
         match.append(item)
-    
+
     return match
 
 def _autostart(enable):
     """Set up XDG autostart file."""
-    
+
     if TEST:
         fname = os.path.join(os.path.curdir, "autostart.desktop")
     else:
         if os.path.exists(fname):
             os.remove(fname)
         return
-    
+
     content = {
         "Exec": "gnome-encfs autostart",
         "Name": "EncFS",
         "Version": "1.0",
         "X-GNOME-Autostart-enabled": "true"
     }
-    
+
     de = xdg_de(filename=fname)
     for key, value in content.items():
         de.set(key, value)
 
 def list_items(path=None):
     """List EncFS items in keyring."""
-    
+
     items = _get_items(anypath=path)
 
     if not items and path:
         print("* encfs path     : %s" % epath)
         print("  mount point    : %s" % mpoint)
         print("  mount at login : %s" % (amount == "y" and "yes" or "no"))
-        
+
     return True
 
 def add_item(epath, mpoint):
     """Add new EncFS item to keyring."""
-    
+
     if not _is_encfs(epath):
         _proceed("no EncFS at given path")
     if not os.path.isdir(mpoint):
         _proceed("mount point is not a directory")
     if _get_items(mpoint=mpoint):
         _proceed("mount point already in keyring")
-    
+
     secret = preset.password or getpass.getpass("EncFS password: ")
     amount = preset.amount or raw_input("Mount at login [Y/n]: ") or "y"
     amount = amount.strip()[0].lower() == "y" and "y" or "n"
     attr.update(GENCFS_ATTR)
     name = "EncFS mount at %s" % mpoint
     gk.item_create_sync(KEYRING, ITYPE, name, attr, secret, False)
-    
+
     global _items_cached
     _items_cached = None
-    
+
     return True
 
 def edit_item(mpoint):
     """Edit EncFS item in keyring."""
-    
+
     items = _get_items()
     edits = _get_items(mpoint=mpoint)
-    
+
     if not edits:
         print(MSG_NO_MATCH)
         return False
 
     for item in edits:
-        
+
         # get item data
         epath = item.attributes["encfs-path"]
         mpoint = item.attributes["mount-point"]
         amount = amount.strip()[0].lower() == "y" and "y" or "n"
         mpoint = _pathify(mpoint)
         epath = _pathify(epath)
-        
+
         # check item data
         for other in [i for i in items if i.item_id != item.item_id]:
             if other.attributes["mount-point"] == mpoint:
         info = gk.item_get_info_sync(KEYRING, item.item_id)
         info.set_secret(secret)
         gk.item_set_info_sync(KEYRING, item.item_id, info)
-        
+
         global _items_cached
         _items_cached = None
-    
+
     return True
 
 def remove_item(mpoint):
     """Remove EncFS item from keyring."""
-    
+
     items = _get_items(mpoint=mpoint)
-    
+
     if not items:
         print(MSG_NO_MATCH)
         return False
 
     for item in items:
         gk.item_delete_sync(KEYRING, item.item_id)
-        
+
     global _items_cached
     _items_cached = None
 
 
 def mount_items(path, autostart):
     """Mount selected items.
-    
+
     If `path` is set, mount only those items where the EncFS path or mount
     point equals `path`. If `autostart` is True, mount only those items where
     auto-mount is set to 'y'.
-    
+
     """
     items = _get_items(anypath=path, amount=(autostart and "y" or None))
 
     if not items and path:
         print(MSG_NO_MATCH)
         return False
-    
+
     rc = True
 
     for item in items:
             p.communicate(input="%s\n" % item.secret)
             msg += p.returncode and "FAILED" or "OK"
             rc &= not p.returncode
-            
+
         print(msg)
 
     return rc
-            
+
 # =============================================================================
 # main
 # =============================================================================
 
 def main():
-    
+
     opts = _options()
-    
+
     if opts.add:
         ok = add_item(opts.p1, opts.p2)
     elif opts.list:
     return ok
     
 if __name__ == '__main__':
-    
+
     ret = main()
     _exit(int(not ret))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.