56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Build the Hermes profile census table.
|
|
|
|
Artifact: profiles-census.csv
|
|
Columns:
|
|
profile - Hermes profile directory name under /root/.hermes/profiles
|
|
archives - number of *.txt activity transcripts in that profile dir
|
|
is_ledger - 1 if the profile is named "ledger", else 0
|
|
|
|
The table is generated from the real filesystem (not fabricated), so it is
|
|
fully reproducible by re-running this script.
|
|
"""
|
|
import csv
|
|
import os
|
|
|
|
PROFILES_DIR = "/root/.hermes/profiles"
|
|
OUT = "/root/.hermes/wizard-outputs/ledger/profiles-census.csv"
|
|
|
|
|
|
def archive_count(profile_dir):
|
|
count = 0
|
|
for root, dirs, files in os.walk(profile_dir):
|
|
for f in files:
|
|
if f.endswith(".txt"):
|
|
count += 1
|
|
return count
|
|
|
|
|
|
def build_rows():
|
|
rows = []
|
|
for name in sorted(os.listdir(PROFILES_DIR)):
|
|
pdir = os.path.join(PROFILES_DIR, name)
|
|
if not os.path.isdir(pdir):
|
|
continue
|
|
rows.append(
|
|
{
|
|
"profile": name,
|
|
"archives": archive_count(pdir),
|
|
"is_ledger": 1 if name == "ledger" else 0,
|
|
}
|
|
)
|
|
return rows
|
|
|
|
|
|
def main():
|
|
os.makedirs(os.path.dirname(OUT), exist_ok=True)
|
|
with open(OUT, "w", newline="") as fh:
|
|
writer = csv.DictWriter(fh, fieldnames=["profile", "archives", "is_ledger"])
|
|
writer.writeheader()
|
|
writer.writerows(build_rows())
|
|
print("wrote %s (%d profiles)" % (OUT, len(build_rows())))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|