9
9
import json
10
10
11
11
class HubFlistSyncer :
12
- def __init__ (self , baseurl , localdir ):
12
+ def __init__ (self , baseurl , localdir , newhost ):
13
13
self .baseurl = baseurl
14
14
self .localdir = localdir
15
15
@@ -19,6 +19,10 @@ def __init__(self, baseurl, localdir):
19
19
self .downloaded = 0
20
20
self .files = 0
21
21
22
+ self .backhost = newhost
23
+ self .backport = 9900
24
+ self .backname = "default"
25
+
22
26
#
23
27
# remote helpers
24
28
#
@@ -112,7 +116,7 @@ def local_sync_regular_file(self, username, entry, targetfile):
112
116
os .remove (targetfile )
113
117
114
118
url = f"{ self .baseurl } /{ username } /{ entry ['name' ]} "
115
- sys . stdout . write (f"\r [+] downloading: { url } \033 \x5b K" )
119
+ print (f"\r [+] downloading: { url } \033 \x5b K" )
116
120
117
121
r = requests .get (url )
118
122
with open (targetfile , "wb" ) as f :
@@ -243,8 +247,7 @@ def metadata_update(self, target):
243
247
print ("[-] legacy flist, no metadata records found, initializing" )
244
248
cursor .execute ("CREATE TABLE metadata (key VARCHAR(64) PRIMARY KEY, value TEXT);" )
245
249
246
- # FIXME: takes theses settings from a main place
247
- backend = json .dumps ({"namespace" : "default" , "host" : "hub.updated.host" , "port" : 7900 })
250
+ backend = json .dumps ({"namespace" : self .backname , "host" : self .backhost , "port" : self .backport })
248
251
249
252
cursor .execute ("REPLACE INTO metadata (key, value) VALUES ('backend', ?)" , (backend ,))
250
253
db .commit ()
@@ -262,20 +265,21 @@ def metadata_update(self, target):
262
265
return True
263
266
264
267
if __name__ == "__main__" :
265
- if len (sys .argv ) < 3 :
268
+ if len (sys .argv ) < 4 :
266
269
print ("" )
267
- print (f" Usage: { sys .argv [0 ]} [remote-host] [local-directory]" )
270
+ print (f" Usage: { sys .argv [0 ]} [remote-host] [local-directory] [local-host] " )
268
271
print ("" )
269
272
print (" Example:" )
270
- print (f" { sys .argv [0 ]} https://hub.grid.tf /tmp/users" )
273
+ print (f" { sys .argv [0 ]} https://hub.grid.tf /tmp/users mirror.hub.grid.tf " )
271
274
print ("" )
272
275
273
276
sys .exit (1 )
274
277
275
278
host = sys .argv [1 ]
276
279
target = sys .argv [2 ]
280
+ newhost = sys .argv [3 ]
277
281
278
- sync = HubFlistSyncer (host , target )
282
+ sync = HubFlistSyncer (host , target , newhost )
279
283
280
284
repositories = sync .remote_repositories ()
281
285
updating = sync .local_sync_repositories (repositories )
0 commit comments