@@ -0,0 +1,2081 @@
+#!/usr/bin/env python%0A# -*- coding: utf-8 -*-%0A%0Aimport sys%0Afrom time import time%0Afrom warnings import filterwarnings%0Afilterwarnings(action='ignore', category=DeprecationWarning, message=%22Python 2.6 is no longer supported by the Python core team%22)%0Afrom twisted.internet import reactor, defer%0Afrom txjsonrpc.web.jsonrpc import Proxy%0Afrom hyphe_backend.lib import config_hci%0A%0Aconfig = config_hci.load_config()%0Aif not config:%0A    exit()%0A%0Adaysback = 7%0Aif len(sys.argv) %3E 1:%0A    try:%0A        daysback = int(sys.argv%5B1%5D)%0A    except:%0A        print %3E%3E sys.stderr, %22ERROR: argument must be an integer (number of days back)%22%0A        exit(1)%0Adayms = 1000 * 60 * 60 * 24%0Adelay = dayms * daysback%0A%0Aproxy = Proxy('http://127.0.0.1:%25d' %25 config%5B'core_api_port'%5D)%0A%0A@defer.inlineCallbacks%0Adef handleList(res):%0A    if res%5B'code'%5D == 'fail':%0A        defer.returnValue(printError(res%5B'message'%5D))%0A    for cid, corpus in res%5B'result'%5D.items():%0A        since = time() * 1000 - corpus%5B'last_activity'%5D%0A        if since %3E delay:%0A            print %22REMOVING old corpus:%22, cid, corpus%5B'last_activity'%5D, int(since/dayms), %22days old%22%0A            res = yield proxy.callRemote('start_corpus', cid, config%5B'ADMIN_PASSWORD'%5D if corpus%5B'password'%5D else '')%0A            if res%5B'code'%5D == 'fail':%0A                print %3E%3E sys.stderr, %22WARNING: could not start old corpus %25s: %25s%22 %25 (cid, res%5B'message'%5D)%0A                continue%0A            res = yield proxy.callRemote('ping', cid, 30)%0A            if res%5B'code'%5D == 'fail':%0A                print %3E%3E sys.stderr, %22WARNING: could not ping old corpus %25s: %25s%22 %25 (cid, res%5B'message'%5D)%0A                continue%0A            res = yield proxy.callRemote('destroy_corpus', cid)%0A            if res%5B'code'%5D == 'fail':%0A                print sys.stderr, %22WARNING: could not destroy old corpus %25s: %25s%22 %25 (cid, res%5B'message'%5D)%0A%0A%0Adef printError(error):%0A    print %3E%3E sys.stderr, %22ERROR: Cannot get list of corpora%22, error%0A%0Adef shutdown(data):%0A    reactor.stop()%0A%0Ad = proxy.callRemote('list_corpus')%0Ad.addCallback(handleList).addErrback(printError)%0Ad.addCallback(shutdown)%0Areactor.run()%0A

add old corpus clean from demo