Jelajahi Sumber

Prototype importer ...

oz123 10 tahun lalu
induk
melakukan
88cf1e3e59
3 mengubah file dengan 50 tambahan dan 13 penghapusan
  1. 1 0
      pwman/__init__.py
  2. 39 9
      pwman/exchange/importer.py
  3. 10 4
      scripts/pwman3

+ 1 - 0
pwman/__init__.py

@@ -88,6 +88,7 @@ def parser_options(formatter_class=argparse.HelpFormatter):
                         default=os.path.expanduser("~/.pwman/config"),
                         help='cofiguration file to read')
     parser.add_argument('-d', '--database', dest='dbase')
+    parser.add_argument('-i', '--import', dest='import_file', type=file)
     return parser
 
 

+ 39 - 9
pwman/exchange/importer.py

@@ -1,4 +1,4 @@
-#============================================================================
+# ============================================================================
 # This file is part of Pwman3.
 #
 # Pwman3 is free software; you can redistribute it and/or modify
@@ -13,13 +13,43 @@
 # You should have received a copy of the GNU General Public License
 # along with Pwman3; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#============================================================================
-# Copyright (C) 2012 Oz Nahum <nahumoz@gmail.com>
-#============================================================================
-#============================================================================
-# Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
-#============================================================================
-
+# ============================================================================
+# Copyright (C) 2014 Oz Nahum Tiram <nahumoz@gmail.com>
+# ============================================================================
 '''
-Not implemented yet
+A module to hold the importer class
 '''
+
+
+class BaseImporter(object):
+
+    """
+    The base class which defines the action needed to import data
+    to pwman database
+    """
+
+    def __init__(self):
+        pass
+
+
+class CSVImporter(BaseImporter):
+
+    """
+    A reference implementation which imports a CSV to the pwman database
+    """
+    def __init__(self):
+        pass
+
+
+class Importer(object):
+
+    """
+    The actual job runner which by default runs a csv importer instance.
+    This could be changes by calling other instance which for example import
+    from KeePass XML or other formats.
+    """
+    def __init__(self, invoke=CSVImporter):
+        self.runner = invoke
+
+    def run(self):
+        self.runner()

+ 10 - 4
scripts/pwman3

@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-#============================================================================
+# ============================================================================
 # This file is part of Pwman3.
 #
 # Pwman3 is free software; you can redistribute it and/or modify
@@ -14,11 +14,11 @@
 # You should have received a copy of the GNU General Public License
 # along with Pwman3; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#============================================================================
+# ============================================================================
 # Copyright (C) 2012-2014 Oz Nahum <nahumoz@gmail.com>
-#============================================================================
+# ============================================================================
 # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
-#============================================================================
+# ============================================================================
 from __future__ import print_function
 import sys
 from pwman import get_conf_options, get_db_version
@@ -37,6 +37,12 @@ def main(args):
     xselpath, dbtype, config = get_conf_options(args, OSX)
     dbver = get_db_version(config, dbtype, args)
     CryptoEngine.get(dbver)
+
+    if args.import_file:
+       importer = Importer(args, config)
+       importer.run()
+       sys.exit(0)
+
     fname = config.get_value('Database', 'filename')
     db = pwman.data.factory.create(dbtype, dbver, fname)
     cli = PwmanCliNew(db, xselpath, CLICallback, config)