Пример #1
0
 def fill(self):
     '''Launch an editor with a tempfile for filling in the item's content,
        then retrieve the content.'''
     # Look for a default editor using os.getenv
     envs = ['EDITOR', 'VISUAL']
     editor = None
     for env in envs:
         env = os.getenv(env)
         if env is not None:
             editor = env
             break
     if editor is None:
         editor = 'vim'
     # Launch the editor with a tempfile
     path = tempfile.mkstemp()[1]
     syscall = editor + ' ' + path
     os.system(syscall)
     if os.path.exists(path):
         fp = open(path, 'r')
         self.content = unicode(''.join([line for line in fp]))
         fp.close()
         return True
     else:
         print util.decorate('FAIL', 'Fatal: Operation Aborted.')
         return False
Пример #2
0
 def fill(self):
     '''Launch an editor with a tempfile for filling in the item's content,
        then retrieve the content.'''
     # Look for a default editor using os.getenv
     envs = ['EDITOR','VISUAL']
     editor = None
     for env in envs:
         env = os.getenv(env)
         if env is not None:
             editor = env
             break
     if editor is None:
         editor = 'vim'
     # Launch the editor with a tempfile 
     path = tempfile.mkstemp()[1]
     syscall = editor + ' ' + path
     os.system(syscall)
     if os.path.exists(path):
         fp = open(path,'r')
         self.content = unicode(''.join([line for line in fp]))
         fp.close()
         return True
     else:
         print util.decorate('FAIL','Fatal: Operation Aborted.')
         return False
Пример #3
0
 def matchIdentifier(self,identifier,quiet=False):
     '''Since entering partial identifier hashes is allowed, we need a way to match them'''
     values = (identifier + '%',)
     query = 'select hash from %s where hash like ?' % self.table
     if self.connected:
         self.cursor.execute(query,values)
         rows = self.cursor.fetchall()
         if len(rows) == 0:
             if not quiet:
                 print util.decorate('FAIL','Fatal: No identifier could be matched')
             return None 
         if len(rows) > 1:
             if not quiet:
                 print util.decorate('FAIL','Fatal: Supplied identifier has multiple matches, please be more specific.')
             return None 
         else:
             return str(rows[0][0])
Пример #4
0
 def matchIdentifier(self, identifier, quiet=False):
     """Since entering partial identifier hashes is allowed, we need a way to match them"""
     values = (identifier + "%",)
     query = "select hash from %s where hash like ?" % self.table
     if self.connected:
         self.cursor.execute(query, values)
         rows = self.cursor.fetchall()
         if len(rows) == 0:
             if not quiet:
                 print util.decorate("FAIL", "Fatal: No identifier could be matched")
             return None
         if len(rows) > 1:
             if not quiet:
                 print util.decorate(
                     "FAIL", "Fatal: Supplied identifier has multiple matches, please be more specific."
                 )
             return None
         else:
             return str(rows[0][0])
Пример #5
0
 def display(self):
     '''Prints the item's attributes.'''
     content = ''
     prettyTime = datetime.fromtimestamp(self.timestamp).strftime('%a %b %d %H:%M')
     for ch in self.content:
         if ch == '\n':
             content += '\n          '
         else:
             content += ch
     if sys.stdout.isatty():
         print 'Hash:    ', util.decorate('WARNING',self.identifier)
         print 'Time:    ', util.decorate('WARNING',prettyTime)
         print 'Priority:', util.decorate('WARNING',self.priority)
         print 'Tags:    ', util.decorate('OKGREEN',','.join(self.tags))
         print 'Content: ', content
         print
     else:
         print 'Hash:    ', self.identifier
         print 'Time:    ', prettyTime
         print 'Priority:', self.priority
         print 'Tags:    ', ','.join(self.tags)
         print 'Content: ', content
         print
