from argtools import command, argument

from env import app_options


@command.add_sub(name='set_keys_expire', help='set_keys_expire')
@argument('--service_id', dest='service_id', help='service id', default='dev')
@argument('--pattern', dest='pattern', help='pattern', default='test-key:*')
@argument('--second', dest='second', help='second', default=36000)
def set_keys_expire(args=None):
    app_options.set('service.id', args.service_id)
    iter_count = 500
    exec_count = 5000

    if args.pattern and args.second:
        from env.server import redis_server

        pipe = redis_server.pipeline()
        count = 0
        for key in redis_server.scan_iter(match=args.pattern,
                                          count=iter_count):
            count += 1
            pipe.expire(key, args.second)
            if count == exec_count:
                count = 0
                pipe.execute()


if __name__ == '__main__':
    command.run()
Beispiel #2
0
#!/usr/bin/env python
from argtools import command, argument


@command
@argument('foo', help='a positional arugment')
@argument('--bar', default=3, help='an optional argument')
def main(args):
    """ One line description here

    Write details here (printed with --help|-h)
    """
    print args.bar
    print args.foo
    return 1  # return code


if __name__ == '__main__':
    command.run()
Beispiel #3
0
        roffset = self.right * bs
        if self.validate:
            intervals = with_validation(intervals, bs)

        for (chrom, ivs) in groupby(intervals,
                                    itemgetter(0)):  # group by chrom
            emit_start = 0
            buff = []
            sig = 0
            last_iv = BedgRec(
                chrom, float('inf'), float('inf'),
                0.0)  # dummy record for avoid emission after ivs consumed

            for iv in chain(ivs, [last_iv]):
                while buff and emit_start + roffset < iv.start:
                    #sig = sum(v for (s, v) in buff)            # for speed, avoid summation
                    yield (chrom, emit_start, emit_start + bs, sig)
                    emit_start += bs
                    if buff[0][0] < emit_start - loffset:
                        sig -= buff[0][1]
                        buff.pop(0)

                val = iv.value / denom
                sig += val
                buff.append((iv.start, val))
                emit_start = max(emit_start, iv.start - roffset)


if __name__ == '__main__':
    exit(command.run())
Beispiel #4
0
def main():
    command.run()