Skip to content

Commit 04bda34

Browse files
committed
tools: hub-clone: new hub metadata customizable
1 parent 95214e9 commit 04bda34

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

tools/hub-clone.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import json
1010

1111
class HubFlistSyncer:
12-
def __init__(self, baseurl, localdir):
12+
def __init__(self, baseurl, localdir, newhost):
1313
self.baseurl = baseurl
1414
self.localdir = localdir
1515

@@ -19,6 +19,10 @@ def __init__(self, baseurl, localdir):
1919
self.downloaded = 0
2020
self.files = 0
2121

22+
self.backhost = newhost
23+
self.backport = 9900
24+
self.backname = "default"
25+
2226
#
2327
# remote helpers
2428
#
@@ -112,7 +116,7 @@ def local_sync_regular_file(self, username, entry, targetfile):
112116
os.remove(targetfile)
113117

114118
url = f"{self.baseurl}/{username}/{entry['name']}"
115-
sys.stdout.write(f"\r[+] downloading: {url} \033\x5bK")
119+
print(f"\r[+] downloading: {url} \033\x5bK")
116120

117121
r = requests.get(url)
118122
with open(targetfile, "wb") as f:
@@ -243,8 +247,7 @@ def metadata_update(self, target):
243247
print("[-] legacy flist, no metadata records found, initializing")
244248
cursor.execute("CREATE TABLE metadata (key VARCHAR(64) PRIMARY KEY, value TEXT);")
245249

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})
248251

249252
cursor.execute("REPLACE INTO metadata (key, value) VALUES ('backend', ?)", (backend,))
250253
db.commit()
@@ -262,20 +265,21 @@ def metadata_update(self, target):
262265
return True
263266

264267
if __name__ == "__main__":
265-
if len(sys.argv) < 3:
268+
if len(sys.argv) < 4:
266269
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]")
268271
print("")
269272
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")
271274
print("")
272275

273276
sys.exit(1)
274277

275278
host = sys.argv[1]
276279
target = sys.argv[2]
280+
newhost = sys.argv[3]
277281

278-
sync = HubFlistSyncer(host, target)
282+
sync = HubFlistSyncer(host, target, newhost)
279283

280284
repositories = sync.remote_repositories()
281285
updating = sync.local_sync_repositories(repositories)

0 commit comments

Comments
 (0)