Skip to content

Commit 607d3af

Browse files
authored
Merge pull request #8 from ProgramPack/experimental
Merged branch: experimental -> base
2 parents 762d60d + cf6ca6e commit 607d3af

10 files changed

Lines changed: 74 additions & 18 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["3.8", "3.9", "3.10"]
19+
python-version: ["3.9", "3.10"]
2020

2121
steps:
2222
- uses: actions/checkout@v3

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ sclean:
1515
rm -rf build
1616
rm -rf dist
1717
sgeneratechangelog:
18-
git log --pretty="- %s" > CHANGELOG.md
18+
git log --pretty="- %s" > CHANGELOG.md

examples/blank.propack

452 Bytes
Binary file not shown.

examples/blankapp/App

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#!/usr/bin/env bash

examples/blankapp/manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "blank",
3+
"description": "Application that does nothing",
4+
"author": "VBPROGER",
5+
"version": "1.0.0",
6+
"mainfile": "App"
7+
}

programpack/__init__.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@
99
from hashlib import sha256
1010
from platform import system
1111
from warnings import warn
12+
from requests import get as r_get
1213

1314
__all__ = [
1415
'PackedProgram', 'convert_file_to_executable', 'deconvert', 'create_archive'
1516
]
1617
__version__ = '0.0.1'
1718

18-
shebang = b'#!/usr/bin/env -S python3 -m programpack run\n'
19-
shebang_v = b'#!/usr/bin/env -S python3 -m programpack run --virtual\n'
20-
_empty = ''
21-
_emptyb = b''
22-
_os = system().strip().lower()
19+
shebang = b'#!/usr/bin/env -S python3 -m programpack run\n'
20+
shebang_v = b'#!/usr/bin/env -S python3 -m programpack run --virtual\n'
21+
_empty = ''
22+
_emptyb = b''
23+
_os = system().strip().lower()
24+
_server = 'https://github.com/ProgramPack/hub'
25+
_request_base = '/raw/main/apps/'
26+
_server_p_rbase = '{}{}'.format(_server, _request_base)
2327

28+
def _get_text(url): return str(r_get(url).text)
29+
def _get_json(url): return loads(_get_text(url).strip())
2430
def _decode(b: bytes or bytearray) -> str: return b.decode('utf-8')
2531
def _PropertyBlocked(): raise RuntimeError('Property is privated; blocked')
2632
def _get_file_sha256(filename: str = ''):
@@ -67,6 +73,10 @@ def read_main_file(self):
6773
return self.archive.read(self.main_file)
6874
def read_resources(self) -> dict:
6975
'''Read "Resources" folder and return dictionary'''
76+
warn(
77+
'Function "read_resources" may be deprecated in future',
78+
DeprecationWarning
79+
)
7080
resources_dict = {}
7181
for resource in self.archive.namelist():
7282
if resource.startswith(self.resfold):
@@ -89,15 +99,17 @@ def run(self, w_resources: bool = True, autocall: bool = True, delete: bool = Tr
8999
args = [tempf_name]
90100
args.extend(self.call_args)
91101
if w_resources:
92-
res = self.read_resources()
93102
tmpresfold_n = join(self.tmpresfold, self.generate_unique_id())
94-
if res:
95-
mkdir(tmpresfold_n, exist_ok = True)
96-
for key in res:
97-
value = res[key]
98-
if key and value:
99-
with open(join(tmpresfold_n, key), 'wb+') as f:
100-
f.write(value['content'])
103+
mkdir(tmpresfold_n, exist_ok = True)
104+
for current_file in self.archive.namelist():
105+
if current_file.startswith(self.resfold):
106+
dest = join(tmpresfold_n, current_file.removeprefix(self.resfold))
107+
if current_file.endswith(sep): mkdir(dest, exist_ok = True)
108+
else:
109+
self.archive.extract(current_file, tmpresfold_n)
110+
move_file(join(tmpresfold_n, current_file), join(tmpresfold_n, dest))
111+
rmtree(join(tmpresfold_n, 'Resources'), ignore_errors = True)
112+
del current_file
101113
args.append(tmpresfold_n)
102114
if autocall:
103115
if virtual:
@@ -145,6 +157,7 @@ def update_icon(self, _clean: bool = False) -> bool:
145157
)
146158
remove(tempf.name)
147159
return True
160+
def generate_unique_id_local(name: str = 'unnamed', domain: str = 'com', author: str = 'unknown'): return '{}.{}.{}'.format(domain, author, name)
148161
def convert_file_to_executable(file_name: str = '', virtual: bool = False):
149162
'''Make the file executable by other programs'''
150163
chmod(file_name, 0o777)
@@ -167,3 +180,11 @@ def get_manifest(file_name: str = '') -> dict or bool:
167180
program = PackedProgram(str(file_name).strip())
168181
program.read()
169182
return program.manifest
183+
def hub_get_id_by(name: str, domain: str, author: str, *args, **kwargs): return _server_p_rbase + generate_unique_id_local(name, domain, author, *args, **kwargs) + '.json'
184+
def hub_get_meta(name: str, domain: str, author: str): return _get_json(hub_get_id_by(name, domain, author))
185+
def hub_download_s(name: str, domain: str, author: str): return _get_text(hub_get_meta(name, domain, author)['link'])
186+
def hub_download(name: str, domain: str, author: str, output: str = 'download.propack'):
187+
data = hub_download_s(name, domain, author)
188+
with open(str(output).strip(), 'w+') as f:
189+
f.write(data)
190+
chmod(output, 0o777)

