mac.py 2.8 KB

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