mac.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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) 2012 Oz Nahum <nahumoz@gmail.com>
  18. # ============================================================================
  19. # Copyright (C) 2006 Ivan Kelly <ivan@ivankelly.net>
  20. # ============================================================================
  21. # pylint: disable=I0011
  22. from __future__ import print_function
  23. "all mac os related classes"
  24. from pwman.ui.cli import PwmanCli
  25. from pwman.ui import tools
  26. import time
  27. # pylint: disable=R0904
  28. class PwmanCliMac(PwmanCli):
  29. """
  30. inherit from PwmanCli, override the right functions...
  31. """
  32. def do_copy(self, args):
  33. ids = self._get_ids(args)
  34. if len(ids) > 1:
  35. print("Can only 1 password at a time...")
  36. try:
  37. node = self._db.getnodes(ids)
  38. node[0].get_password()
  39. tools.text_to_mcclipboard(node[0].get_password())
  40. print("copied password for {}@{} clipboard".format(
  41. node[0].get_username(), node[0].get_url()))
  42. time.sleep(10)
  43. tools.text_to_clipboards("")
  44. except Exception as e:
  45. self.error(e)
  46. def do_cp(self, args):
  47. self.do_copy(args)
  48. def do_open(self, args):
  49. ids = self._get_ids(args)
  50. if not args:
  51. self.help_open()
  52. return
  53. if len(ids) > 1:
  54. print("Can open only 1 link at a time ...")
  55. return None
  56. try:
  57. node = self._db.getnodes(ids)
  58. url = node[0].get_url()
  59. tools.open_url(url, macosx=True)
  60. except Exception as e:
  61. self.error(e)
  62. def do_o(self, args):
  63. self.do_open(args)
  64. ##
  65. # Help functions
  66. ##
  67. def help_open(self):
  68. self.usage("open <ID>")
  69. print("Launch default browser with 'open url',\n"
  70. "the url must contain http:// or https://.")
  71. def help_o(self):
  72. self.help_open()
  73. def help_copy(self):
  74. self.usage("copy <ID>")
  75. print("Copy password to Cocoa clipboard using pbcopy")
  76. def help_cp(self):
  77. self.help_copy()