pwman3 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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.tools import CLICallback
  27. import pwman.data.factory
  28. from pwman.exchange.importer import Importer
  29. from pwman.util.crypto_engine import CryptoEngine
  30. if sys.version_info.major > 2:
  31. raw_input = input
  32. def get_ui_platform(platform): # pragma: no cover
  33. if 'darwin' in platform:
  34. from pwman.ui.mac import PwmanCliMac as PwmanCli
  35. OSX = True
  36. elif 'win' in platform:
  37. from pwman.ui.win import PwmanCliWin as PwmanCli
  38. OSX = False
  39. else:
  40. from pwman.ui.cli import PwmanCli
  41. OSX = False
  42. return PwmanCli, OSX
  43. def main(args):
  44. PwmanCli, OSX = get_ui_platform(sys.platform)
  45. xselpath, dbtype, config = get_conf_options(args, OSX)
  46. dbver = get_db_version(config, args)
  47. CryptoEngine.get()
  48. dburi = config.get_value('Database', 'dburi')
  49. db = pwman.data.factory.createdb(dburi, dbver)
  50. if args.import_file:
  51. importer = Importer((args, config, db))
  52. importer.run()
  53. sys.exit(0)
  54. cli = PwmanCli(db, xselpath, CLICallback, config)
  55. try:
  56. cli.cmdloop()
  57. except KeyboardInterrupt as e:
  58. print(e)
  59. finally:
  60. config.save()
  61. if __name__ == '__main__':
  62. args = parser_options().parse_args()
  63. main(args)