diff options
author | emkael <emkael@tlen.pl> | 2024-01-19 01:32:12 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2024-01-19 01:32:12 +0100 |
commit | c64ba72cce68441a4a236f57ae9c63ddfdf93119 (patch) | |
tree | e059efa13691e099e14eed6c2da55db44e30600b | |
parent | b7c0d0c8515b9563b19aa9bfd4dca8b24a7c6de1 (diff) |
Parsing multiple hashes (leading zeroes) into file prefix
-rw-r--r-- | squaredeal/__init__.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/squaredeal/__init__.py b/squaredeal/__init__.py index feed499..bd10ff5 100644 --- a/squaredeal/__init__.py +++ b/squaredeal/__init__.py @@ -1,4 +1,4 @@ -import base64, hashlib, os, random, shutil, string, subprocess +import base64, hashlib, os, random, re, shutil, string, subprocess def generate_session_key(): @@ -30,8 +30,14 @@ class SquareDealPhase(object): return ':'.join([str(self.sessions), str(self.boards), self.prefix, self.info or '']) def _output_file_name(self, session, reserve=False): - # TODO: that funky multiple hash syntax for leading zeroes - return self.prefix.replace('#', str(session)) + ('reserve' if reserve else '') + prefix = self.prefix + session_search = re.findall(r'#+', prefix) + for session_match in sorted(session_search, reverse=True): + session_str = ('%0'+str(len(session_match))+'d') % (session) + prefix = prefix.replace(session_match, session_str) + if reserve: + prefix += 'reserve' + return prefix def generate(self, session, delayed_info, reserve=False): if not SquareDeal.BIGDEALX_PATH: |