diff --git a/code/custom-conversions/dfend_reloaded_source_releases_to_git.py b/code/custom-conversions/dfend_reloaded_source_releases_to_git.py index 22e881f3..a91ad6e2 100644 --- a/code/custom-conversions/dfend_reloaded_source_releases_to_git.py +++ b/code/custom-conversions/dfend_reloaded_source_releases_to_git.py @@ -49,7 +49,7 @@ def single_release(zip): # get date from the files (latest of last modified) latest_last_modified = 0 - for dirpath, dirnames, filenames in os.walk(git_path): + for dirpath, dirnames, filenames in git_path.walk(): if dirpath.startswith(git_path / '.git'): # not in '.git' continue diff --git a/code/custom-conversions/dungeon_crawl_source_releases_to_git.py b/code/custom-conversions/dungeon_crawl_source_releases_to_git.py index 9292cc1e..6d75cd14 100644 --- a/code/custom-conversions/dungeon_crawl_source_releases_to_git.py +++ b/code/custom-conversions/dungeon_crawl_source_releases_to_git.py @@ -71,7 +71,7 @@ def single_revision(): global original_date if original_date is None: latest_last_modified = 0 - for dirpath, dirnames, filenames in os.walk(nonempty_temp_path): + for dirpath, dirnames, filenames in nonempty_temp_path.walk(): for filename in filenames: filepath = dirpath / filename lastmodified = os.path.getmtime(filepath) diff --git a/code/custom-conversions/lechemindeladam_svn_to_git.py b/code/custom-conversions/lechemindeladam_svn_to_git.py index b19a061b..753bb073 100644 --- a/code/custom-conversions/lechemindeladam_svn_to_git.py +++ b/code/custom-conversions/lechemindeladam_svn_to_git.py @@ -180,7 +180,7 @@ def delete_global_excludes(folder): """ """ - for dirpath, dirnames, filenames in os.walk(folder): + for dirpath, dirnames, filenames in folder.walk(): rel_path = os.path.relpath(dirpath, folder) for file in filenames: if file in global_exclude: @@ -191,7 +191,7 @@ def delete_empty_directories(folder): """ """ - for dirpath, dirnames, filenames in os.walk(folder, topdown=False): + for dirpath, dirnames, filenames in folder.walk(topdown=False): rel_path = os.path.relpath(dirpath, folder) if not filenames and not dirnames: os.removedirs(dirpath) @@ -202,7 +202,7 @@ def list_large_unwanted_files(folder): """ output = [] - for dirpath, dirnames, filenames in os.walk(folder): + for dirpath, dirnames, filenames in folder.walk(): rel_path = os.path.relpath(dirpath, folder) for file in filenames: file_path = dirpath / file diff --git a/code/helpers/is_already_included.py b/code/helpers/is_already_included.py index 260dd405..f4702e0a 100644 --- a/code/helpers/is_already_included.py +++ b/code/helpers/is_already_included.py @@ -16,7 +16,7 @@ def similarity(a, b): if __name__ == "__main__": similarity_threshold = 0.7 - root_path = os.path.realpath(os.path.dirname(__file__) / os.path.pardir) + root_path = os.path.realpath(__file__.parent / os.path.pardir) # read docs/data.json data_file = root_path / 'docs', 'data.json' diff --git a/code/helpers/list_python_external_imports.py b/code/helpers/list_python_external_imports.py index f107b34a..7f22a19d 100644 --- a/code/helpers/list_python_external_imports.py +++ b/code/helpers/list_python_external_imports.py @@ -13,8 +13,11 @@ def local_module(module_base, file_path, module): """ module = module.split('.') module[-1] += '.py' - pathA = module_base / *module - pathB = file_path / *module + pathA = module_base + pathB = file_path + for part in module: + pathA /= part + pathB /= part return pathA.exists() or pathB.exists() @@ -32,13 +35,13 @@ def local_module(module_base, file_path, module): regex_as = re.compile(r"(as.*)$", re.MULTILINE) # modify these locations - root_folder = r'' - module_base = r'' + root_folder = pathlib.Path(r'') + module_base = pathlib.Path(r'') # get all *.py files below the root_folder python_files = [] setup_files = [] - for dirpath, dirnames, filenames in os.walk(root_folder): + for dirpath, dirnames, filenames in root_folder.walk(): for file in ('setup.py', 'requirements.txt'): if file in filenames: setup_files.append(dirpath / file) @@ -80,7 +83,7 @@ def local_module(module_base, file_path, module): matches = regex_from.findall(content) for match in matches: - module = match[0] # only the from part + module = match[0] # only from part module = module.strip() if not local_module(module_base, file_path, module): imports.append(module) diff --git a/code/html/generate_static_website.py b/code/html/generate_static_website.py index 04112f6a..a8f634dc 100644 --- a/code/html/generate_static_website.py +++ b/code/html/generate_static_website.py @@ -223,16 +223,18 @@ def raise_helper(msg): raise Exception(msg) -def write(text, file): +def write(text, path): """ Writes a generated HTML page to a file, but checks with a HTML parser before. :param text: :param file: """ # output file - if isinstance(file, str): - file = [file] - file = c.web_path / file + if isinstance(path, str): + path = [path] + file = c.web_path + for part in path: + file /= part # check file hash and use previous version if file in previous_files and previous_files[file]['hash'] == file_hash(text): @@ -248,9 +250,7 @@ def write(text, file): raise RuntimeError(e) # create output directory if necessary - containing_dir = os.path.dirname(file) - if not containing_dir.is_dir(): - containing_dir.mkdir() + file.parent.mkdir(parents=True, exist_ok=True) # write text utils.write_text(file, text) @@ -1032,14 +1032,14 @@ def generate(entries, inspirations, developers): utils.copy_tree(c.web_template_path / 'js', c.web_js_path) # copy screenshots path - files = [file for file in c.screenshots_path.iterdir() if file.endswith('.jpg')] + filenames = [file.name for file in c.screenshots_path.iterdir() if file.suffix == '.jpg'] c.web_screenshots_path.mkdir(parents=True, exist_ok=True) - for file in files: - shutil.copyfile(c.screenshots_path / file, c.web_screenshots_path / file) + for filename in filenames: + shutil.copyfile(c.screenshots_path / filename, c.web_screenshots_path / filename) # collage_image and google search console token and favicon.svg - for file in ('collage_games.jpg', 'google1f8a3863114cbcb3.html', 'favicon.svg'): - shutil.copyfile(c.web_template_path / file, c.web_path / file) + for filename in ('collage_games.jpg', 'google1f8a3863114cbcb3.html', 'favicon.svg'): + shutil.copyfile(c.web_template_path / filename, c.web_path / filename) # create Jinja Environment environment = Environment(loader=FileSystemLoader(c.web_template_path), autoescape=True) @@ -1287,12 +1287,12 @@ def generate(entries, inspirations, developers): # create dictionary of file hashes print('estimate file hashes') - for dirpath, dirnames, filenames in os.walk(c.web_path): # TODO in Python 3.12 Path.walk() exists - for file in filenames: - if any(file.endswith(ext) for ext in ('.html', '.svg')): - file = pathlib.Path(dirpath) / file - text = utils.read_text(file) - previous_files[file] = {'hash': file_hash(text), 'text': text} + for dirpath, dirnames, filenames in c.web_path.walk(): # TODO in Python 3.12 Path.walk() exists + for filename in filenames: + if any(filename.endswith(ext) for ext in ('.html', '.svg')): + filename = dirpath / filename + text = utils.read_text(filename) + previous_files[filename] = {'hash': file_hash(text), 'text': text} # clean the output directory print('clean current static website') diff --git a/code/html/osgameclones_download_images_create_collage.py b/code/html/osgameclones_download_images_create_collage.py index c040d6ad..68865267 100644 --- a/code/html/osgameclones_download_images_create_collage.py +++ b/code/html/osgameclones_download_images_create_collage.py @@ -184,7 +184,7 @@ def assemble_collage(): N = Nx * Ny # paths - root_path = os.path.realpath(os.path.dirname(__file__) / os.path.pardir) + root_path = os.path.realpath(__file__.parent / os.path.pardir) download_path = root_path / 'code' / 'images-download' downsized_path = download_path / 'downsized' output_file = root_path / 'code' / 'collage_games.jpg' diff --git a/code/maintenance_entries.py b/code/maintenance_entries.py index eda79ac5..c34c20a3 100644 --- a/code/maintenance_entries.py +++ b/code/maintenance_entries.py @@ -114,7 +114,6 @@ def write_entries(self): osg.write_entries(self.entries) print('entries written') - def check_template_leftovers(self): """ Checks for template leftovers. @@ -130,7 +129,7 @@ def check_template_leftovers(self): for check_string in check_strings: if content.find(check_string) >= 0: - print(f'{os.path.basename(entry_path)}: found {check_string}') + print(f'{entry_path.parent}: found {check_string}') print('checked for template leftovers') def check_inconsistencies(self): diff --git a/code/requirements.txt b/code/requirements.txt index 0ac2b1bb..96712ecd 100644 --- a/code/requirements.txt +++ b/code/requirements.txt @@ -1,7 +1,7 @@ pygithub lark-parser BeautifulSoup4 -PyQt5 +PySide6 wikipedia Jinja2 html5lib diff --git a/code/synchronization/osgameclones_synchronization.py b/code/synchronization/osgameclones_synchronization.py index 548baa8f..623449b1 100644 --- a/code/synchronization/osgameclones_synchronization.py +++ b/code/synchronization/osgameclones_synchronization.py @@ -1,4 +1,4 @@ -""" +""" osgameclones has the following fields: 'updated', 'video', 'repo', 'license', 'originals', 'status', 'multiplayer', 'info', 'lang', 'feed', 'content', 'images', 'url', 'name', 'framework', 'type', 'development' @@ -152,7 +152,7 @@ def create_many_to_one_mapping(map): download_missing_screenshots = False # paths - root_path = os.path.realpath(os.path.dirname(__file__) / os.path.pardir, os.path.pardir) + root_path = c.root_path # read our database our_entries = osg.read_entries() @@ -171,8 +171,7 @@ def create_many_to_one_mapping(map): screenshots = osg.read_screenshots_overview() # import osgameclones data - osgc_path = os.path.realpath(os.path.join(root_path, os.path.pardir, '11_osgameclones.git', - 'games')) # this is specific for my local constellation + osgc_path = root_path.parent / '11_osgameclones.git' / 'games' # this is specific for my local constellation osgc_files = osgc_path.iterdir() # iterate over all yaml files in osgameclones/data folder and load contents @@ -499,10 +498,10 @@ def create_many_to_one_mapping(map): print(f'create new entry for {osgc_name}') file_name = osg.canonical_name(osgc_name) + '.md' target_file = c.entries_path / file_name - if os.path.isfile(target_file): + if target_file.is_file(): print(f'warning: file {file_name} already existing, save under slightly different name') target_file = c.entries_path / file_name[:-3] + '-duplicate.md' - if os.path.isfile(target_file): + if target_file.is_file(): continue # just for safety reasons # add Title and File diff --git a/code/synchronization/screenshot_import_bzt.py b/code/synchronization/screenshot_import_bzt.py index ef82daf1..b4fb2c28 100644 --- a/code/synchronization/screenshot_import_bzt.py +++ b/code/synchronization/screenshot_import_bzt.py @@ -13,7 +13,7 @@ if __name__ == "__main__": # paths - root_path = os.path.realpath(os.path.dirname(__file__) / os.path.pardir, os.path.pardir) + root_path = os.path.realpath(__file__.parent / os.path.pardir, os.path.pardir) # read content of screenshots_bzt.txt info = u.read_text(root_path / 'code' / 'synchronization' / 'screenshots_bzt.txt') diff --git a/code/utils/osg_ui.py b/code/utils/osg_ui.py index fd680e8e..3543a48e 100644 --- a/code/utils/osg_ui.py +++ b/code/utils/osg_ui.py @@ -3,7 +3,7 @@ """ import sys -from PyQt5 import QtCore, QtGui, QtWidgets +from PySide6 import QtCore, QtGui, QtWidgets def exception_hook(type, value, traceback): @@ -20,7 +20,7 @@ def run_simple_button_app(title, actions): :param actions: :return: """ - # fix PyQt5 eating exceptions (see http://stackoverflow.com/q/14493081/1536976) + # fix PySide6 eating exceptions (see http://stackoverflow.com/q/14493081/1536976) sys.excepthook = exception_hook # create app diff --git a/code/utils/utils.py b/code/utils/utils.py index 13e20461..039f20e1 100644 --- a/code/utils/utils.py +++ b/code/utils/utils.py @@ -98,9 +98,9 @@ def detect_archive_type(name): def folder_size(path): size = 0 - for dirpath, dirnames, filenames in os.walk(path): + for dirpath, dirnames, filenames in path.walk(): for file in filenames: - size += os.path.getsize(dirpath / file) + size += (dirpath / file).stat().st_size return size @@ -138,7 +138,7 @@ def determine_latest_last_modified_date(folder): "last modified" date of all these files. """ latest_last_modified = 0 - for dirpath, dirnames, filenames in os.walk(folder): + for dirpath, dirnames, filenames in folder.walk(): for filename in filenames: filepath = dirpath / filename lastmodified = os.path.getmtime(filepath) @@ -173,13 +173,17 @@ def copy_tree(source, destination): # this gave an FileNotFoundError: [Errno 2] No such file or directory: '' on Windows # distutils.dir_util.copy_tree(archive_path, git_path) destination.mkdir(parents=True, exist_ok=True) - for dirpath, dirnames, filenames in os.walk(source): # TODO replace os.walk with path.walk (Python 3.12) - # first create all the directory on destination - for directory in (destination / os.path.relpath(os.path.join(dirpath, x, source)) for x in dirnames): + + for dirpath, dirnames, filenames in source.walk(): + # first create all the directories on destination + destination_path = destination / dirpath.relative_to(source) + for directory in (destination_path / dirname for dirname in dirnames): directory.mkdir(parents=True, exist_ok=True) + # second copy all the files - for source_file in (pathlib.Path(dirpath) / x for x in filenames): - destination_file = destination / os.path.relpath(source_file, source) + for filename in filenames: + source_file = dirpath / filename + destination_file = destination_path / filename shutil.copyfile(source_file, destination_file)