-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrkndexer
executable file
·52 lines (45 loc) · 2.09 KB
/
rkndexer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
import argparse
import binascii
import sys
import traceback
import psycopg2
import prometheus_client as prom # /~https://github.com/prometheus/client_python
import rkndex.indexer as indexer
from rkndex.util import schedule_every
def str_sha1(s):
if len(binascii.unhexlify(s)) != 20:
raise ValueError()
return s
def parse_args():
p = argparse.ArgumentParser(description='Importer of the git archive to postgresql')
p.add_argument('--giweb', help='URL root for darkk/rkn:giweb API', metavar='URL', required=True)
p.add_argument('--postgres', metavar='DSN', help='libpq data source name', required=True)
#p.add_argument('--prom-addr', help='Prometheus exporter bind IP', metavar='IP', default='127.0.0.1')
#p.add_argument('--prom-port', help='Prometheus exporter bind port', metavar='PORT', type=int, required=True)
act = p.add_mutually_exclusive_group(required=True)
act.add_argument('--daemon', action='store_true', help='Run as a daemon-loop')
act.add_argument('--list', action='store_true', help='Sync list of dumps')
act.add_argument('--listed-diff', action='store_true', help='Sync all listed diffs')
act.add_argument('--diff', metavar='SHA1', nargs=2, type=str_sha1, help='Ingest a diff between two blobs')
#act.add_argument('--diff-next', metavar='SHA1', help='Ingest a diff between this and the next blob')
return p.parse_args()
def main():
o = parse_args()
#prom.start_http_server(o.prom_port, o.prom_addr)
pgconn = psycopg2.connect(dsn=o.postgres) # ordinary postgres connection
if o.list:
indexer.main_list(pgconn, o.giweb)
elif o.diff:
indexer.main_diff(pgconn, o.giweb, o.diff[0], o.diff[1])
elif o.listed_diff:
indexer.main_alldiff(pgconn, o.giweb)
elif o.daemon:
for _ in schedule_every((None,), 60):
try:
if indexer.main_list(pgconn, o.giweb): # new objects
indexer.main_alldiff(pgconn, o.giweb) # maybe, fail
except Exception:
traceback.print_exc(file=sys.stderr)
if __name__ == '__main__':
main()