updated script for reorganizing folders to handle the weird nesting that FCCS does

This commit is contained in:
2026-07-06 16:12:55 -05:00
parent 1ae9ba27a6
commit a664a00f4d
3 changed files with 74 additions and 29 deletions

View File

@@ -71,32 +71,66 @@ def build_folder_patterns(templates):
Non-recurring folders (no YYYY) are matched literally.
A built-in pattern for 'UltraTax CS MM-DD-YYYY' is always included.
Returns a list of (compiled_regex, template_name) tuples, sorted
longest-first to prevent partial matches.
Returns a list of (compiled_regex, template_name, folder_type) tuples,
sorted longest-first to prevent partial matches.
folder_type is one of:
"yyyy" — recurring folder with year prefix (captured in group 1)
"ultratax" — UltraTax CS folder with date suffix (captured in group 1)
"static" — non-recurring folder, no decomposition needed
"""
patterns = []
# Built-in: UltraTax CS folders (auto-generated by UltraTax integration)
patterns.append((
re.compile(r"UltraTax CS \d{2}-\d{2}-\d{4}$"),
re.compile(r"UltraTax CS (\d{2}-\d{2}-\d{4})$"),
"UltraTax CS",
"ultratax",
))
for tmpl in templates:
if "YYYY" in tmpl:
# Replace YYYY with 4-digit year pattern, escape the rest
# Replace YYYY with captured 4-digit year pattern, escape the rest
parts = tmpl.split("YYYY")
regex_str = re.escape(parts[0]) + r"\d{4}" + re.escape(parts[1])
regex_str = re.escape(parts[0]) + r"(\d{4})" + re.escape(parts[1])
patterns.append((re.compile(regex_str + "$"), tmpl, "yyyy"))
else:
# Non-recurring folder — exact match
regex_str = re.escape(tmpl)
patterns.append((re.compile(regex_str + "$"), tmpl))
patterns.append((re.compile(regex_str + "$"), tmpl, "static"))
# Sort by regex pattern length (longest first) to avoid partial matches
patterns.sort(key=lambda p: len(p[0].pattern), reverse=True)
return patterns
def decompose_folder_path(match, folder_type, template_name):
"""
Decompose a matched folder name into nested path components that
recreate the FCCS UI folder structure.
Returns a tuple of path parts to be joined with os.path.join().
Examples:
yyyy: "YYYY Tax Documents" matched "2025 Tax Documents"
→ ("Tax Documents", "2025")
ultratax: "UltraTax CS 12-31-2008"
→ ("UltraTax CS", "12-31-2008")
static: "Permanent File"
→ ("Permanent File",)
"""
if folder_type == "yyyy":
year = match.group(1)
# Strip "YYYY " from template to get the base folder name
base_name = template_name.replace("YYYY", "").strip()
return (base_name, year)
elif folder_type == "ultratax":
date = match.group(1)
return ("UltraTax CS", date)
else:
return (template_name,)
def load_lines(path):
"""Read non-blank, non-comment lines from a file."""
if not os.path.exists(path):