programpack/__main__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def pull_from_git():
1818
except IndexError: argv2 = None
1919
try: argv3 = args[3]
2020
except IndexError: argv3 = None
21+
try: argv4 = args[4]
22+
except IndexError: argv4 = None
23+
try: argv5 = args[5]
24+
except IndexError: argv5 = None
25+
try: argv6 = args[6]
26+
except IndexError: argv6 = None
2127

2228
help_message = '''--- ProgramPack ---
2329
Commands:
@@ -44,7 +50,10 @@ def pull_from_git():
4450
version
4551
See current version
4652
manifest <fn>
47-
Print manifest of file'''
53+
Print manifest of file
54+
hub
55+
hub download <name> <domain> <author> <output>
56+
Will download ProgramPack file by name, domain and author from hub.'''
4857

4958
if 'help' in str(argv1):
5059
print(help_message)
@@ -73,6 +82,16 @@ def pull_from_git():
7382
elif argv1 == 'manifest':
7483
if argv2:
7584
print(propack.get_manifest(argv2), end = '')
85+
elif argv1 == 'hub':
86+
if argv2:
87+
if argv2 == 'download':
88+
if argv3 and argv4 and argv5:
89+
propack.hub_download(argv3, argv4, argv5, argv6 or 'output.txt')
90+
else:
91+
print('usage: hub download <name> <domain> <author> [output]')
92+
else: print('Unknown hub command. See --help')
93+
else:
94+
print('usage: hub <download, ...> <>')
7695
else:
7796
if len(args) <= 1: print('No args given. See --help.')
7897
else: print('Invalid arguments. See --help for more info.')

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests>=2.31.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
version = '0.0.1',
66
author = 'VBPROGER',
77
py_modules = ['programpack'],
8-
install_requires = [],
8+
install_requires = [open('requirements.txt', 'r+').read()],
99
packages = find_packages(),
1010
python_requires = '>=3.10',
1111
)

test/test.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
#!/usr/bin/env python3
22
import unittest, pydoc, zipfile
3+
from os import getcwd, chdir
4+
from os.path import join as join_paths
35
propack = pydoc.importfile('programpack/__init__.py')
46

57
class TestProgramPack(unittest.TestCase):
68
def setUp(self): self.propack = propack
79
def test_PackedProgram(self):
10+
captured_dir = join_paths(getcwd())
11+
chdir(captured_dir)
12+
813
program = self.propack.PackedProgram('test/testapp.propack')
914
program.read()
1015
program.run()
1116
program.close()
1217

18+
chdir(captured_dir)
19+
1320
program = self.propack.PackedProgram('test/also_testing.propack')
1421
program.read()
1522
program.update_icon()
1623
program.run()
1724
program.close()
1825

1926
if __name__ == '__main__':
20-
unittest.main()
27+
unittest.main()

0 commit comments

Comments
 (0)