From 65032a5b58eff0ae303ce46e4878a570e62aceef Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sat, 9 Mar 2024 11:33:25 +0000 Subject: [PATCH] fileutil: accept Path instances as arguments --- mmgen/autosign.py | 2 +- mmgen/fileutil.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mmgen/autosign.py b/mmgen/autosign.py index 9b0a848d..fd3038f5 100755 --- a/mmgen/autosign.py +++ b/mmgen/autosign.py @@ -558,7 +558,7 @@ class Autosign: if self.keyfile.exists(): from .fileutil import shred_file ymsg(f'Shredding wallet encryption key ‘{self.keyfile}’') - shred_file(str(self.keyfile), verbose=self.cfg.verbose) + shred_file(self.keyfile, verbose=self.cfg.verbose) else: gmsg('No wallet encryption key on removable device') diff --git a/mmgen/fileutil.py b/mmgen/fileutil.py index f1b7ac9a..57926d0e 100755 --- a/mmgen/fileutil.py +++ b/mmgen/fileutil.py @@ -20,6 +20,8 @@ fileutil: Routines that read, write, execute or stat files """ +# 09 Mar 2024: make all utils accept Path instances as arguments + import sys,os from .color import set_vt100 @@ -43,7 +45,7 @@ def check_or_create_dir(path): run([ ('rm' if sys.platform == 'win32' else '/bin/rm'), '-rf', - path ]) + str(path)]) set_vt100() try: os.makedirs(path,0o700) @@ -64,7 +66,7 @@ def shred_file(fn,verbose=False): run( ['shred','--force','--iterations=30','--zero','--remove=wipesync'] + (['--verbose'] if verbose else []) - + [fn], + + [str(fn)], check=True ) set_vt100() @@ -135,7 +137,7 @@ def get_seed_file(cfg,nargs,wallets=None,invoked_as=None): if wallets or wf: check_infile(wallets[0] if wallets else wf) - return wallets[0] if wallets else (wf,None)[wd_from_opt] + return str(wallets[0]) if wallets else (wf,None)[wd_from_opt] # could be a Path instance def _open_or_die(filename,mode,silent=False): try: @@ -166,6 +168,8 @@ def write_data_to_file( check_data = False, cmp_data = None): + outfile = str(outfile) # could be a Path instance + if quiet: ask_tty = ask_overwrite = False @@ -221,7 +225,7 @@ def write_data_to_file( def do_file(outfile,ask_write_prompt): if (outdir or (cfg.outdir and not ignore_opt_outdir)) and not os.path.isabs(outfile): - outfile = make_full_path(outdir or cfg.outdir, outfile) + outfile = make_full_path(str(outdir or cfg.outdir), outfile) # outdir could be Path instance if ask_write: if not ask_write_prompt: