Skip to content

Commit

Permalink
fix os to pathlib remaining errors and old style format strings to f-…
Browse files Browse the repository at this point in the history
…strings (with flynt)
  • Loading branch information
Trilarion committed Mar 3, 2024
1 parent 2af162f commit acf3352
Show file tree
Hide file tree
Showing 28 changed files with 361 additions and 361 deletions.
6 changes: 3 additions & 3 deletions code/archive_detect_submodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
# loop over all git archives
submodules = []
for repo in archives['git']:
print('process {}'.format(repo))
print(f'process {repo}')
git_folder = a.git_folder_name(repo)
folder = archive_folder / 'git' / git_folder
if not folder.is_dir():
print('Warning: folder {} does not exist'.format(git_folder))
print(f'Warning: folder {git_folder} does not exist')
continue
os.chdir(folder)
try:
Expand All @@ -64,5 +64,5 @@
submodules = [x for x in submodules if not any([x.startswith(y) for y in ('.', 'git@')])]

# store them
print('found {} submodules'.format(len(submodules)))
print(f'found {len(submodules)} submodules')
u.write_text(code_folder / 'archives.git-submodules.json', json.dumps(submodules, indent=1))
12 changes: 6 additions & 6 deletions code/archive_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def hg_update(folder):
def run_update(type, urls, type_folder=None):
if type_folder is None:
type_folder = type
print('update {} {} archives'.format(len(urls), type))
print(f'update {len(urls)} {type} archives')
base_folder = archive_folder / type_folder
if not base_folder.exists():
base_folder.mkdir()
Expand All @@ -86,7 +86,7 @@ def run_update(type, urls, type_folder=None):
# find those folders not used anymore
existing_folders = [x for x in base_folder.iterdir() if (base_folder / x).is_dir()]
unused_folders = [x for x in existing_folders if x not in folders]
print('{} unused archives, move to unused folder'.format(len(unused_folders)))
print(f'{len(unused_folders)} unused archives, move to unused folder')
for folder in unused_folders:
origin = base_folder / folder
destination = unused_base_folder / folder
Expand All @@ -95,22 +95,22 @@ def run_update(type, urls, type_folder=None):

# new folder, need to clone
new_folders = [x for x in folders if x not in existing_folders]
print('{} new archives, will clone'.format(len(new_folders)))
print(f'{len(new_folders)} new archives, will clone')

# add root to folders
folders = [base_folder / x for x in folders]
os.chdir(base_folder)
for folder, url in zip(folders, urls):
if not folder.is_dir():
print('clone {} into {}'.format(url, folder.relative_to(base_folder)))
print(f'clone {url} into {folder.relative_to(base_folder)}')
try:
clone[type](url, folder)
except RuntimeError as e:
print('error occurred while cloning, will skip')

# at the end update them all
for folder in folders:
print('update {}'.format(os.path.basename(folder)))
print(f'update {os.path.basename(folder)}')
if not folder.is_dir():
print('folder not existing, wanted to update, will skip')
continue
Expand All @@ -122,7 +122,7 @@ def run_update(type, urls, type_folder=None):


def run_info(type, urls):
print('collect info on {}'.format(type))
print(f'collect info on {type}')

# get derived folder names
folders = [type / folder_name[type](url) for url in urls]
Expand Down
20 changes: 10 additions & 10 deletions code/custom-conversions/aatraders_source_release_to_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def special_aatrade_package_extraction(source):
files = source.iterdir()
if any([x.startswith('aatrade_package') for x in files]):
# we got the special case
print('aatrade package extraction of {}'.format(source))
print(f'aatrade package extraction of {source}')

# first delete all, that do not begin with the package name
for file in files:
Expand All @@ -34,7 +34,7 @@ def special_aatrade_package_extraction(source):

# base path is the directory containing this file
base_path = pathlib.Path(__file__)
print('base path={}'.format(base_path))
print(f'base path={base_path}')

# recreate archive path
archive_path = base_path / 'downloads'
Expand All @@ -44,7 +44,7 @@ def special_aatrade_package_extraction(source):
# load source releases urls
with open(base_path / 'aatraders.json', 'r') as f:
urls = json.load(f)
print('will process {} urls'.format(len(urls)))
print(f'will process {len(urls)} urls')
if len(urls) != len(set(urls)):
raise RuntimeError("urls list contains duplicates")

Expand All @@ -68,14 +68,14 @@ def special_aatrade_package_extraction(source):
if destination.exists():
continue
# download
print(' download {}'.format(os.path.basename(destination)))
print(f' download {os.path.basename(destination)}')
download_url(url, destination)

# extract them
print('extract downloaded archives')
extracted_archives = [x + '-extracted' for x in archives]
for archive, extracted_archive in zip(archives, extracted_archives):
print(' extract {}'.format(os.path.basename(archive)))
print(f' extract {os.path.basename(archive)}')
# only if not yet existing
if extracted_archive.exists():
continue
Expand Down Expand Up @@ -109,7 +109,7 @@ def special_aatrade_package_extraction(source):

print('proposed order')
for url, _, version, _, date, size in db:
print(' date={} version={} size={}'.format(date, version, size))
print(f' date={date} version={version} size={size}')

# git init
git_path = base_path / 'aatrade'
Expand All @@ -125,7 +125,7 @@ def special_aatrade_package_extraction(source):
print('process revisions')
git_author = 'akapanamajack, tarnus <[email protected]>'
for url, archive_path, version, _, date, _ in db:
print(' process version={}'.format(version))
print(f' process version={version}')

# clear git path without deleting .git
print(' clear git')
Expand All @@ -151,6 +151,6 @@ def special_aatrade_package_extraction(source):
# perform the commit
print('git commit')
os.chdir(git_path)
message = 'version {} ({}) on {}'.format(version, url, date)
print(' message "{}"'.format(message))
subprocess_run(['git', 'commit', '--message={}'.format(message), '--author={}'.format(git_author), '--date={}'.format(date)])
message = f'version {version} ({url}) on {date}'
print(f' message "{message}"')
subprocess_run(['git', 'commit', f'--message={message}', f'--author={git_author}', f'--date={date}'])
20 changes: 10 additions & 10 deletions code/custom-conversions/dfend_reloaded_source_releases_to_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def subprocess_run(cmd):
"""
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode:
print("error {} in call {}".format(result.returncode, cmd))
print(f"error {result.returncode} in call {cmd}")
print(result.stderr.decode('ascii'))
sys.exit(-1)
else:
print(' output: {}'.format(result.stdout.decode('ascii')))
print(f" output: {result.stdout.decode('ascii')}")

def single_release(zip):
"""
Expand All @@ -28,8 +28,8 @@ def single_release(zip):
# get version
matches = version_regex.findall(zip)
version = matches[0]
print(' version {}'.format(version))
ftp_link = 'https://sourceforge.net/projects/dfendreloaded/files/D-Fend%20Reloaded/D-Fend%20Reloaded%20{}/'.format(version)
print(f' version {version}')
ftp_link = f'https://sourceforge.net/projects/dfendreloaded/files/D-Fend%20Reloaded/D-Fend%20Reloaded%20{version}/'

# clear git path without deleting '.git'
for item in git_path.iterdir():
Expand Down Expand Up @@ -61,7 +61,7 @@ def single_release(zip):
# print('{}, {}'.format(filepath, datetime.datetime.fromtimestamp(latest_last_modified).strftime('%Y-%m-%d')))

original_date = datetime.datetime.fromtimestamp(latest_last_modified).strftime('%Y-%m-%d')
print(' last modified: {}'.format(original_date))
print(f' last modified: {original_date}')

# update the git index (add unstaged, remove deleted, ...)
print('git add')
Expand All @@ -71,9 +71,9 @@ def single_release(zip):
# perform the commit
print('git commit')
os.chdir(git_path)
message = 'version {} from {} ({})'.format(version, original_date, ftp_link)
print(' message "{}"'.format(message))
subprocess_run(['git', 'commit', '--message={}'.format(message), '--author={}'.format(author), '--date={}'.format(original_date)])
message = f'version {version} from {original_date} ({ftp_link})'
print(f' message "{message}"')
subprocess_run(['git', 'commit', f'--message={message}', f'--author={author}', f'--date={original_date}'])


if __name__ == "__main__":
Expand All @@ -94,10 +94,10 @@ def single_release(zip):
# get all files in the source releases path and sort them
zips = source_releases_path.iterdir()
zips = [file for file in zips if os.path.isfile(source_releases_path / file)]
print('found {} source releases'.format(len(zips)))
print(f'found {len(zips)} source releases')
zips.sort()

# iterate over them and do revisions
for counter, zip in enumerate(zips):
print('{}/{}'.format(counter, len(zips)))
print(f'{counter}/{len(zips)}')
single_release(zip)
16 changes: 8 additions & 8 deletions code/custom-conversions/dungeon_crawl_source_releases_to_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def subprocess_run(cmd):
"""
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode:
print("error {} in call {}".format(result.returncode, cmd))
print(f"error {result.returncode} in call {cmd}")
print(result.stderr.decode('ascii'))
sys.exit(-1)
else:
print(' output: {}'.format(result.stdout.decode('ascii')))
print(f" output: {result.stdout.decode('ascii')}")

def single_revision():
"""
Expand All @@ -55,7 +55,7 @@ def single_revision():
shutil.copyfileobj(response, tmp_file)

# unpack source files and delete archive
print('extract {} to temp'.format(os.path.basename(ftp_link)))
print(f'extract {os.path.basename(ftp_link)} to temp')
extract_sources(tmp_file.name, os.path.splitext(ftp_link)[1], temp_path)
os.remove(tmp_file.name)

Expand All @@ -65,7 +65,7 @@ def single_revision():
while len(names) == 1:
nonempty_temp_path = nonempty_temp_path / names[0]
names = nonempty_temp_path.iterdir()
print(' working in "{}" relative to temp'.format(os.path.relpath(nonempty_temp_path, temp_path)))
print(f' working in "{os.path.relpath(nonempty_temp_path, temp_path)}" relative to temp')

# if no original date is indicated, get it from the files (latest of last modified)
global original_date
Expand All @@ -78,7 +78,7 @@ def single_revision():
if lastmodified > latest_last_modified:
latest_last_modified = lastmodified
original_date = datetime.datetime.fromtimestamp(latest_last_modified).strftime('%Y-%m-%d')
print(' extracted original date from files: {}'.format(original_date))
print(f' extracted original date from files: {original_date}')

# clear git path without deleting '.git'
print('clear git')
Expand All @@ -104,10 +104,10 @@ def single_revision():
# perform the commit
print('git commit')
os.chdir(git_path)
message = 'version {} ({}) on {}'.format(version, ftp_link, original_date)
print(' message "{}"'.format(message))
message = f'version {version} ({ftp_link}) on {original_date}'
print(f' message "{message}"')
# subprocess_run(['git', 'commit', '--message={}'.format(message), '--author={}'.format(author), '--date={}'.format(original_date), '--dry-run'])
subprocess_run(['git', 'commit', '--message={}'.format(message), '--author={}'.format(author), '--date={}'.format(original_date)])
subprocess_run(['git', 'commit', f'--message={message}', f'--author={author}', f'--date={original_date}'])


if __name__ == "__main__":
Expand Down
40 changes: 20 additions & 20 deletions code/custom-conversions/lechemindeladam_svn_to_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def special_treatment(destination, revision):
folder = destination / 'EmpireOfSteam'
if folder.is_dir():
# move to empire path
empire = empire_path / 'r{:04d}'.format(revision)
empire = empire_path / f'r{revision:04d}'
shutil.move(folder, empire)

# holy editor cleanup
Expand Down Expand Up @@ -232,10 +232,10 @@ def checkout(revision_start, revision_end=None):
print('not enough free disc space, will exit')
sys.exit(-1)

print('checking out revision {}'.format(revision))
print(f'checking out revision {revision}')

# create destination directory
destination = svn_checkout_path / 'r{:04d}'.format(revision)
destination = svn_checkout_path / f'r{revision:04d}'
if destination.exists():
shutil.rmtree(destination)

