changeset 42:7d28efc8dfa1

fix + bump
author Jeff Hammel <k0scist@gmail.com>
date Thu, 23 Feb 2017 09:35:11 -0800
parents c9d222b85e63
children 436d8e5ea294
files setup.py silvermirror/unify.py
diffstat 2 files changed, 16 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py	Thu Feb 23 09:10:58 2017 -0800
+++ b/setup.py	Thu Feb 23 09:35:11 2017 -0800
@@ -1,6 +1,6 @@
 from setuptools import setup
 
-version = '0.2.3'
+version = '0.3'
 
 setup(name='silvermirror',
       version=version,
--- a/silvermirror/unify.py	Thu Feb 23 09:10:58 2017 -0800
+++ b/silvermirror/unify.py	Thu Feb 23 09:35:11 2017 -0800
@@ -6,6 +6,7 @@
 
 import argparse
 import getpass
+import json
 import os
 import socket
 import subprocess
@@ -43,7 +44,7 @@
     except KeyError:
         raise KeyError("password must be True or False (You gave: '%s')" % password)
 
-    ### resources
+    # resources
     for resource in config:
 
         # directory of resource
@@ -62,15 +63,17 @@
             ignore += config[resource]['ignore'].split()
         config[resource]['ignore'] = ignore
 
-    ###
-    config = { 'main': main, 'resources': config }
-    return config
+    # return configuration
+    return  {'main': main, 'resources': config}
+
 
-def unify(conf, _resources, test=False, verbose=True, notification_prefix='\n*** SilverMirror; '):
+def unify(conf,
+          _resources,
+          test=False,
+          verbose=True,
+          notification_prefix='\n*** SilverMirror; '):
     """unify virtual filesystems given configuration"""
 
-    # TODO: -> OO
-
     # log function
     def log(message):
         if verbose:
@@ -109,7 +112,7 @@
     ### determine resources to sync
     cwd = os.path.realpath(os.getcwd())
     resources = conf['resources']
-    if 'all' not in _resources:
+    if (resources is None) or ('all' not in _resources):
         if _resources:
             resources = dict([(key, value) for key, value in resources.items()
                               if key in _resources])
@@ -122,6 +125,7 @@
     if test:
         log("Resources:\n")
         pprint(resources)
+        return
 
     # choose reflector backend
     reflectors = dict([(i.name, i.load()) for i in iter_entry_points('silvermirror.reflectors')])
@@ -141,6 +145,7 @@
     finally:
         os.chdir(cwd)
 
+
 def main(args=sys.argv[1:]):
     """CLI"""
 
@@ -155,7 +160,7 @@
                         action='store_true', default=False)
     parser.add_argument('-v', '--verbose',
                         action='store_true', default=False)
-    parser.add_argument('resources', nargs='*',
+    parser.add_argument('resources', nargs='*', default=None,
                         help="resources to sync, or all if omitted")
     options = parser.parse_args(args)
 
@@ -179,7 +184,7 @@
     conf['main']['password'] = options.password and conf['main']['password']
 
     # mirror all the things
-    unify(conf, args, options.test)
+    unify(conf, options.resources, test=options.test, verbose=options.verbose)
 
 if __name__ == '__main__':
     unify()