Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.9", "3.10"]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ sclean:
rm -rf build
rm -rf dist
sgeneratechangelog:
git log --pretty="- %s" > CHANGELOG.md
git log --pretty="- %s" > CHANGELOG.md
Binary file added examples/blank.propack
Binary file not shown.
1 change: 1 addition & 0 deletions examples/blankapp/App
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env bash
7 changes: 7 additions & 0 deletions examples/blankapp/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "blank",
"description": "Application that does nothing",
"author": "VBPROGER",
"version": "1.0.0",
"mainfile": "App"
}
47 changes: 34 additions & 13 deletions programpack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,24 @@
from hashlib import sha256
from platform import system
from warnings import warn
from requests import get as r_get

__all__ = [
'PackedProgram', 'convert_file_to_executable', 'deconvert', 'create_archive'
]
__version__ = '0.0.1'

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

def _get_text(url): return str(r_get(url).text)
def _get_json(url): return loads(_get_text(url).strip())
def _decode(b: bytes or bytearray) -> str: return b.decode('utf-8')
def _PropertyBlocked(): raise RuntimeError('Property is privated; blocked')
def _get_file_sha256(filename: str = ''):
Expand Down Expand Up @@ -67,6 +73,10 @@ def read_main_file(self):
return self.archive.read(self.main_file)
def read_resources(self) -> dict:
'''Read "Resources" folder and return dictionary'''
warn(
'Function "read_resources" may be deprecated in future',
DeprecationWarning
)
resources_dict = {}
for resource in self.archive.namelist():
if resource.startswith(self.resfold):
Expand All @@ -89,15 +99,17 @@ def run(self, w_resources: bool = True, autocall: bool = True, delete: bool = Tr
args = [tempf_name]
args.extend(self.call_args)
if w_resources:
res = self.read_resources()
tmpresfold_n = join(self.tmpresfold, self.generate_unique_id())
if res:
mkdir(tmpresfold_n, exist_ok = True)
for key in res:
value = res[key]
if key and value:
with open(join(tmpresfold_n, key), 'wb+') as f:
f.write(value['content'])
mkdir(tmpresfold_n, exist_ok = True)
for current_file in self.archive.namelist():
if current_file.startswith(self.resfold):
dest = join(tmpresfold_n, current_file.removeprefix(self.resfold))
if current_file.endswith(sep): mkdir(dest, exist_ok = True)
else:
self.archive.extract(current_file, tmpresfold_n)
move_file(join(tmpresfold_n, current_file), join(tmpresfold_n, dest))
rmtree(join(tmpresfold_n, 'Resources'), ignore_errors = True)
del current_file
args.append(tmpresfold_n)
if autocall:
if virtual:
Expand Down Expand Up @@ -145,6 +157,7 @@ def update_icon(self, _clean: bool = False) -> bool:
)
remove(tempf.name)
return True
def generate_unique_id_local(name: str = 'unnamed', domain: str = 'com', author: str = 'unknown'): return '{}.{}.{}'.format(domain, author, name)
def convert_file_to_executable(file_name: str = '', virtual: bool = False):
'''Make the file executable by other programs'''
chmod(file_name, 0o777)
Expand All @@ -167,3 +180,11 @@ def get_manifest(file_name: str = '') -> dict or bool:
program = PackedProgram(str(file_name).strip())
program.read()
return program.manifest
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'
def hub_get_meta(name: str, domain: str, author: str): return _get_json(hub_get_id_by(name, domain, author))
def hub_download_s(name: str, domain: str, author: str): return _get_text(hub_get_meta(name, domain, author)['link'])
def hub_download(name: str, domain: str, author: str, output: str = 'download.propack'):
data = hub_download_s(name, domain, author)
with open(str(output).strip(), 'w+') as f:
f.write(data)
chmod(output, 0o777)
21 changes: 20 additions & 1 deletion programpack/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def pull_from_git():
except IndexError: argv2 = None
try: argv3 = args[3]
except IndexError: argv3 = None
try: argv4 = args[4]
except IndexError: argv4 = None
try: argv5 = args[5]
except IndexError: argv5 = None
try: argv6 = args[6]
except IndexError: argv6 = None

help_message = '''--- ProgramPack ---
Commands:
Expand All @@ -44,7 +50,10 @@ def pull_from_git():
version
See current version
manifest <fn>
Print manifest of file'''
Print manifest of file
hub
hub download <name> <domain> <author> <output>
Will download ProgramPack file by name, domain and author from hub.'''

if 'help' in str(argv1):
print(help_message)
Expand Down Expand Up @@ -73,6 +82,16 @@ def pull_from_git():
elif argv1 == 'manifest':
if argv2:
print(propack.get_manifest(argv2), end = '')
elif argv1 == 'hub':
if argv2:
if argv2 == 'download':
if argv3 and argv4 and argv5:
propack.hub_download(argv3, argv4, argv5, argv6 or 'output.txt')
else:
print('usage: hub download <name> <domain> <author> [output]')
else: print('Unknown hub command. See --help')
else:
print('usage: hub <download, ...> <>')
else:
if len(args) <= 1: print('No args given. See --help.')
else: print('Invalid arguments. See --help for more info.')
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests>=2.31.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
version = '0.0.1',
author = 'VBPROGER',
py_modules = ['programpack'],
install_requires = [],
install_requires = [open('requirements.txt', 'r+').read()],
packages = find_packages(),
python_requires = '>=3.10',
)
9 changes: 8 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
#!/usr/bin/env python3
import unittest, pydoc, zipfile
from os import getcwd, chdir
from os.path import join as join_paths
propack = pydoc.importfile('programpack/__init__.py')

class TestProgramPack(unittest.TestCase):
def setUp(self): self.propack = propack
def test_PackedProgram(self):
captured_dir = join_paths(getcwd())
chdir(captured_dir)

program = self.propack.PackedProgram('test/testapp.propack')
program.read()
program.run()
program.close()

chdir(captured_dir)

program = self.propack.PackedProgram('test/also_testing.propack')
program.read()
program.update_icon()
program.run()
program.close()

if __name__ == '__main__':
unittest.main()
unittest.main()