Skip to content

Commit

Permalink
Merge pull request #15 from PortsMaster/dev
Browse files Browse the repository at this point in the history
Added PortMaster installation scripts, updated language files.
  • Loading branch information
kloptops authored Oct 7, 2023
2 parents 2d1b1e4 + cd53ef2 commit 992e0d7
Show file tree
Hide file tree
Showing 16 changed files with 755 additions and 580 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Create PortMaster.zip
id: create-zip
run: |
./do_release.sh ${{steps.version.outputs.version}}
./do_release.sh release
- name: Create md5 hashes
id: md5
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,9 @@ harbourmaster.txt
PortMaster.zip
pylibs.zip
version

# PortMaster Installer scripts.
makeself*/
makeself-*.run
runtimes.zip
Install*PortMaster.sh
18 changes: 12 additions & 6 deletions PortMaster/pugwash
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

## -- BEGIN PORTMASTER INFO --
PORTMASTER_VERSION = '8.4.14'
PORTMASTER_VERSION = '8.4.15'
PORTMASTER_RELEASE_CHANNEL = 'beta'
## -- END PORTMASTER INFO --

Expand All @@ -27,6 +27,7 @@ import re
import shutil
import sys
import textwrap
import time
import zipfile

from pathlib import Path
Expand Down Expand Up @@ -223,10 +224,10 @@ gettext.textdomain('messages')
## Code starts here.

__IP_ADDRESS=None
def get_ip_address():
def get_ip_address(force_update=False):
global __IP_ADDRESS

if __IP_ADDRESS is not None:
if not force_update and __IP_ADDRESS is not None:
return __IP_ADDRESS

import socket
Expand All @@ -239,7 +240,7 @@ def get_ip_address():
__IP_ADDRESS = s.getsockname()[0]

except Exception:
__IP_ADDRESS = _("Unknown IP")
__IP_ADDRESS = None

finally:
s.close()
Expand Down Expand Up @@ -522,7 +523,7 @@ class PortMasterGUI(pySDL2gui.GUI, harbourmaster.Callback):
# 'rg503'
# 'rg351v'
# 'rg353v'
'rgb30'
# 'rgb30'
# 'ogs'
# 'ogu'
# 'x55'
Expand Down Expand Up @@ -614,7 +615,7 @@ class PortMasterGUI(pySDL2gui.GUI, harbourmaster.Callback):
self.set_data('system.cfw_name', device_info['name'])
self.set_data('system.cfw_version', device_info['version'])
self.set_data('system.device_name', device_info['device'])
self.set_data('system.ip_address', get_ip_address())
self.set_data('system.ip_address', get_ip_address() or _("Unknown IP"))
self.set_data('system.progress_text', "")
self.set_data('system.progress_amount', "")
self.set_data('system.progress_perc_5', "0")
Expand Down Expand Up @@ -1704,6 +1705,11 @@ def main(argv):
global LOG_FILE_HANDLE
global LOG_FILE

if not get_ip_address():
print(_("No network connection available."))
time.sleep(5)
return 255

with make_temp_directory() as temp_dir:
argv = argv[:]

Expand Down
2 changes: 2 additions & 0 deletions PortMaster/pylibs/harbourmaster/harbour.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ def load_ports(self):
'portmaster.sh',
'thememaster',
'thememaster.sh',
'install portmaster.sh',
'install full portmaster.sh',
'videos',
):
continue
Expand Down
112 changes: 67 additions & 45 deletions PortMaster/pylibs/harbourmaster/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def json_safe_load(*args):


def fetch(url):
r = requests.get(url)
r = requests.get(url, timeout=10)
if r.status_code != 200:
logger.error(f"Failed to download {url!r}: {r.status_code}")
return None
Expand Down Expand Up @@ -173,19 +173,29 @@ def load_pm_signature(file_name):
if not file_name.is_file():
return None

if file_name.suffix.casefold() not in ('.sh', ):
if file_name.suffix.lower() not in ('.sh', ):
return None

for line in file_name.read_text().split('\n'):
if not line.strip().startswith('#'):
continue
try:
for line in file_name.read_text().split('\n'):
if not line.strip().startswith('#'):
continue

if 'PORTMASTER:' not in line:
continue

