Ejemplo n.º 1
0
def main():
    logging.info("Gordias started")
    try:
        threading.Thread(target=run, kwargs=dict(host='0.0.0.0',
                                                 port=8080)).start()  # Run API
        sync.start_sync()
    except:
        logging.error("Unexpected error: {0}", sys.exc_info()[0])
    finally:
        database.close_connection()
        notnull.dump_matrices()
Ejemplo n.º 2
0
def local_start_sync(client):
    global local_path
    global g_ind
    start_sync(client, local_path, g_ind, False)
Ejemplo n.º 3
0
def main():
    # load config
    config = load_config()
    _consumer_key = ""
    _consumer_secret = ""
    
    if config.has_section('client'):
        _consumer_key = config.get('client', '_consumer_key')
        _consumer_secret = config.get('client', '_consumer_secret')

    # init client
    client = Client(_consumer_key, _consumer_secret)
    
    # auth before use
    auth(client, config)

    if client.is_authed():
        global local_path
        global g_ind
        if config.has_section('sync'):
            local_path = config.get('sync', 'local_path')
        if not local_path:
            home_dir = os.path.expanduser('~')
            default_dir = os.path.join(home_dir, "kuaipan")
            is_create_default = False
            if not os.path.exists(default_dir):
                is_create_default = True
                os.mkdir(default_dir)
            
            dialog = gtk.FileChooserDialog(title="请选择快盘文件同步到本地存放的文件夹", parent=None,
                action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
                buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,gtk.RESPONSE_OK))
            dialog.set_current_folder(default_dir)

            filter = gtk.FileFilter()
            filter.set_name("所有文件夹")
            filter.add_pattern("*")
            dialog.add_filter(filter)            
                
            response = dialog.run()
            if response == gtk.RESPONSE_OK:
                print dialog.get_filename(), 'selected'
                local_path = dialog.get_filename()
                if is_create_default and local_path != default_dir:
                    os.rmdir(default_dir)
                config.add_section('sync')
                config.set('sync', 'local_path', local_path)
                fp = open(get_cfg_path(), 'w')
                config.write(fp)                    
            else:
                print 'Closed, no files selected'
            dialog.destroy()

        if not local_path:
            return

        ac_info = client.get_account_info()
        print('is authed')
        print(ac_info)
        window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        g_ind = init_indicator(ac_info, client)

        # start sync thread
        start_sync(client, local_path, g_ind)
        
        # start monitor thread
        start_monitor(client, local_path, g_ind)
        
        # start run application
        gtk.main()
    else:
        print('not authed')
Ejemplo n.º 4
0
def main():
    '''entry point '''
    # my_wunder = MyWunder()

    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--init',
        help='init local support, user -eEMail -pPassword to finish it',
        action='store_true')
    parser.add_argument('-e', '--email', help='your email address')
    parser.add_argument('-p', '--password', help='your password')
    parser.add_argument('-l',
                        '--lists',
                        help='show lists',
                        action='store_true')
    parser.add_argument('-t',
                        '--tasks',
                        help='show tasks',
                        action='store_true')
    parser.add_argument('-u',
                        '--update',
                        help='update database',
                        action='store_true')
    parser.add_argument('-n', '--name', help="list name")
    parser.add_argument('-m', '--month', help="query by month", type=int)
    parser.add_argument('-s',
                        '--sum',
                        help="sum the number at title",
                        action="store_true")

    args = parser.parse_args()

    if args.init:
        assert args.email, 'need user, use -h to see more.'
        assert args.password, 'need password, use -h to see more.'
        my_wunder.login(args.email, args.password)
        my_wunder.init_db()

    elif args.lists:
        if args.name:
            list_id = my_wunder.query_list(args.name)
            print list_id
        else:
            l = my_wunder.query_list()
            format_printer(l)
    elif args.tasks:
        assert args.name, "you must use -n LISTNAME to assign the list name for tasks"
        l = my_wunder.query_tasks(args.name)
        if args.month:
            month = args.month

            def month_filter(tk):
                d = dateutil.parser.parse(tk['created_at'])
                y, da, day = str(d).split('-')
                return int(da) == month and datetime.now().year == int(y)

            l = filter(month_filter, l)
        format_printer(l)
        if args.sum:
            number_filter_func = lambda d: list(
                set(re.findall('\d*', d)) - set(['']))
            item_number_result_list = [
                number_filter_func(d['title']) for d in l
                if len(number_filter_func(d['title'])) > 0
            ]
            totals = sum([
                sum([float(ii) for ii in i]) for i in item_number_result_list
            ])
            logging.info("totals %f", totals)
            print "totals %f" % totals
    elif args.update:
        start_sync()
    else:
        l = my_wunder.query_list()
        format_printer(l)