Skip to content

bugfix-fix-platname-and-unzip-permission #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ venv.bak/
# mypy
.mypy_cache/

.idea/
.idea/

.DS_Store
21 changes: 15 additions & 6 deletions install_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ def traverse(f, data):
def gq(tmp, data):
return traverse(mk_tmplt(tmp), data)

class ZipFileWithPermissions(zipfile.ZipFile):
def _extract_member(self, member, targetpath, pwd):
if not isinstance(member, zipfile.ZipInfo):
member = self.getinfo(member)
targetpath = super()._extract_member(member, targetpath, pwd)

attr = member.external_attr >> 16
if attr != 0:
os.chmod(targetpath, attr)
return targetpath

def get_binary():
from purescripto.version import __blueprint_version__
Expand All @@ -100,30 +110,29 @@ def get_binary():
.format(max_fit_tag)).json()
print('Binaries downloaded.')
plat_name = get_platform()

matcher = re.compile('\S+' + re.escape(plat_name))
tmplt = {'browser_download_url': matcher}
try:
each = next(gq(tmplt, data))
except StopIteration:
import sys
print(
"It seems that binaries for your platform is not available.\n"
f"It seems that binaries for your platform (which name is ${plat_name}) is not available.\n"
"Following way must work, but can be quite time-consuming:\n"
"Firstly, Install Haskell Stack Build Tool: https://docs.haskellstack.org/en/stable/README/\n"
"Second, Clone https://github.com/purescript-python/purescript-python, then do `stack install .`"
)
sys.exit(1)

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

out_path.mkdir(exist_ok=True, parents=True)
out_path.mkdir(exist_ok=True, parents=True, mode=0o777)
zf.extract(exe, path=str(out_path))
make_executable(str(out_path / exe))


get_binary()
if __name__ == "__main__":
get_binary()