diff --git a/freqtrade/commands/strategy_utils_commands.py b/freqtrade/commands/strategy_utils_commands.py index 0124b73b6..aca368742 100644 --- a/freqtrade/commands/strategy_utils_commands.py +++ b/freqtrade/commands/strategy_utils_commands.py @@ -1,6 +1,6 @@ import logging -import os import time +from pathlib import Path from typing import Any, Dict from freqtrade.configuration import setup_utils_configuration @@ -45,11 +45,11 @@ def start_strategy_update(args: Dict[str, Any]) -> None: def start_conversion(strategy_obj, config): # try: - print(f"Conversion of {os.path.basename(strategy_obj['location'])} started.") + print(f"Conversion of {Path(strategy_obj['location']).name} started.") instance_strategy_updater = StrategyUpdater() start = time.perf_counter() instance_strategy_updater.start(config, strategy_obj) elapsed = time.perf_counter() - start - print(f"Conversion of {os.path.basename(strategy_obj['location'])} took {elapsed:.1f} seconds.") + print(f"Conversion of {Path(strategy_obj['location']).name} took {elapsed:.1f} seconds.") # except: # pass diff --git a/freqtrade/strategy/strategyupdater.py b/freqtrade/strategy/strategyupdater.py index db19d4fba..6fe1f326c 100644 --- a/freqtrade/strategy/strategyupdater.py +++ b/freqtrade/strategy/strategyupdater.py @@ -1,4 +1,3 @@ -import os import shutil from pathlib import Path @@ -55,10 +54,10 @@ class StrategyUpdater: target_file = Path.joinpath(strategies_backup_folder, strategy_obj['location_rel']) # read the file - with open(source_file, 'r') as f: + with Path(source_file).open('r') as f: old_code = f.read() if not strategies_backup_folder.is_dir(): - os.makedirs(strategies_backup_folder) + Path(strategies_backup_folder).mkdir(parents=True, exist_ok=True) # backup original # => currently no date after the filename, @@ -69,7 +68,7 @@ class StrategyUpdater: # update the code new_code = self.update_code(old_code) # write the modified code to the destination folder - with open(source_file, 'w') as f: + with Path(source_file).open('w') as f: f.write(new_code) # define the function to update the code