Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
[general] Use f strings
Browse files Browse the repository at this point in the history
  • Loading branch information
IceflowRE committed Nov 9, 2018
1 parent 315ad48 commit b16a299
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
4 changes: 2 additions & 2 deletions mp3monitoring/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def _init(ignore_save=False):
with dynamic_data.SAVE_FILE.open('w', encoding='utf-8') as writer:
json.dump(json_dict, writer, indent=4)
except PermissionError:
print('Cant write to config folder ({home}). Make sure you have write permissions.'.format(home=str(home)))
print(f"Cant write to config folder ({home}). Make sure you have write permissions.")

# load save file
# TODO: version not used
Expand All @@ -48,7 +48,7 @@ def start():
Entry point into program.
"""
if sys.version_info[0] < 3 or sys.version_info[1] < 6:
sys.exit('Only Python 3.6 or greater is supported. You are using: {version}'.format(version=sys.version))
sys.exit("Only Python 3.6 or greater is supported. You are using: " + sys.version)

parser = ArgumentParser(prog='mp3-monitoring',
description='Monitors a folder and copies mp3s to another folder. Quit with Ctrl+C.')
Expand Down
5 changes: 2 additions & 3 deletions mp3monitoring/gui/windows/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def __init__(self, parent):
# set descriptions
self.programName.setText(static_data.LONG_NAME)
self.version.setText(static_data.VERSION)
self.authorValue.setText(
"<a href=\"{link}\">{name}</a>".format(link=static_data.AUTHOR_GITHUB, name=static_data.AUTHOR))
self.authorValue.setText(f"<a href=\"{static_data.AUTHOR_GITHUB}\">{static_data.AUTHOR}</a>")
self.licenseValue.setText("<a href=\"https://www.gnu.org/licenses/gpl-3.0-standalone.html\">GPLv3</a>")
self.websiteValue.setText("<a href=\"{url}\">Github</a>".format(url=static_data.PROJECT_URL))
self.websiteValue.setText(f"<a href=\"{static_data.PROJECT_URL}\">Github</a>")

# set logo
self.logo.setStyleSheet('background: transparent')
Expand Down
24 changes: 9 additions & 15 deletions mp3monitoring/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,7 @@ def from_json_dict(cls, json_dict):
return cls(source_dir, target_dir, startup, pause, last_mod_time)

def __str__(self):
return "{active} | {source} | {target} | {pause}s | {status} | {startup} | {time}".format(
active=self.thread.isAlive(),
source=str(self.source_dir),
target=str(self.target_dir),
pause=str(self.pause),
status=self.status,
startup=self.startup,
time=self.last_mod_time)
return f"{self.thread.isAlive()} | {self.source_dir} | {self.target_dir} | {self.pause}s | {self.status} | {self.startup} | {self.last_mod_time}"

def start(self):
"""
Expand Down Expand Up @@ -107,21 +100,20 @@ def check_directories(self):
Check source and initialize target directory.
"""
if not self.source_dir.exists():
self.status = 'Source ({source_dir}) does not exist.'.format(source_dir=str(self.source_dir))
self.status = f"Source ({self.source_dir}) does not exist."
return False
elif not self.source_dir.is_dir():
self.status = 'Source ({source_dir}) is not a directory.'.format(source_dir=str(self.source_dir))
self.status = f"Source ({self.source_dir}) is not a directory."
return False

if not self.target_dir.exists():
try:
Path.mkdir(self.target_dir, parents=True)
except PermissionError:
self.status = 'Cant create target directory ({target_dir}). Do you have write permissions?'.format(
target_dir=str(self.target_dir))
self.status = f"Cant create target directory ({self.target_dir}). Do you have write permissions?"
return False
elif not self.target_dir.is_dir():
self.status = 'Target ({target_dir}) is not a directory.'.format(target_dir=str(self.target_dir))
self.status = f"Target ({self.target_dir}) is not a directory."
return False
return True

Expand Down Expand Up @@ -184,7 +176,8 @@ def get_all_mp3(files):
:param files: file list
:return: set(file)
"""
pbar = tqdm(files, desc="Checking for mp3", unit="file", leave=True, mininterval=0.2, ncols=100, disable=dynamic_data.DISABLE_TQDM)
pbar = tqdm(files, desc="Checking for mp3", unit="file", leave=True, mininterval=0.2, ncols=100,
disable=dynamic_data.DISABLE_TQDM)
mp3_files = {file for file in pbar if is_mp3(file)}
pbar.close()
return mp3_files
Expand All @@ -198,7 +191,8 @@ def copy_files(files, target_dir: Path):
:param pbar:
:return:
"""
pbar = tqdm(files, desc="Copying new mp3", unit="mp3", leave=True, mininterval=0.2, ncols=100, disable=dynamic_data.DISABLE_TQDM)
pbar = tqdm(files, desc="Copying new mp3", unit="mp3", leave=True, mininterval=0.2, ncols=100,
disable=dynamic_data.DISABLE_TQDM)
for file in pbar:
try:
new_file = target_dir.joinpath(file.name)
Expand Down
4 changes: 2 additions & 2 deletions mp3monitoring/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def load_settings(save_dict):
if value.lower() in settings:
setattr(settings_data, value, settings[value.lower()])
else:
print('{value} not found in settings.'.format(value=value))
print(f"{value} not found in settings.")
else:
print('No settings found in save file.')

Expand All @@ -34,7 +34,7 @@ def get_settings_dict():
try:
settings[value.lower()] = getattr(settings_data, value)
except AttributeError:
print('Internal fail, for settings variable. ({variable}'.format(variable=value))
print(f"Internal fail, for settings variable. ({value}")
return settings


Expand Down
5 changes: 0 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ start-dir = tests
code-directories = mp3monitoring
test-file-pattern = *_test.py

[output-buffer]
always-on = True
stderr = False
stdout = True

[coverage]
always-on = True
coverage = mp3monitoring
Expand Down

0 comments on commit b16a299

Please sign in to comment.