base.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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) 2013 Oz Nahum <nahumoz@gmail.com>
  18. # ============================================================================
  19. # pylint: disable=I0011
  20. """
  21. Define the base CLI interface for pwman3
  22. """
  23. from __future__ import print_function
  24. import sys
  25. if sys.version_info.major > 2: # pragma: no cover
  26. raw_input = input
  27. class HelpUIMixin(object): # pragma: no cover
  28. """
  29. this class holds all the UI help functionality.
  30. in PwmanCliNew. The later inherits from this class
  31. and allows it to print help messages to the console.
  32. """
  33. def usage(self, string):
  34. print ("Usage: %s" % (string))
  35. def help_open(self):
  36. self.usage("open <ID>")
  37. print ("Launch default browser with 'xdg-open url',\n",
  38. "the url must contain http:// or https://.")
  39. def help_o(self):
  40. self.help_open()
  41. def help_copy(self):
  42. self.usage("copy <ID>")
  43. print ("Copy password to X clipboard (xsel required)")
  44. def help_cp(self):
  45. self.help_copy()
  46. def help_cls(self):
  47. self.usage("cls")
  48. print ("Clear the Screen from information.")
  49. def help_list(self):
  50. self.usage("list <tag> ...")
  51. print ("List nodes that match current or specified filter.",
  52. " ls is an alias.")
  53. def help_EOF(self):
  54. self.help_exit()
  55. def help_delete(self):
  56. self.usage("delete <ID|tag> ...")
  57. print ("Deletes nodes. rm is an alias.")
  58. self._mult_id_help()
  59. def help_h(self):
  60. self.help_help()
  61. def help_help(self):
  62. self.usage("help [topic]")
  63. print ("Prints a help message for a command.")
  64. def help_e(self):
  65. self.help_edit()
  66. def help_n(self):
  67. self.help_new()
  68. def help_p(self):
  69. self.help_print()
  70. def help_l(self):
  71. self.help_list()
  72. def help_edit(self):
  73. self.usage("edit <ID|tag> ... ")
  74. print ("Edits a nodes.")
  75. def help_import(self):
  76. self.usage("import [filename] ...")
  77. print ("Not implemented...")
  78. def help_export(self):
  79. self.usage("export [{'filename': 'foo.csv', 'delimiter':'|'}] ")
  80. print("All nodes under the current filter are exported.")
  81. def help_new(self):
  82. self.usage("new")
  83. print ("Creates a new node.,",
  84. "You can override default config settings the following way:\n",
  85. "pwman> n {'leetify':False, 'numerics':True}")
  86. def help_rm(self):
  87. self.help_delete()
  88. def help_print(self):
  89. self.usage("print <ID|tag> ...")
  90. print ("Displays a node. ")
  91. self._mult_id_help()
  92. def _mult_id_help(self):
  93. print("Multiple ids and nodes can be specified, separated by a space.",
  94. " A range of ids can be specified in the format n-N. e.g. ",
  95. " '10-20' would specify all nodes having ids from 10 to 20 ",
  96. " inclusive. Tags are considered one-by-one. e.g. 'foo 2 bar'",
  97. " would yield to all nodes with tag 'foo', node 2 and all ",
  98. " nodes with tag 'bar'.")
  99. def help_exit(self):
  100. self.usage("exit")
  101. print("Exits the application.")
  102. def help_passwd(self):
  103. self.usage("passwd")
  104. print("Changes the password on the database. ")
  105. def help_forget(self):
  106. self.usage("forget")
  107. print("Forgets the database password. Your password will need to ",
  108. "be reentered before accessing the database again.")
  109. def help_clear(self):
  110. self.usage("clear")
  111. print("Clears the filter criteria. ")
  112. def help_filter(self):
  113. self.usage("filter <tag> ...")
  114. print("Filters nodes on tag. Arguments can be zero or more tags. ",
  115. "Displays current tags if called without arguments.")
  116. def help_tags(self):
  117. self.usage("tags")
  118. print("Displays all tags in used in the database.")
  119. class AliasesMixin(object): # pragma: no cover
  120. """
  121. Define all the alias you want here...
  122. """
  123. def do_cp(self, args):
  124. self.do_copy(args)
  125. def do_e(self, arg):
  126. self.do_edit(arg)
  127. def do_EOF(self, args):
  128. return self.do_exit(args)
  129. def do_l(self, args):
  130. self.do_list(args)
  131. def do_ls(self, args):
  132. self.do_list(args)
  133. def do_p(self, arg):
  134. self.do_print(arg)
  135. def do_rm(self, arg):
  136. self.do_delete(arg)
  137. def do_o(self, args):
  138. self.do_open(args)
  139. def do_h(self, arg):
  140. self.do_help(arg)
  141. def do_n(self, arg):
  142. self.do_new(arg)