mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-14 19:47:12 +00:00
more robust tripid labelling
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
import hashlib
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
import resource
|
||||
import string
|
||||
import subprocess
|
||||
import os
|
||||
from decimal import getcontext
|
||||
from pathlib import Path
|
||||
|
||||
getcontext().prec = 2 # use 2 significant figures for decimal calculations
|
||||
|
||||
|
||||
import settings
|
||||
|
||||
"""This file declares TROG a globally visible object for caches.
|
||||
@@ -30,6 +31,8 @@ thread.
|
||||
"""
|
||||
|
||||
TROG = {"pagecache": {"expedition": {}}, "caves": {"gcavelookup": {}, "gcavecount": {}}}
|
||||
alphabet = []
|
||||
sha = hashlib.new('sha256')
|
||||
|
||||
# This is module-level executable. This is a Bad Thing. Especially when it touches the file system.
|
||||
try:
|
||||
@@ -50,7 +53,27 @@ def chaosmonkey(n):
|
||||
return False
|
||||
# print("CHAOS strikes !", file=sys.stderr)
|
||||
return True
|
||||
|
||||
|
||||
def unique_slug(text, n):
|
||||
"""This gives an almost-unique id based on the text,
|
||||
2 hex digits would seem adequate, but we might get a collision.
|
||||
Not used anywhere.
|
||||
"""
|
||||
sha.update(text.encode('utf-8'))
|
||||
return sha.hexdigest()[0:n]
|
||||
|
||||
def alphabet_suffix(n):
|
||||
"""This is called repeatedly during initial parsing import, hence the cached list
|
||||
"""
|
||||
global alphabet
|
||||
if not alphabet:
|
||||
alphabet = list(string.ascii_lowercase)
|
||||
|
||||
if n < len(alphabet):
|
||||
suffix = alphabet[n]
|
||||
else:
|
||||
suffix = "_X_" + random.choice(string.ascii_lowercase) + random.choice(string.ascii_lowercase)
|
||||
return suffix
|
||||
|
||||
def only_commit(fname, message):
|
||||
"""Only used to commit a survex file edited and saved in view/survex.py"""
|
||||
|
||||
Reference in New Issue
Block a user