Example #1
0
    def do_new(self, arg):
        '''Add new password to current category. You will be prompted to enter
fields.

Syntax:
    new [-p | -t]

    -p - Get properties by parsing provided text. Will open default text editor
         for you to paste text in. Mutually exclusive with -t option. 
    -t - Display editor template in default text editor. Mutually exclusive with -p option.
'''
        new_pass = FigaroPassword() # FIXME: Password type shouldn't be hardcoded.
        argv = arg.split()

        if   "-p" in argv and "-t" in argv:
            print _("new: -p and -t arguments are mutually exclusive.")          
            print _("try 'help new' for more information")
        elif "-p" in argv:
            text = self.getEditorInput()
            choosendict = parser.parseMessage(text, self.conf.patterns)
            new_pass.update(choosendict)
        elif "-t" in argv:
            text = self.getEditorInput(new_pass.asEditText())
            choosendict = parser.parseMessage(text, [new_pass.getEditPattern()])
            new_pass.update(choosendict)

        try:
            self.editPassword(new_pass)
        except (KeyboardInterrupt, EOFError):
            self.printMessage(_("Cancelled"))
        else:
            tree = self.getCwd()
            tree.addNode(new_pass)
            self.tryToSave()
Example #2
0
    def do_new(self, arg):
        '''Add new password to current category. You will be prompted to enter
fields.

Syntax:
    new [-p]

    -p - Get properties by parsing provided text. Will open default text editor
         for you to paste text in.
'''
        new_pass = FigaroPassword(
        )  # FIXME: Password type shouldn't be hardcoded.
        argv = arg.split()

        if "-p" in argv:
            text = self.getEditorInput()
            choosendict = parser.parseMessage(text, self.conf.patterns)
            new_pass.update(choosendict)

        try:
            self.editPassword(new_pass)
        except (KeyboardInterrupt, EOFError):
            print "Cancelled"
        else:
            tree = self.getCwd()
            tree.addNode(new_pass)
            self.tryToSave()
Example #3
0
 def process(self, resp_id):
     patterns = globals.app.conf.patterns
     buf = self['text'].get_buffer()
     b_start, b_end = buf.get_bounds()
     text = buf.get_text(b_start, b_end, False)
     self.parseddict = parseMessage(text, patterns)
     return True
Example #4
0
    def do_new(self, arg):
        '''Add new password to current category. You will be prompted to enter
fields.

Syntax:
    new [-p | -t]

    -p - Get properties by parsing provided text. Will open default text editor
         for you to paste text in. Mutually exclusive with -t option. 
    -t - Display editor template in default text editor. Mutually exclusive with -p option.

    If the config option 'force-editor is set, this command defaults to the -t option when no options are provided.
'''
        new_pass = FigaroPassword(
        )  # FIXME: Password type shouldn't be hardcoded.

        argv = arg.split()

        use_visual_editor = len(
            argv) == 0 and self.conf.options["force-editor"]

        if "-p" in argv and "-t" in argv:
            print _("new: -p and -t arguments are mutually exclusive.")
            print _("try 'help new' for more information")
        elif "-p" in argv:
            text = self.getEditorInput()
            choosendict = parser.parseMessage(text, self.conf.patterns)
            new_pass.update(choosendict)
        elif "-t" in argv or use_visual_editor:
            text = self.getEditorInput(new_pass.asEditText())
            choosendict = parser.parseMessage(text,
                                              [new_pass.getEditPattern()])
            new_pass.update(choosendict)

        try:
            if not use_visual_editor:
                self.editPassword(new_pass)
        except (KeyboardInterrupt, EOFError):
            self.printMessage(_("Cancelled"))
        else:
            tree = self.getCwd()
            tree.addNode(new_pass)
            self.tryToSave()
Example #5
0
 def test_parseMessage(self):
     texts = ["username/password: actualuser/actualpassword",
     """Username : actualuser
     Password    : actualpassword""",
     "user: actualuser pass:actualpassword"
     ]
     result = {'password': '******', 'user': '******'}
     for text in texts:
         dict = parser.parseMessage(text, parser.patterns)
         self.assertEqual(dict, result)
