Skip to content

Commit

Permalink
Added initial support for EmuELEC.
Browse files Browse the repository at this point in the history
  • Loading branch information
kloptops committed Nov 10, 2023
1 parent 8c92f91 commit 8d4cfe8
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ config/


ports/
ports_scripts/
themes/
*.squashfs
*.squashfs.md5
Expand Down
2 changes: 2 additions & 0 deletions PortMaster/pylibs/harbourmaster/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from .config import (
HM_DEFAULT_PORTS_DIR,
HM_DEFAULT_SCRIPTS_DIR,
HM_DEFAULT_TOOLS_DIR,
HM_GENRES,
HM_PORTS_DIR,
HM_SCRIPTS_DIR,
HM_SORT_ORDER,
HM_SOURCE_DEFAULTS,
HM_TESTING,
Expand Down
26 changes: 26 additions & 0 deletions PortMaster/pylibs/harbourmaster/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

HM_TOOLS_DIR=None
HM_PORTS_DIR=None
HM_SCRIPTS_DIR=None
HM_UPDATE_FREQUENCY=(60 * 60 * 1) # Only check automatically once per hour.

HM_TESTING=False
Expand All @@ -25,6 +26,7 @@
################################################################################
## The following code is a simplification of the PortMaster toolsloc and whichsd code.
HM_DEFAULT_PORTS_DIR = Path("/roms/ports")
HM_DEFAULT_SCRIPTS_DIR = Path("/roms/ports")
HM_DEFAULT_TOOLS_DIR = Path("/roms/ports")

if (Path().cwd() / '..' / '.git').is_dir():
Expand All @@ -34,19 +36,26 @@
## For testing
HM_DEFAULT_TOOLS_DIR = Path('.').absolute()
HM_DEFAULT_PORTS_DIR = Path('ports/').absolute()
HM_DEFAULT_SCRIPTS_DIR = Path('ports_scripts/').absolute()
HM_TESTING=True
elif Path("/opt/tools/PortMaster/").is_dir():
HM_DEFAULT_TOOLS_DIR = Path("/opt/tools")
elif Path("/opt/system/Tools/PortMaster/").is_dir():
HM_DEFAULT_TOOLS_DIR = Path("/opt/system/Tools")
elif Path("/storage/roms/ports_scripts").is_dir():
HM_DEFAULT_TOOLS_DIR = Path("/storage/roms/ports")
HM_DEFAULT_PORTS_DIR = Path("/storage/roms/ports")
HM_DEFAULT_SCRIPTS_DIR = Path("/storage/roms/ports_scripts")
elif Path("/storage/roms/ports").is_dir():
HM_DEFAULT_TOOLS_DIR = Path("/storage/roms/ports")
HM_DEFAULT_PORTS_DIR = Path("/storage/roms/ports")
HM_DEFAULT_SCRIPTS_DIR = Path("/storage/roms/ports")
else:
HM_DEFAULT_TOOLS_DIR = Path("/roms/ports")

if Path("/roms2/ports").is_dir():
HM_DEFAULT_PORTS_DIR = Path("/roms2/ports")
HM_DEFAULT_SCRIPTS_DIR = Path("/roms2/ports")

## Default TOOLS_DIR
if HM_TOOLS_DIR is None:
Expand Down Expand Up @@ -79,6 +88,21 @@
logger.error(f"{HM_PORTS_DIR!r} is set to something weird.")
exit(255)

## Default TOOLS_DIR
if HM_SCRIPTS_DIR is None:
if 'HM_SCRIPTS_DIR' in os.environ:
HM_SCRIPTS_DIR = Path(os.environ['HM_SCRIPTS_DIR'])
else:
HM_SCRIPTS_DIR = HM_DEFAULT_SCRIPTS_DIR
elif isinstance(HM_SCRIPTS_DIR, str):
HM_SCRIPTS_DIR = Path(HM_SCRIPTS_DIR).resolve()
elif isinstance(HM_SCRIPTS_DIR, pathlib.PurePath):
# This is good.
pass
else:
logger.error(f"{HM_SCRIPTS_DIR!r} is set to something weird.")
exit(255)


if 'HM_PERFTEST' in os.environ:
HM_PERFTEST=True
Expand Down Expand Up @@ -139,9 +163,11 @@
__all__ = (
'HM_DEFAULT_PORTS_DIR',
'HM_DEFAULT_TOOLS_DIR',
'HM_DEFAULT_SCRIPTS_DIR',
'HM_GENRES',
'HM_PERFTEST',
'HM_PORTS_DIR',
'HM_SCRIPTS_DIR',
'HM_SORT_ORDER',
'HM_SOURCE_DEFAULTS',
'HM_TESTING',
Expand Down
106 changes: 82 additions & 24 deletions PortMaster/pylibs/harbourmaster/harbour.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class HarbourMaster():
PORTERS_URL = PORT_INFO_URL + "porters.json"
SOURCES_URL = PORT_INFO_URL + "sources.json"

def __init__(self, config, *, tools_dir=None, ports_dir=None, temp_dir=None, callback=None):
def __init__(self, config, *, tools_dir=None, ports_dir=None, scripts_dir=None, temp_dir=None, callback=None):
"""
config = load_config()
"""
Expand All @@ -64,6 +64,9 @@ def __init__(self, config, *, tools_dir=None, ports_dir=None, temp_dir=None, cal
if ports_dir is None:
ports_dir = HM_PORTS_DIR

if scripts_dir is None:
scripts_dir = HM_SCRIPTS_DIR

if isinstance(tools_dir, str):
tools_dir = Path(tools_dir)
elif not isinstance(tools_dir, pathlib.PurePath):
Expand All @@ -83,6 +86,7 @@ def __init__(self, config, *, tools_dir=None, ports_dir=None, temp_dir=None, cal
self.libs_dir = tools_dir / "PortMaster" / "libs"
self.themes_dir = tools_dir / "PortMaster" / "themes"
self.ports_dir = ports_dir
self.scripts_dir = scripts_dir
self.cfg_file = self.cfg_dir / "config.json"

self.sources = {}
Expand All @@ -105,6 +109,7 @@ def __init__(self, config, *, tools_dir=None, ports_dir=None, temp_dir=None, cal
self.utils = []

self.ports_dir.mkdir(0o755, parents=True, exist_ok=True)
self.scripts_dir.mkdir(0o755, parents=True, exist_ok=True)
self.themes_dir.mkdir(0o755, parents=True, exist_ok=True)
self.libs_dir.mkdir(0o755, parents=True, exist_ok=True)

Expand Down Expand Up @@ -428,6 +433,43 @@ def _load_port_info(self, port_file):

return port_info

def _iter_ports_dir(self):
if self.ports_dir != self.scripts_dir:
yield from self.scripts_dir.iterdir()

yield from self.ports_dir.iterdir()

def _ports_dir_exists(self, file_name):
if (self.scripts_dir / file_name).exists():
return True

return (self.ports_dir / file_name).exists()

def _ports_dir_is_file(self, file_name):
if (self.scripts_dir / file_name).is_file():
return True

return (self.ports_dir / file_name).is_file()

def _ports_dir_is_dir(self, file_name):
if (self.scripts_dir / file_name).is_dir():
return True

return (self.ports_dir / file_name).is_dir()

def _ports_dir_relative_to(self, path):
try:
return path.relative_to(self.scripts_dir)

except ValueError:
return path.relative_to(self.ports_dir)

def _ports_dir_file(self, file_name, is_script=False):
if is_script:
return (self.scripts_dir / file_name)

return (self.ports_dir / file_name)

@timeit
def load_ports(self):
"""
Expand Down Expand Up @@ -480,7 +522,7 @@ def load_ports(self):
# The files attribute keeps track of file renames.
if port_info.get('files', None) is None:
port_info['files'] = {
'port.json': str(port_file.relative_to(self.ports_dir)),
'port.json': str(self._ports_dir_relative_to(self.ports_dir)),
}
port_info['changed'] = True

Expand All @@ -496,7 +538,7 @@ def load_ports(self):
for item in port_info['items']:
add_dict_list_unique(all_items, item, port_info['name'])

if (self.ports_dir / item).exists():
if self._ports_dir_exists(item):
if item not in get_dict_list(port_info['files'], item):
add_dict_list_unique(port_info['files'], item, item)
port_info['changed'] = True
Expand All @@ -505,7 +547,7 @@ def load_ports(self):
for item in get_dict_list(port_info, 'items_opt'):
add_dict_list_unique(all_items, item, port_info['name'])

if (self.ports_dir / item).exists():
if self._ports_dir_exists(item):
if item not in get_dict_list(port_info['files'], item):
add_dict_list_unique(port_info['files'], item, item)
port_info['changed'] = True
Expand All @@ -514,7 +556,7 @@ def load_ports(self):
ports_files[port_info['name']] = port_file

## Phase 2: Check all files
for file_item in self.ports_dir.iterdir():
for file_item in self._iter_ports_dir():
## Skip these
if file_item.name.casefold() in (
'gamelist.xml',
Expand Down Expand Up @@ -594,10 +636,10 @@ def load_ports(self):

unknown_files.append(file_name)

# from pprint import pprint
# pprint(all_items)
# pprint(file_renames)
# pprint(unknown_files)
from pprint import pprint
pprint(all_items)
pprint(file_renames)
pprint(unknown_files)

## Create new ports.
new_ports = []
Expand Down Expand Up @@ -635,7 +677,7 @@ def load_ports(self):

port_info = port_info_load(port_info_raw)

port_file = self.ports_dir / port_info_raw['file']
port_file = self._ports_dir_file(port_info_raw['file'])

## Load extra info
for source in self.sources.values():
Expand All @@ -655,7 +697,9 @@ def load_ports(self):
port_info['attr']['porter'] = ['Unknown']

if isinstance(port_info['attr']['porter'], str):
port_info['attr']['porter'] = ports_info['portsmd_fix'].get(port_info['attr']['porter'].lower(), port_info['attr']['porter'])
port_info['attr']['porter'] = ports_info['portsmd_fix'].get(
port_info['attr']['porter'].lower(),
port_info['attr']['porter'])

if port_info.get('status', None) is None:
port_info['status'] = {}
Expand All @@ -672,28 +716,28 @@ def load_ports(self):

# Add all the root dirs/scripts in the port
for item in port_info['items']:
if (self.ports_dir / item).exists():
if self._ports_dir_exists(item):
if item not in get_dict_list(port_info['files'], item):
add_dict_list_unique(port_info['files'], item, item)
port_info['changed'] = True

if item in file_renames:
item_rename = file_renames[item]
if (self.ports_dir / item_rename).exists():
if self._ports_dir_exists(item_rename):
if item_rename not in get_dict_list(port_info['files'], item):
add_dict_list_unique(port_info['files'], item, item_rename)
port_info['changed'] = True

# And any optional ones.
for item in get_dict_list(port_info, 'items_opt'):
if (self.ports_dir / item).exists():
if self._ports_dir_exists(item):
if item not in get_dict_list(port_info['files'], item):
add_dict_list_unique(port_info['files'], item, item)
port_info['changed'] = True

if item in file_renames:
item_rename = file_renames[item]
if (self.ports_dir / item_rename).exists():
if self._ports_dir_exists(item_rename):
if item_rename not in get_dict_list(port_info['files'], item):
add_dict_list_unique(port_info['files'], item, item_rename)
port_info['changed'] = True
Expand All @@ -711,7 +755,7 @@ def load_ports(self):
file_names = get_dict_list(port_info['files'], port_file)

for file_name in list(file_names):
if not (self.ports_dir / file_name).exists():
if not self._ports_dir_exists(file_name):
remove_dict_list(port_info['files'], port_file, file_name)
port_info['changed'] = True

Expand Down Expand Up @@ -1184,7 +1228,12 @@ def _install_port(self, download_info):
self.callback.progress(_("Installing"), file_number+1, total_files, '%')
self.callback.message(f"- {file_info.filename}")

dest_file = path=self.ports_dir / file_info.filename
is_script = (
file_info.filename.endswith('.sh') and
file_info.filename.count('/') == 0)

dest_file = path = self._ports_dir_file(file_info.filename, is_script)
dest_dir = (is_script and self.scripts_dir or self.ports_dir)

if not file_info.filename.endswith('/'):
if not dest_file.parent.is_dir():
Expand All @@ -1194,7 +1243,7 @@ def _install_port(self, download_info):
add_list_unique(undo_data, dest_file)

# cprint(f"- <b>{file_info.filename!r}</b> <d>[{nice_size(file_info.file_size)} ({compress_saving:.0f}%)]</d>")
zf.extract(file_info, path=self.ports_dir)
zf.extract(file_info, path=dest_dir)

# print(f"Port Info: {port_info}")
# print(f"Download Info: {download_info}")
Expand All @@ -1211,12 +1260,12 @@ def _install_port(self, download_info):
del port_info['source']

port_info['files'] = {
'port.json': str(port_info_file.relative_to(self.ports_dir)),
'port.json': str(self._ports_dir_relative_to(port_info_file)),
}

# Add all the root dirs/scripts in the port
for item in port_info['items']:
if (self.ports_dir / item).exists():
if self._ports_dir_exists(item):
if item not in get_dict_list(port_info['files'], item):
add_dict_list_unique(port_info['files'], item, item)

Expand All @@ -1225,7 +1274,7 @@ def _install_port(self, download_info):

# And any optional ones.
for item in get_dict_list(port_info, 'items_opt'):
if (self.ports_dir / item).exists():
if self._ports_dir_exists(item):
if item not in get_dict_list(port_info['files'], item):
add_dict_list_unique(port_info['files'], item, item)

Expand Down Expand Up @@ -1614,9 +1663,6 @@ def uninstall_port(self, port_name):

ports_dir = self.ports_dir

if not ports_dir.is_absolute():
ports_dir = ports_dir.resolve()

uninstall_items = [
item
for item in all_port_items
Expand All @@ -1638,6 +1684,18 @@ def uninstall_port(self, port_name):
elif item_path.is_file():
item_path.unlink()

item_path = self.scripts_dir / item

if item_path.exists():
cprint(f"- removing {item}")
self.callback.message(f"- {item}")

if item_path.is_dir():
shutil.rmtree(item_path)

elif item_path.is_file():
item_path.unlink()

self.callback.message_box(_("Successfully uninstalled {port_name}").format(port_name=port_info_name))

del port_loc[port_name.casefold()]
Expand Down
8 changes: 7 additions & 1 deletion PortMaster/pylibs/harbourmaster/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def portmaster_install(self):

## Copy the files as per usual.
shutil.copy(JELOS_PM_DIR / "control.txt", PM_DIR / "control.txt")
shutil.copy(JELOS_PM_DIR / "gptokeyb", PM_DIR / "gptokeyb")
# shutil.copy(JELOS_PM_DIR / "gptokeyb", PM_DIR / "gptokeyb")
shutil.copy(JELOS_PM_DIR / "gamecontrollerdb.txt", PM_DIR / "gamecontrollerdb.txt")
shutil.copy(JELOS_PM_DIR / "mapper.txt", PM_DIR / "mapper.txt")

Expand All @@ -191,10 +191,16 @@ class PlatformAmberELEC(PlatformGCD_PortMaster, PlatformBase):
ES_NAME = 'emustation'


class PlatformEmuELEC(PlatformGCD_PortMaster, PlatformBase):
MOVE_PM_BASH = True
ES_NAME = 'emustation'


HM_PLATFORMS = {
'jelos': PlatformJELOS,
'arkos': PlatformArkOS,
'amberelec': PlatformAmberELEC,
'emuelec': PlatformEmuELEC,
'unofficialos': PlatformUOS,
'default': PlatformBase,
# 'default': PlatformAmberELEC,
Expand Down

0 comments on commit 8d4cfe8

Please sign in to comment.