Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

Revisions

  1. yasoob revised this gist Jun 8, 2014. 1 changed file with 58 additions and 58 deletions.
    @@ -2,15 +2,15 @@
    [JS] Jump Start: Your commandline companion

    Commands:
    js add <name> <file>
    js rm (<name> | --all)
    js show (--all | -a)
    js <name>
    js add <name> <file>
    js rm (<name> | --all)
    js show (--all | -a)
    js <name>

    Options:
    --version -v: Print program version and exit
    --help -h : Print this help message and exit
    --db : Print the db location
    --version -v: Print program version and exit
    --help -h : Print this help message and exit
    --db : Print the db location
    """


    @@ -21,9 +21,9 @@ import sys
    from __future__ import print_function

    COMMANDS = {
    'create':'''
    CREATE TABLE IF NOT EXISTS path(id INTEGER PRIMARY KEY, name TEXT,
    path TEXT, filename TEXT)
    'create':'''
    CREATE TABLE IF NOT EXISTS path(id INTEGER PRIMARY KEY, name TEXT,
    path TEXT, filename TEXT)
    ''',
    'insert':'''
    INSERT INTO path(name, path, filename)
    @@ -34,64 +34,64 @@ COMMANDS = {
    ''',
    'delete','''
    DELETE FROM path WHERE name=?
    '''
    '''
    }

    DB = os.path.expanduser("~/.js")

    class JS(object):
    def __init__(self,options):
    self.options = options
    def __init__(self,options):
    self.options = options

    def connect(self):
    db = sqlite3.connect(DB)
    cursor = db.cursor()
    with cursor:
    cursor.execute(COMMANDS['create'])
    return cursor
    def connect(self):
    db = sqlite3.connect(DB)
    cursor = db.cursor()
    with cursor:
    cursor.execute(COMMANDS['create'])
    return cursor

    @classmethod
    def get(self, name):
    cursor = self.connect()
    with cursor:
    cursor.execute(COMMANDS['select'], (name))
    path = cursor.fetchone()
    if path is None:
    print("Path not available. Have you inserted it before?")
    sys.exit()
    return path
    @classmethod
    def get(self, name):
    cursor = self.connect()
    with cursor:
    cursor.execute(COMMANDS['select'], (name))
    path = cursor.fetchone()
    if path is None:
    print("Path not available. Have you inserted it before?")
    sys.exit()
    return path

    @classmethod
    def add(self,name,filename):
    path = os.getcwd()
    cursor = self.connect()
    with cursor:
    if cursor.execute(COMMANDS['select'],(name)) is not None:
    print('The name you entered is already present in the db')
    sys.exit()
    cursor.execute(COMMANDS['insert'],(name, path, filename))
    print('Command successfully inserted into the db')
    @classmethod
    def add(self,name,filename):
    path = os.getcwd()
    cursor = self.connect()
    with cursor:
    if cursor.execute(COMMANDS['select'],(name)) is not None:
    print('The name you entered is already present in the db')
    sys.exit()
    cursor.execute(COMMANDS['insert'],(name, path, filename))
    print('Command successfully inserted into the db')

    @classmethod
    def remove(self,name):
    cursor = self.connect()
    with cursor:
    if cursor.execute(COMMANDS['select']).fetchone() is None:
    print('That command is not present in the db')
    sys.exit()
    cursor.execute(COMMANDS['delete'],(name))
    print('{0} is deleted from db'.format(name))
    @classmethod
    def remove(self,name):
    cursor = self.connect()
    with cursor:
    if cursor.execute(COMMANDS['select']).fetchone() is None:
    print('That command is not present in the db')
    sys.exit()
    cursor.execute(COMMANDS['delete'],(name))
    print('{0} is deleted from db'.format(name))

    @classmethod
    def delete_db(self):
    os.remove(DB)
    print('Db successfully deleted!')
    @classmethod
    def delete_db(self):
    os.remove(DB)
    print('Db successfully deleted!')

    @staticmethod
    def execute(command):
    print("Command is being executed...")
    subprocess.call(command, shell=True)
    @staticmethod
    def execute(command):
    print("Command is being executed...")
    subprocess.call(command, shell=True)

    def main():
    args = sys.argv[1:]
    if len(args)
    args = sys.argv[1:]
    if len(args)
  2. yasoob created this gist Jun 8, 2014.
    @@ -0,0 +1,97 @@
    """
    [JS] Jump Start: Your commandline companion

    Commands:
    js add <name> <file>
    js rm (<name> | --all)
    js show (--all | -a)
    js <name>

    Options:
    --version -v: Print program version and exit
    --help -h : Print this help message and exit
    --db : Print the db location
    """


    import sqlite3
    import os
    import subprocess
    import sys
    from __future__ import print_function

    COMMANDS = {
    'create':'''
    CREATE TABLE IF NOT EXISTS path(id INTEGER PRIMARY KEY, name TEXT,
    path TEXT, filename TEXT)
    ''',
    'insert':'''
    INSERT INTO path(name, path, filename)
    VALUES (?, ?, ?)
    ''',
    'select':'''
    SELECT path,filename FROM path WHERE name=?
    ''',
    'delete','''
    DELETE FROM path WHERE name=?
    '''
    }

    DB = os.path.expanduser("~/.js")

    class JS(object):
    def __init__(self,options):
    self.options = options

    def connect(self):
    db = sqlite3.connect(DB)
    cursor = db.cursor()
    with cursor:
    cursor.execute(COMMANDS['create'])
    return cursor

    @classmethod
    def get(self, name):
    cursor = self.connect()
    with cursor:
    cursor.execute(COMMANDS['select'], (name))
    path = cursor.fetchone()
    if path is None:
    print("Path not available. Have you inserted it before?")
    sys.exit()
    return path

    @classmethod
    def add(self,name,filename):
    path = os.getcwd()
    cursor = self.connect()
    with cursor:
    if cursor.execute(COMMANDS['select'],(name)) is not None:
    print('The name you entered is already present in the db')
    sys.exit()
    cursor.execute(COMMANDS['insert'],(name, path, filename))
    print('Command successfully inserted into the db')

    @classmethod
    def remove(self,name):
    cursor = self.connect()
    with cursor:
    if cursor.execute(COMMANDS['select']).fetchone() is None:
    print('That command is not present in the db')
    sys.exit()
    cursor.execute(COMMANDS['delete'],(name))
    print('{0} is deleted from db'.format(name))

    @classmethod
    def delete_db(self):
    os.remove(DB)
    print('Db successfully deleted!')

    @staticmethod
    def execute(command):
    print("Command is being executed...")
    subprocess.call(command, shell=True)

    def main():
    args = sys.argv[1:]
    if len(args)