Example #6
0
 def test_parseMessage(self):
     texts = [
         "username/password: actualuser/actualpassword",
         """Username : actualuser
     Password    : actualpassword""", "user: actualuser pass:actualpassword"
     ]
     result = {'password': '******', 'user': '******'}
     for text in texts:
         dict = parser.parseMessage(text, parser.patterns)
         self.assertEqual(dict, result)
Example #7
0
    def do_import(self, arg):
        '''Imports new password records into current category.
Syntax:
    import
    
    Get properties by parsing provided text. Will open default text editor
    for you to paste text in.
'''
        argv = arg.split()
        tree = self.getCwd()

        text = self.getEditorInput()
        for line in text.split("\n"):
            new_pass = FigaroPassword() # FIXME: Password type shouldn't be hardcoded.
            choosendict = parser.parseMessage(line, self.conf.patterns)
            new_pass.update(choosendict)
            tree.addNode(new_pass)

        self.tryToSave()
Example #8
0
    def do_edit(self, arg):
        """edit password information.

Syntax:
    edit [-p] <regexp>

Prompts the user to edit a password item in the current category.
If <regexp> matches multiple items, the list of matches will be printed
and user is prompted to select one.

If the optional '-p' flag is specified or the 'force-editor' config option is set,
the password will be edited using the editor specified in the VISUAL or EDITOR
environment variables, defaulting to "vi" if neither is found.
Otherwise the user is prompted to edit each entry of the password entry on the command line.

"""
        argv = arg.split()

        if argv and argv[0] == "-p":
            use_editor = True
            arg = self.shiftArgv(argv)
        elif self.conf.options["force-editor"]:
            use_editor = True
        else:
            use_editor = False

        selected_password = self.pickPassword(arg)

        if selected_password:
            try:
                if use_editor:
                    text = self.getEditorInput(selected_password.asEditText())
                    patterns = [selected_password.getEditPattern()]
                    chosendict = parser.parseMessage(text, patterns)
                    selected_password.update(chosendict)
                else:
                    self.editPassword(selected_password)

                self.tryToSave()
            except (KeyboardInterrupt, EOFError):
                self.printMessage(_("Cancelled"))
        else:
            self.printMessage(_("No password selected"))
Example #9
0
    def do_edit(self, arg):
        '''edit password information.

Syntax:
    edit [-p] <regexp>

Prompts the user to edit a password item in the current category.
If <regexp> matches multiple items, the list of matches will be printed
and user is prompted to select one.

If the optional '-p' flag is specified or the 'force-editor' config option is set,
the password will be edited using the editor specified in the VISUAL or EDITOR
environment variables, defaulting to "vi" if neither is found.
Otherwise the user is prompted to edit each entry of the password entry on the command line.

'''
        argv = arg.split()

        if argv and argv[0] == '-p':
            use_editor = True
            arg = self.shiftArgv(argv)
        elif self.conf.options['force-editor']:
            use_editor = True
        else:
            use_editor = False

        selected_password = self.pickPassword(arg)

        if selected_password:
            try:
                if use_editor:
                    text = self.getEditorInput(selected_password.asEditText())
                    patterns = [selected_password.getEditPattern()]
                    chosendict = parser.parseMessage(text, patterns)
                    selected_password.update(chosendict)
                else:
                    self.editPassword(selected_password)

                self.tryToSave()
            except (KeyboardInterrupt, EOFError):
                self.printMessage(_("Cancelled"))
        else:
            self.printMessage(_("No password selected"))
Example #10
0
    def do_import(self, arg):
        '''Imports new password records into current category.
Syntax:
    import
    
    Get properties by parsing provided text. Will open default text editor
    for you to paste text in.
'''
        argv = arg.split()
        tree = self.getCwd()

        text = self.getEditorInput()
        for line in [x for x in text.splitlines() if x]:
            new_pass = FigaroPassword(
            )  # FIXME: Password type shouldn't be hardcoded.
            choosendict = parser.parseMessage(line, self.conf.patterns)
            new_pass.update(choosendict)
            tree.addNode(new_pass)

        self.tryToSave()
Example #11
0
 def process(self):
     patterns = globals.app.conf.patterns
     buf = self['text'].get_buffer()
     b_start, b_end = buf.get_bounds()
     text = buf.get_text(b_start, b_end, gtk.FALSE)
     self.parseddict = parseMessage(text, patterns)