pwman3 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. # ============================================================================
  3. # This file is part of Pwman3.
  4. #
  5. # Pwman3 is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License, version 2
  7. # as published by the Free Software Foundation;
  8. #
  9. # Pwman3 is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with Pwman3; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. # ============================================================================
  18. # Copyright (C) 2012-2014 Oz Nahum Tiram <nahumoz@gmail.com>
  19. # ============================================================================
  20. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  21. # ============================================================================
  22. from __future__ import print_function
  23. import sys
  24. from pwman import get_conf_options, get_db_version
  25. from pwman import parser_options
  26. from pwman.ui import get_ui_platform
  27. from pwman.ui.tools import CLICallback
  28. import pwman.data.factory
  29. from pwman.exchange.importer import Importer
  30. from pwman.util.crypto_engine import CryptoEngine
  31. if sys.version_info.major > 2:
  32. raw_input = input
  33. def main(args):
  34. PwmanCliNew, OSX = get_ui_platform(sys.platform)
  35. xselpath, dbtype, config = get_conf_options(args, OSX)
  36. dbver = get_db_version(config, dbtype, args)
  37. CryptoEngine.get(dbver)
  38. fname = config.get_value('Database', 'filename')
  39. db = pwman.data.factory.create(dbtype, dbver, fname)
  40. if args.import_file:
  41. importer = Importer(args, config, db)
  42. importer.run()
  43. sys.exit(0)
  44. cli = PwmanCliNew(db, xselpath, CLICallback, config)
  45. try:
  46. cli.cmdloop()
  47. except KeyboardInterrupt as e:
  48. print(e)
  49. if __name__ == '__main__':
  50. args = parser_options().parse_args()
  51. main(args)