importer.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # ============================================================================
  2. # This file is part of Pwman3.
  3. #
  4. # Pwman3 is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License, version 2
  6. # as published by the Free Software Foundation;
  7. #
  8. # Pwman3 is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with Pwman3; if not, write to the Free Software
  15. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. # ============================================================================
  17. # Copyright (C) 2014 Oz Nahum Tiram <nahumoz@gmail.com>
  18. # ============================================================================
  19. '''
  20. A module to hold the importer class
  21. '''
  22. class BaseImporter(object):
  23. """
  24. The base class which defines the action needed to import data
  25. to pwman database
  26. """
  27. def __init__(self):
  28. pass
  29. class CSVImporter(BaseImporter):
  30. """
  31. A reference implementation which imports a CSV to the pwman database
  32. """
  33. def __init__(self, args, config):
  34. self.args = args
  35. self.config = config
  36. def _read_file(self):
  37. return []
  38. def _create_node(self, row):
  39. pass
  40. def runner(self):
  41. for row in self._read_file():
  42. self._create_node()
  43. class Importer(object):
  44. """
  45. The actual job runner which by default runs a csv importer instance.
  46. This could be changes by calling other instance which for example import
  47. from KeePass XML or other formats.
  48. """
  49. def __init__(self, invoke=CSVImporter):
  50. self.runner = invoke()
  51. def run(self):
  52. self.runner()