colosseum.utils.acme.path
1import os 2import os.path 3import uuid 4from typing import Optional, Tuple 5 6# Pre-compute a unique identifier which is consistent within a single process. 7_ACME_ID = uuid.uuid1() 8 9 10def process_path( 11 path: str, 12 *subpaths: str, 13 ttl_seconds: Optional[int] = None, 14 backups: Optional[bool] = None, 15 add_uid: bool = True 16) -> str: 17 """Process the path string. 18 19 This will process the path string by running `os.path.expanduser` to replace 20 any initial "~". It will also append a unique string on the end of the path 21 and create the directories leading to this path if necessary. 22 23 Args: 24 path: string defining the path to process and create. 25 *subpaths: potential subpaths to include after uniqification. 26 ttl_seconds: ignored. 27 backups: ignored. 28 add_uid: Whether to add a unique directory identifier between `path` and 29 `subpaths`. If FLAGS.acme_id is set, will use that as the identifier. 30 31 Returns: 32 the processed, expanded path string. 33 """ 34 del backups, ttl_seconds 35 36 path = os.path.expanduser(path) 37 if add_uid: 38 path = os.path.join(path, *get_unique_id()) 39 path = os.path.join(path, *subpaths) 40 os.makedirs(path, exist_ok=True) 41 return path 42 43 44def get_unique_id() -> Tuple[str, ...]: 45 """Makes a unique identifier for this process; override with FLAGS.acme_id.""" 46 # By default we'll use the global id. 47 identifier = str(_ACME_ID) 48 49 # Return as a tuple (for future proofing). 50 return (identifier,)
def
process_path( path: str, *subpaths: str, ttl_seconds: Optional[int] = None, backups: Optional[bool] = None, add_uid: bool = True) -> str:
11def process_path( 12 path: str, 13 *subpaths: str, 14 ttl_seconds: Optional[int] = None, 15 backups: Optional[bool] = None, 16 add_uid: bool = True 17) -> str: 18 """Process the path string. 19 20 This will process the path string by running `os.path.expanduser` to replace 21 any initial "~". It will also append a unique string on the end of the path 22 and create the directories leading to this path if necessary. 23 24 Args: 25 path: string defining the path to process and create. 26 *subpaths: potential subpaths to include after uniqification. 27 ttl_seconds: ignored. 28 backups: ignored. 29 add_uid: Whether to add a unique directory identifier between `path` and 30 `subpaths`. If FLAGS.acme_id is set, will use that as the identifier. 31 32 Returns: 33 the processed, expanded path string. 34 """ 35 del backups, ttl_seconds 36 37 path = os.path.expanduser(path) 38 if add_uid: 39 path = os.path.join(path, *get_unique_id()) 40 path = os.path.join(path, *subpaths) 41 os.makedirs(path, exist_ok=True) 42 return path
Process the path string.
This will process the path string by running os.path.expanduser
to replace
any initial "~". It will also append a unique string on the end of the path
and create the directories leading to this path if necessary.
Args:
path: string defining the path to process and create.
*subpaths: potential subpaths to include after uniqification.
ttl_seconds: ignored.
backups: ignored.
add_uid: Whether to add a unique directory identifier between path
and
subpaths
. If FLAGS.acme_id is set, will use that as the identifier.
Returns: the processed, expanded path string.
def
get_unique_id() -> Tuple[str, ...]:
45def get_unique_id() -> Tuple[str, ...]: 46 """Makes a unique identifier for this process; override with FLAGS.acme_id.""" 47 # By default we'll use the global id. 48 identifier = str(_ACME_ID) 49 50 # Return as a tuple (for future proofing). 51 return (identifier,)
Makes a unique identifier for this process; override with FLAGS.acme_id.