importer.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. import csv
  23. class BaseImporter(object):
  24. """
  25. The base class which defines the action needed to import data
  26. to pwman database
  27. """
  28. def __init__(self):
  29. pass
  30. class CSVImporter(BaseImporter):
  31. """
  32. A reference implementation which imports a CSV to the pwman database
  33. """
  34. def __init__(self, args, config):
  35. self.args = args
  36. self.config = config
  37. def _read_file(self):
  38. return []
  39. def _create_node(self, row):
  40. pass
  41. def runner(self):
  42. for row in self._read_file():
  43. self._create_node()
  44. class Importer(object):
  45. """
  46. The actual job runner which by default runs a csv importer instance.
  47. This could be changes by calling other instance which for example import
  48. from KeePass XML or other formats.
  49. """
  50. def __init__(self, invoke=CSVImporter):
  51. self.runner = invoke()
  52. def run(self):
  53. self.runner()