Expand All @@ -244,14 +244,14 @@ def checkout(revision_start, revision_end=None):
# sometimes checkout fails for reasons like "svn: E000024: Can't open file '/svn/p/lechemindeladam/code/db/revs/1865': Too many open files", we try again and again in these cases
while True:
try:
subprocess_run(['svn', 'export', '-r{}'.format(revision), svn_url, destination])
subprocess_run(['svn', 'export', f'-r{revision}', svn_url, destination])
break
except:
print('problem with export, will try again')
if destination.is_dir():
shutil.rmtree(destination)

print('checkout took {:.1f}s'.format(time.time() - start_time))
print(f'checkout took {time.time() - start_time:.1f}s')


def fix_revision(revision_start, revision_end=None):
Expand All @@ -266,12 +266,12 @@ def fix_revision(revision_start, revision_end=None):
sizes = {}

for revision in range(revision_start, revision_end + 1):
print('fixing revision {}'.format(revision))
print(f'fixing revision {revision}')

# destination directory
destination = svn_checkout_path / 'r{:04d}'.format(revision)
destination = svn_checkout_path / f'r{revision:04d}'
if not destination.exists():
raise RuntimeError('cannot fix revision {}, directory does not exist'.format(revision))
raise RuntimeError(f'cannot fix revision {revision}, directory does not exist')

# special treatment
special_treatment(destination, revision)
Expand Down Expand Up @@ -326,12 +326,12 @@ def read_logs():
os.chdir(svn_checkout_path)
start_time = time.time()
log = subprocess_run(['svn', 'log', svn_url], display=False)
print('read log took {:.1f}s'.format(time.time() - start_time))
print(f'read log took {time.time() - start_time:.1f}s')
# process log
log = log.split('\r\n------------------------------------------------------------------------\r\n')
# not the last one
log = log[:-2]
print('{} log entries'.format(len(log)))
print(f'{len(log)} log entries')

# process log entries
log = [x.split('\r\n') for x in log]
Expand Down Expand Up @@ -363,12 +363,12 @@ def gitify(revision_start, revision_end):
assert revision_end >= revision_start

for revision in range(revision_start, revision_end + 1):
print('adding revision {} to git'.format(revision))
print(f'adding revision {revision} to git')

# svn folder
svn_folder = svn_checkout_path / 'r{:04d}'.format(revision)
svn_folder = svn_checkout_path / f'r{revision:04d}'
if not svn_folder.exists():
raise RuntimeError('cannot add revision {}, directory does not exist'.format(revision))
raise RuntimeError(f'cannot add revision {revision}, directory does not exist')

# clear git path
print('git clear path')
Expand All @@ -394,19 +394,19 @@ def gitify(revision_start, revision_end):
# check if there is something to commit
status = subprocess_run(['git', 'status', '--porcelain'])
if not status:
print(' nothing to commit for revision {}, will skip'.format(revision))
print(f' nothing to commit for revision {revision}, will skip')
continue

# perform the commit
print('git commit')
log = logs[revision] # revision, author, date, message
message = log[3] + '\r\nsvn-revision: {}'.format(revision)
print(' message "{}"'.format(message))
message = log[3] + f'\r\nsvn-revision: {revision}'
print(f' message "{message}"')
author = authors[log[1]]
author = '{} <{}>'.format(*author)
cmd = ['git', 'commit', '--allow-empty-message', '--message={}'.format(message), '--author={}'.format(author),
'--date={}'.format(log[2])]
print(' cmd: {}'.format(' '.join(cmd)))
cmd = ['git', 'commit', '--allow-empty-message', f'--message={message}', f'--author={author}',
f'--date={log[2]}']
print(f" cmd: {' '.join(cmd)}")
subprocess_run(cmd)


Expand All @@ -418,7 +418,7 @@ def gitify(revision_start, revision_end):

# base path is the directory containing this file
base_path = pathlib.Path(__file__) / 'conversion'
print('base path={}'.format(base_path))
print(f'base path={base_path}')

# derived paths
svn_checkout_path = base_path / 'svn'
Expand Down
Loading

0 comments on commit acf3352

Please sign in to comment.