15def write_file(overwrite,overwrite_is_default,full_qualified_filename):
17 overwrite is of type Overwrite and is what the user passes in
18 overwrite_is_default is a boolean
20 if overwrite==Overwrite.Always:
22 elif overwrite==Overwrite.Never
and os.path.exists(full_qualified_filename):
24 elif overwrite==Overwrite.Never
and not os.path.exists(full_qualified_filename):
26 elif overwrite==Overwrite.Default:
27 if not overwrite_is_default
and os.path.exists(full_qualified_filename):
32 print(
"Error: undefined overwrite strategy")
45def shortened_class_name(class_name, max_length=MAX_CLASS_NAME_LENGTH):
48 Class name of a generated observer or action set which is short enough
51 Names up to max_length characters are returned unchanged. Longer names
52 are cut off and get a consecutive number appended, e.g. ..._1, ..._2.
53 The cut-off names carry no meaning anymore, but every call with the same
54 long name and the same max_length yields the same short name, so the
55 generated files can refer to each other.
57 @param class_name: str
60 @param max_length: int
61 Longest admissible class name.
64 if len(class_name) <= max_length:
66 key = (class_name, max_length)
67 if key
not in _shortened_class_names:
68 suffix =
"_" + str(len(_shortened_class_names) + 1)
69 _shortened_class_names[key] = class_name[: max_length - len(suffix)] + suffix
70 return _shortened_class_names[key]