@@ 1,7 1,8 @@
import os
+import shutil
+import tarfile
import tempfile
import urllib.request
-import zipfile
# https://github.com/orus-io/elm-spa/archive/refs/heads/master.zip
# https://github.com/orus-io/elm-spa/archive/refs/tags/1.2.0.zip
@@ 77,45 78,45 @@ known_forges = {
"github.com": {
"match": match_github,
TRACK_CSET: {
- "url": "https://github.com/%(path)s/archive/%(track)s.zip",
+ "url": "https://github.com/%(path)s/archive/%(track)s.tar.gz",
"prefix": "%(name)s-%(track)s",
},
TRACK_BRANCH: {
- "url": "https://github.com/%(path)s/archive/refs/heads/%(track)s.zip",
+ "url": "https://github.com/%(path)s/archive/refs/heads/%(track)s.tar.gz",
"prefix": "%(name)s-%(track)s",
},
TRACK_TAG: {
- "url": "https://github.com/%(path)s/archive/refs/tags/%(track)s.zip",
+ "url": "https://github.com/%(path)s/archive/refs/tags/%(track)s.tar.gz",
"prefix": "%(name)s-%(track)s",
},
},
"orus.io-hg": {
"match": match_orus_io_hg,
TRACK_CSET: {
- "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.zip%(token)s",
+ "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.tar.gz%(token)s",
"prefix": "%(name)s-%(track)s",
},
TRACK_BRANCH: {
- "url": "https://orus.io/%(path)s/-/archive/branch/%(track)s/%(name)s-branch-%(track)s.zip%(token)s",
+ "url": "https://orus.io/%(path)s/-/archive/branch/%(track)s/%(name)s-branch-%(track)s.tar.gz%(token)s",
"prefix": "%(name)s-branch-%(track)s",
},
TRACK_TAG: {
- "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.zip%(token)s",
+ "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.tar.gz%(token)s",
"prefix": "%(name)s-%(track)s",
},
},
"orus.io-git": {
"match": match_orus_io_git,
TRACK_CSET: {
- "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.zip%(token)s",
+ "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.tar.gz%(token)s",
"prefix": "%(name)s-%(track)s",
},
TRACK_BRANCH: {
- "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.zip%(token)s",
+ "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.tar.gz%(token)s",
"prefix": "%(name)s-%(track)s",
},
TRACK_TAG: {
- "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.zip%(token)s",
+ "url": "https://orus.io/%(path)s/-/archive/%(track)s/%(name)s-%(track)s.tar.gz%(token)s",
"prefix": "%(name)s-%(track)s",
},
},
@@ 140,40 141,39 @@ def checkout(ui, section, rev, secconf):
if url is None:
continue
try:
- ui.write("fetching %s...\n" % (url))
+ ui.write("fetching %s...\n" % (url.split("?")[0]))
req = urllib.request.Request(
url,
)
f = urllib.request.urlopen(req)
- if f.headers.get("Content-Type") != "application/zip":
- ui.write("not a zipfile (%s)\n" % (f.headers.get("Content-Type")))
+ if f.headers.get("Content-Type") not in (
+ "application/octet-stream",
+ "application/x-gzip",
+ ):
+ ui.write("not a .gz stream (%s)\n" % (f.headers.get("Content-Type")))
continue
with tempfile.NamedTemporaryFile(
"w+b",
prefix="confman-" + section.replace("/", "-") + "-",
- suffix=".zip",
+ suffix=".tar.gz",
delete=False,
- ) as t:
+ ) as tmp:
while True:
b = f.read(1024 * 1024)
if len(b) == 0:
break
- t.write(b)
- t.flush()
+ tmp.write(b)
+ tmp.flush()
+ tmp.seek(0)
- z = zipfile.ZipFile(t.name)
- for info in z.infolist():
- if info.is_dir():
- continue
- path = os.path.join(
- secconf["layout"],
- info.filename.removeprefix(prefix).strip("/"),
- )
-
- if not os.path.exists(os.path.dirname(path)):
- os.makedirs(os.path.dirname(path))
- with open(path, "wb") as out:
- out.write(z.read(info))
+ tar = tarfile.open(mode='r:gz', fileobj=tmp)
+ with tempfile.TemporaryDirectory() as tmpdir:
+ tar.extractall(path=tmpdir)
+ if not os.path.exists(os.path.dirname(secconf["layout"])):
+ os.makedirs(os.path.dirname(secconf["layout"]))
+ if os.path.exists(secconf["layout"]):
+ shutil.rmtree(secconf["layout"])
+ shutil.move(os.path.join(tmpdir, prefix), secconf["layout"])
ui.write(" -> extracted to %s\n" % (secconf["layout"]))
break
except urllib.error.URLError as e: