예제 #1
0
파일: csb.py 프로젝트: rayleyva/csb
def main(args):
    parser = OptionParser(version=version)
    #parser.add_option("-w", "--width", dest="width", default=20,
    #        help="set the default column width to COLS", metavar="COLS")
    parser.add_option("-t", "--table", dest="table", default=None,
            help="start with table NAME open", metavar="NAME")
    parser.add_option("-f", "--file", dest="dbfile", default=None,
            help="read the DB URI from a file", metavar="FILE")
    parser.add_option("-d", "--debug",
            action="store_true", dest="debug", default=False,
            help="turn on debugging to csb.log")
    parser.add_option("-y", "--yes",
            action="store_true", dest="yes", default=False,
            help="Do things without confirming")
    (options, args) = parser.parse_args()

    if len(args) == 1:
        options.fname = args[0]
    elif options.dbfile:
        options.fname = file(options.dbfile).read().strip()
    elif os.path.exists("/etc/csb.conf"):
        options.fname = file("/etc/csb.conf").read().strip()
    else:
        options.fname = raw_input("Enter database uri: ")

    if options.debug:
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)s %(levelname)-8s %(message)s',
            filename="csb.log"
            )
    else:
        logging.basicConfig(
            level=logging.CRITICAL,
            format='%(asctime)s %(levelname)-8s %(message)s'
            )

    try:
        with dbapi(options.fname) as api:
            tables = get_tables(api)
            if len(tables) == 0:
                print "No tables in database"
                return 1
            if not options.table or options.table not in tables:
                options.table = get_tables(api)[0]
            with screen() as stdscr:
                csui.curs_set(False)
                curses.mousemask(0xFFFFFFF)
                main_loop(api, stdscr, options)
    except KeyboardInterrupt:
        print "Exited without committing changes"
        return 2

    return 0
예제 #2
0
파일: csb.py 프로젝트: rayleyva/csb
def do_outside_curses(func, *args, **kw):
    """
    Leave curses mode before running a function, then re-enter it afterwards.

    Useful when eg you want to see the output of a command line app.
    """
    value = None
    old_winch = signal.signal(signal.SIGWINCH, signal.SIG_IGN)
    old_cursor = csui.curs_set(1)
    curses.endwin()

    try:
        os.system("clear")
        value = func(*args, **kw)
        os.system("clear")
    except Exception, e:
        print "The thing outside curses had an error"
        value = None
예제 #3
0
파일: csb.py 프로젝트: rayleyva/csb
    """
    value = None
    old_winch = signal.signal(signal.SIGWINCH, signal.SIG_IGN)
    old_cursor = csui.curs_set(1)
    curses.endwin()

    try:
        os.system("clear")
        value = func(*args, **kw)
        os.system("clear")
    except Exception, e:
        print "The thing outside curses had an error"
        value = None

    curses.initscr()
    csui.curs_set(old_cursor)

    # bug in python? old_winch = 0, so we have to define our own :-/
    def __sigwinch_handler(signal, frame):
        curses.endwin()
        curses.initscr()
    signal.signal(signal.SIGWINCH, __sigwinch_handler)
    return value


# these should be part of some standard library

def limit(val, a, b):
    n = min(a, b)
    x = max(a, b)
    if val < n: val = n