Skip to content

Commit bd87406

Browse files
committed
1. fixbug in zip permission.
2. show not support platform version in shell.
1 parent 0ca1619 commit bd87406

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,6 @@ venv.bak/
108108
# mypy
109109
.mypy_cache/
110110

111-
.idea/
111+
.idea/
112+
113+
.DS_Store

Diff for: install_binary.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ def traverse(f, data):
8989
def gq(tmp, data):
9090
return traverse(mk_tmplt(tmp), data)
9191

92+
class ZipFileWithPermissions(zipfile.ZipFile):
93+
def _extract_member(self, member, targetpath, pwd):
94+
if not isinstance(member, zipfile.ZipInfo):
95+
member = self.getinfo(member)
96+
targetpath = super()._extract_member(member, targetpath, pwd)
97+
98+
attr = member.external_attr >> 16
99+
if attr != 0:
100+
os.chmod(targetpath, attr)
101+
return targetpath
92102

93103
def get_binary():
94104
from purescripto.version import __blueprint_version__
@@ -100,30 +110,29 @@ def get_binary():
100110
.format(max_fit_tag)).json()
101111
print('Binaries downloaded.')
102112
plat_name = get_platform()
103-
104113
matcher = re.compile('\S+' + re.escape(plat_name))
105114
tmplt = {'browser_download_url': matcher}
106115
try:
107116
each = next(gq(tmplt, data))
108117
except StopIteration:
109118
import sys
110119
print(
111-
"It seems that binaries for your platform is not available.\n"
120+
f"It seems that binaries for your platform (which name is ${plat_name}) is not available.\n"
112121
"Following way must work, but can be quite time-consuming:\n"
113122
"Firstly, Install Haskell Stack Build Tool: https://docs.haskellstack.org/en/stable/README/\n"
114123
"Second, Clone https://github.com/purescript-python/purescript-python, then do `stack install .`"
115124
)
116125
sys.exit(1)
117126

118127
url = each['browser_download_url']
119-
zf = zipfile.ZipFile(io.BytesIO(requests.get(url).content))
128+
zf = ZipFileWithPermissions(io.BytesIO(requests.get(url).content))
120129
exe = "pspy-blueprint"
121130
if 'win' in url:
122131
exe += '.exe'
123132

124-
out_path.mkdir(exist_ok=True, parents=True)
133+
out_path.mkdir(exist_ok=True, parents=True, mode=0o777)
125134
zf.extract(exe, path=str(out_path))
126135
make_executable(str(out_path / exe))
127136

128-
129-
get_binary()
137+
if __name__ == "__main__":
138+
get_binary()

0 commit comments

Comments
 (0)