return [
item.strip()
for item in line.split(':', 1)[1].strip().split(',', 1)]

if 'PORTMASTER:' not in line:
continue
except UnicodeDecodeError as err:
logger.error(f"Error loading {file_name}: {err}")
return None

return [
item.strip()
for item in line.split(':', 1)[1].strip().split(',', 1)]
except Exception as err:
# Bad but we will live.
logger.error(f"Error loading {file_name}: {err}")
return None

return None

Expand All @@ -201,7 +211,7 @@ def add_pm_signature(file_name, info):
if not file_name.is_file():
return

if file_name.suffix.casefold() not in ('.sh', ):
if file_name.suffix.lower() not in ('.sh', ):
return

# See if it has some info already.
Expand Down Expand Up @@ -292,53 +302,65 @@ def download(file_name, file_url, md5_source=None, md5_result=None, callback=Non
if md5_result is None:
md5_result = [None]

r = requests.get(file_url, stream=True)
try:
r = requests.get(file_url, stream=True, timeout=(10, 5))

if r.status_code != 200:
if callback is not None:
callback.message_box(_("Unable to download file. [{status_code}]").format(status_code=r.status_code))
if r.status_code != 200:
if callback is not None:
callback.message_box(_("Unable to download file. [{status_code}]").format(status_code=r.status_code))

logger.error(f"Unable to download file: {file_url!r} [{r.status_code}]")
return None
logger.error(f"Unable to download file: {file_url!r} [{r.status_code}]")
return None

total_length = r.headers.get('content-length')
if total_length is None:
total_length = None
total_length_mb = "???? MB"
else:
total_length = int(total_length)
total_length_mb = nice_size(total_length)
total_length = r.headers.get('content-length')
if total_length is None:
total_length = None
total_length_mb = "???? MB"
else:
total_length = int(total_length)
total_length_mb = nice_size(total_length)

md5 = hashlib.md5()
md5 = hashlib.md5()

if callback is not None:
callback.message(_("Downloading {file_url} - ({total_length_mb})").format(file_url=file_url, total_length_mb=total_length_mb))
else:
cprint(f"Downloading <b>{file_url!r}</b> - <b>{total_length_mb}</b>")
if callback is not None:
callback.message(_("Downloading {file_url} - ({total_length_mb})").format(file_url=file_url, total_length_mb=total_length_mb))
else:
cprint(f"Downloading <b>{file_url!r}</b> - <b>{total_length_mb}</b>")

length = 0
with file_name.open('wb') as fh:
for data in r.iter_content(chunk_size=104096, decode_unicode=False):
md5.update(data)
fh.write(data)
length += len(data)

if callback is not None:
callback.progress(_("Downloading file."), length, total_length, 'data')
else:
if total_length is None:
sys.stdout.write(f"\r[{'?' * 40}] - {nice_size(length)} / {total_length_mb} ")
else:
amount = int(length / total_length * 40)
sys.stdout.write(f"\r[{'|' * amount}{' ' * (40 - amount)}] - {nice_size(length)} / {total_length_mb} ")

sys.stdout.flush()

length = 0
with file_name.open('wb') as fh:
for data in r.iter_content(chunk_size=104096, decode_unicode=False):
md5.update(data)
fh.write(data)
length += len(data)
if callback is None:
cprint("\n")

if callback is not None:
callback.progress(_("Downloading file."), length, total_length, 'data')
else:
if total_length is None:
sys.stdout.write(f"\r[{'?' * 40}] - {nice_size(length)} / {total_length_mb} ")
else:
amount = int(length / total_length * 40)
sys.stdout.write(f"\r[{'|' * amount}{' ' * (40 - amount)}] - {nice_size(length)} / {total_length_mb} ")

sys.stdout.flush()
except requests.RequestException as err:
if file_name.is_file():
file_name.unlink()

if callback is None:
cprint("\n")
logger.error(f"Requests error: {err}")

if callback is not None:
callback.progress(_("Downloading file."), length, total_length, 'data')
callback.message_box(_("Download failed: {err}").format(err=str(err)))

return None

md5_file = md5.hexdigest()
if md5_source is not None:
Expand Down
Loading

0 comments on commit 992e0d7

Please sign in to comment.