Commits

Marcin Kasperski committed f893cc4

Porting to keyring-based password storage, cleaning things moved to mekk.nozbe

Comments (0)

Files changed (4)

 
 from setuptools import setup, find_packages
 
-version = '0.3.0'
+version = '0.4.0'
 long_description = open("README.txt").read()
 classifiers = [
     "Programming Language :: Python",

src/mekk/nozbe2xmind/__init__.py

 from xmind_writer import nozbe_to_xmind
-from csv_writer import nozbe_to_csv
-from nozbe import NozbeLegacyApi, NozbeSyncApi, NozbeApi, CachingNozbeApi

src/mekk/nozbe2xmind/run.py

 usage = """
 Generating XMind mind-map with your Nozbe projects and tasks:
 
-    %prog download --map=file.xmind --key=<your api key>
+    %prog download --map=file.xmind --user=<your nozbe username>
 
 Listing changes you made on this mind-map (what-happened):
 
 Uploading changes made on the mind-map (don't do it twice or
 you will add the same actions twice!):
 
-    %prog upload --map=file.xmind --key=<your api key>
-
-Bonus: downloading tasks to CSV file:
-    %prog download --csv=file.csv --key=<your api key>
-or do both map and CSV:
-    %prog download --map=file.xmind --csv=file.csv --key=<your api key>
+    %prog upload --map=file.xmind --user=<your nozbe username>
 
 """
 
     from optparse import OptionParser
     opt_parser = OptionParser(
                               usage=usage)
-    opt_parser.add_option("-k", "--key",
-                          action="store", type="string", dest="key",
-                          help ="Your Nozbe API key (see bottom of http://www.nozbe.com/account/extras)")
+    opt_parser.add_option("-u", "--user",
+                          action="store", type="string", dest="user",
+                          help ="Your Nozbe username")
     opt_parser.add_option("-m", "--map",
                           action="store", type="string", dest="map",
                           help="The name of the output XMind file")
-    opt_parser.add_option("", "--csv",
-                          action="store", type="string", dest="csv",
-                          help="The name of the output CSV file")
     opt_parser.add_option("-c", "--completed",
                           action="store_true", dest = "completed",
                           help = "Include completed tasks (not downloaded by default)")
     if not operation in ['download', 'info', 'upload']:
         opt_parser.error("Invalid operation: %s. Expected: download, info, or upload" % operation)
 
-    if (operation in ['download', 'upload']) and not opts.key:
-        opt_parser.error("This operation requires --key=<your-api-key>")
+    if (operation in ['download', 'upload']) and not opts.user:
+        opt_parser.error("This operation requires --user=<your-nozbe-username>")
     if (operation in ['info', 'upload']):
         if not opts.map:
             opt_parser.error("This operation requires --map=your-xmind-file")
         if not os.path.isfile(opts.map):
             opt_parser.error("File %s does not exist" % opts.map)
     if operation == 'download':
-        if not (opts.csv or opts.map):
-            opt_parser.error("This operation requires --map=<created-xmind-file> or --csv=<created-csv-file> (or both)")
+        if not opts.map:
+            opt_parser.error("This operation requires --map=<created-xmind-file>")
 
     if opts.devel:
         import re
 
 operation, options = parse_options()
 
-from mekk.nozbe2xmind import nozbe_to_xmind, nozbe_to_csv, NozbeApi, CachingNozbeApi
+from mekk.nozbe2xmind import nozbe_to_xmind, nozbe_to_csv, NozbeApi, CachingNozbeApi, NozbeKeyringConnection
 from mekk.nozbe2xmind.run_analysis import upload_changes, print_changes_info
 from twisted.internet import reactor, defer
 import logging
 @defer.inlineCallbacks
 def main():
     try:
+        if operation in ['download', 'upload']:
+            connection = NozbeKeyringConnection(options.user, options.devel)
+
         if operation == "download":
-            if options.map and options.csv:
-                api = CachingNozbeApi(options.key, options.devel)
-            else:
-                api = NozbeApi(options.key, options.devel)
-            if options.map:
-                yield nozbe_to_xmind(api, options.map, options.devel, options.completed)
-                print "XMind map saved to %s" % options.map
-            if options.csv:
-                yield nozbe_to_csv(api, options.csv, options.devel, options.completed)
-                print "CSV file saved to %s" % options.csv
+            api = CachingNozbeApi(connection)
+            yield nozbe_to_xmind(api, options.map, options.devel, options.completed)
+            print "XMind map saved to %s" % options.map
         elif operation == "info":
             print_changes_info(options.map)
         elif operation == "upload":
-            yield upload_changes(NozbeApi(options.key, options.devel), options.map)
+            api = NozbeApi(connection)
+            yield upload_changes(api, options.map)
         else:
             raise Exception("Unknown operation")
-        
-    #except Exception, e:
-    #    print "Failed: ", e
+    except Exception, e:
+        if options.verbose:
+            raise
+        else:
+            print "Failure: ", e
     finally:
         reactor.stop()
 

src/mekk/nozbe2xmind/xmind_writer.py

 # (c) 2008, Marcin Kasperski
 
 from mekk.xmind import XMindDocument, XMIND_MARKS
-from nozbe import NozbeApi
+from mekk.nozbe import NozbeApi
 import simplejson
 from twisted.internet import defer
 import context_icons