def main(arguments, DBURI=DBURI): if arguments['--args']: print arguments if arguments['--use']: DBURI = DBURI.replace('dopy', arguments['--use']) global db, tasks db, tasks = database(DBURI) if not any(arguments.values()): shell() elif arguments['add']: print add(arguments) elif arguments['ls']: print ls(arguments) elif arguments['rm']: print rm(arguments) elif arguments['done']: print done(arguments) elif arguments['get']: print get(arguments) elif arguments['--args']: print arguments elif arguments['note'] or arguments['show']: print note(arguments) else: print arguments
def elevate(path, args): # str, str try: quoted = ' '.join(("%s" % it for it in args)) shell().ShellExecute(path, quoted, '', 'runas') return True except Exception, e: dwarn(e) return False
def run_shell(self): import sqlalchemy as sa from sqlalchemy.orm import sessionmaker import db # settings banner = """ Griffith Interactive Shell Available variables: * sess - database session (try f.e. `sess.bind.echo = True`) * mem_sess - in memory session (playground) * sa - SQLAlchemy module * orm - SQLAlchemy's orm module * db - ORM stuff (f.e. db.Movie class) * gsql - GriffithSQL instance Examples: >>> movie = sess.query(db.Movie).first() >>> print movie.title >>> mem_movie = mem_sess.merge(movie) >>> mem_movie.seen = False >>> mem_sess.add(mem_movie) >>> mem_sess.commit() >>> seen_movies = sess.query(db.Movie).filter_by(seen=True) >>> for movie in seen_movies: print movie.title, movie.loaned >>> person = sess.query(db.Person).first() >>> print "%s has %d movies loaned" % (person.name, person.loaned_movies_count) """ ### prepare local env. ### # create a playground in memory mem_engine = sa.create_engine('sqlite:///:memory:') db.metadata.create_all(bind=mem_engine) # create tables MemSession = sessionmaker(bind=mem_engine) mem_session = MemSession() locs = {'mem_sess': mem_session, 'meta': db.metadata, 'db': db, 'sa': sa, 'orm': sa.orm, 'gsql': self.db, 'sess': self.db.session, #'griffith': self, } #exec 'from db import *' in locs ### prepare the shell ### try: ipython_args = [] # TODO: do we want to pass some args here? # try to use IPython if possible from IPython.Shell import IPShellEmbed shell = IPShellEmbed(argv=ipython_args) shell.set_banner(shell.IP.BANNER + banner) shell(local_ns=locs, global_ns={}) except ImportError: log.debug('IPython is not available') import code shell = code.InteractiveConsole(locals=locs) try: import readline except ImportError: log.debug('readline is not available') shell.interact(banner) sys.exit(0)
def run_shell(self): import sqlalchemy as sa from sqlalchemy.orm import sessionmaker import db # settings banner = """ Griffith Interactive Shell Available variables: * sess - database session (try f.e. `sess.bind.echo = True`) * mem_sess - in memory session (playground) * sa - SQLAlchemy module * orm - SQLAlchemy's orm module * db - ORM stuff (f.e. db.Movie class) * gsql - GriffithSQL instance Examples: >>> movie = sess.query(db.Movie).first() >>> print movie.title >>> mem_movie = mem_sess.merge(movie) >>> mem_movie.seen = False >>> mem_sess.add(mem_movie) >>> mem_sess.commit() >>> seen_movies = sess.query(db.Movie).filter_by(seen=True) >>> for movie in seen_movies: print movie.title, movie.loaned >>> person = sess.query(db.Person).first() >>> print "%s has %d movies loaned" % (person.name, person.loaned_movies_count) """ ### prepare local env. ### # create a playground in memory mem_engine = sa.create_engine('sqlite:///:memory:') db.metadata.create_all(bind=mem_engine) # create tables MemSession = sessionmaker(bind=mem_engine) mem_session = MemSession() locs = { 'mem_sess': mem_session, 'meta': db.metadata, 'db': db, 'sa': sa, 'orm': sa.orm, 'gsql': self.db, 'sess': self.db.session, #'griffith': self, } #exec 'from db import *' in locs ### prepare the shell ### try: ipython_args = [] # TODO: do we want to pass some args here? # try to use IPython if possible try: # >= 0.11 from IPython.frontend.terminal.embed import InteractiveShellEmbed shell = InteractiveShellEmbed(banner2=banner) except ImportError: # < 0.11 from IPython.Shell import IPShellEmbed shell = IPShellEmbed(argv=self.args) shell.set_banner(shell.IP.BANNER + banner) shell(local_ns=locs, global_ns={}) except ImportError: log.debug('IPython is not available') import code shell = code.InteractiveConsole(locals=locs) try: import readline except ImportError: log.debug('readline is not available') shell.interact(banner) sys.exit(0)