Пример #6
0
 def display(self):
     '''Prints the item's attributes.'''
     content = ''
     prettyTime = datetime.fromtimestamp(
         self.timestamp).strftime('%a %b %d %H:%M')
     for ch in self.content:
         if ch == '\n':
             content += '\n          '
         else:
             content += ch
     if sys.stdout.isatty():
         print 'Hash:    ', util.decorate('WARNING', self.identifier)
         print 'Time:    ', util.decorate('WARNING', prettyTime)
         print 'Priority:', util.decorate('WARNING', self.priority)
         print 'Tags:    ', util.decorate('OKGREEN', ','.join(self.tags))
         print 'Content: ', content
         print
     else:
         print 'Hash:    ', self.identifier
         print 'Time:    ', prettyTime
         print 'Priority:', self.priority
         print 'Tags:    ', ','.join(self.tags)
         print 'Content: ', content
         print
Пример #7
0
def main():
    '''Get, interpret, and pass on any commands'''
    
    # Find and import support files
    path = os.getenv('HOME') + '/.jot'
    sys.path.append(path)

    # Class modules
    from lib import item, connection, peer

    # Command modules
    from bin import add, version, remove, show, util, \
            config, search, edit, pull, push, clone, \
            log, tag

    # Parse the configuration file
    config = util.parseConfig()

    # Apply changelog
    util.processChangelog()

    # Parse the command/arguments
    args = []
    if len(sys.argv) > 1:
        command = sys.argv[1]
    else:
        return False
    if len(sys.argv) > 2:
        args = util.parseArgs(sys.argv[2:])
    if len(args) > 0:
        args = util.parseArgs(args)

    # Create a database connection
    db = connection.Connection()

    # Pass off the db and any arguments to a 
    # command-specific function.
    if command == 'add':
        add.add(db,args,config)
    elif command == 'version':
        version.version()
    elif command == 'remove' or command == 'rm':
        remove.remove(db,args)
    elif command == 'config':
        config.config(args)
    elif command == 'show':
        show.show(db,args)
    elif command == 'search':
        search.search(db,args)
    elif command == 'edit':
        edit.edit(db,args,config)
    elif command == 'pull':
        pull.pull(args)
    elif command == 'push':
        push.push(args)
    elif command == 'clone':
        clone.clone(db,args)
    elif command == 'log':
        log.log(args,config)
    elif command == 'tag':
        tag.tag(db,args)
    elif command == 'help':
        help()
    else:
        print util.decorate('FAIL','Fatal: Command not recognized.')
        guess = util.guessCommand(command)
        if guess is not None:
            print 'Did you mean:',' or '.join(guess)
        return False
    return True
Пример #8
0
def main():
    """Get, interpret, and pass on any commands"""

    # Find and import support files
    path = os.getenv("HOME") + "/.jot"
    sys.path.append(path)

    # Class modules
    from lib import item, connection, peer

    # Command modules
    from bin import add, version, remove, show, util, config, search, edit, pull, push, clone, log, tag

    # Parse the configuration file
    config = util.parseConfig()

    # Apply changelog
    util.processChangelog()

    # Parse the command/arguments
    args = []
    if len(sys.argv) > 1:
        command = sys.argv[1]
    else:
        return False
    if len(sys.argv) > 2:
        args = util.parseArgs(sys.argv[2:])
    if len(args) > 0:
        args = util.parseArgs(args)

    # Create a database connection
    db = connection.Connection()

    # Pass off the db and any arguments to a
    # command-specific function.
    if command == "add":
        add.add(db, args, config)
    elif command == "version":
        version.version()
    elif command == "remove" or command == "rm":
        remove.remove(db, args)
    elif command == "config":
        config.config(args)
    elif command == "show":
        show.show(db, args)
    elif command == "search":
        search.search(db, args)
    elif command == "edit":
        edit.edit(db, args, config)
    elif command == "pull":
        pull.pull(args)
    elif command == "push":
        push.push(args)
    elif command == "clone":
        clone.clone(db, args)
    elif command == "log":
        log.log(args, config)
    elif command == "tag":
        tag.tag(db, args)
    else:
        print util.decorate("FAIL", "Fatal: Command not recognized.")
        guess = util.guessCommand(command)
        if guess is not None:
            print "Did you mean:", " or ".join(guess)
        return False
    return True