예제 #1
0
def load():
    open_log("load account")
    open_debug()
    parser = OptionParser()
    parser.add_option("-i", "--conf", dest="conf", action="store", type="string")
    parser.add_option("-n", "--num", dest="num", action="store", type="int")
    parser.add_option("-t", "--target", dest="target", action="store", type="string")

    options, args = parser.parse_args(sys.argv[1:])
    if not options.conf or not options.target:
        parser.print_help()
        sys.exit(-1)

    conf = DictIni(options.conf)
    num = options.num or 100000
    if os.path.exists(options.target):
        log.error("%s had exitst", options.target)
        return
    
    client = MagicClient(conf.account_server[0], int(conf.account_server[1]))
    total = 0
    f = file(options.target, 'w')
    log.trace("begin load data")
    while total < num:
        data = client.get_add_friends()
        if data:
            total += len(data)
            f.write('\n'.join([x.strip() for x in data]))
            log.trace("load account success %s", total)
        elif not data and not total:
            log.trace("load account %s fail")
            break
    f.close()
    log.trace("load accounts %s success %s", len(data), total)
예제 #2
0
    def run(self):
        name = osp.basename(self.dbpath)
        open_log(name, logging.INFO)
        open_debug()
        parser = OptionParser()
        parser.add_option("-a", "--action", dest="action", help="what action[add|del|export|addemail]")
        parser.add_option("-f", "--file", dest="filename",
                      help="write report to add", metavar="FILE")
        parser.add_option("-s", "--state", dest="state", help="what state want to set", type="string")
        parser.add_option('-t', "--target_dir", dest='target_dir', help="which target dir to export")
        parser.add_option('-c', "--count", dest='count', action="store_true")

        options, args = parser.parse_args(sys.argv[1:])
        if options.count:
            return self.count(options.state or '0')
        if options.action == 'export':
            print 'begin export'
            ct = self.export(options.state or '0', options.target_dir)
            return
        
        if not options.filename:
            parser.print_help()
            return
        if osp.isdir(options.filename):
            filenames = [osp.join(options.filename, x) for x in os.listdir(options.filename)] 
        else:
            filenames = [options.filename]
                
        
        if options.action == 'add':             
            total = 0
            for filename in filenames:
                if filename.find('.svn') != -1:
                    continue
                ct = self.add_file_to_db(filename, options.state or 0)
                total += ct
                log.trace('action %s fielname %s result new %d total %d', options.action, filename,  ct, total)
                
        if options.action == 'addemail':             
            total = 0
            for filename in filenames:
                ct = self.add_email_to_db(filename, options.state or 0)
                total += ct
                log.trace('action %s fielname %s result new %d total %d', options.action, filename,  ct, total)

        if options.action == 'del':
            total = 0
            for filename in filenames:
                ct = self.del_file(filename)
                total += ct
                log.trace('action %s fielname %s result new %d total %d', options.action, filename,  ct, total)