flinventory 2.2.2__tar.gz → 2.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {flinventory-2.2.2 → flinventory-2.2.4}/PKG-INFO +1 -1
  2. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/datacleanup.py +95 -25
  3. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/labelprinter_typst.py +6 -5
  4. {flinventory-2.2.2 → flinventory-2.2.4}/pyproject.toml +1 -1
  5. {flinventory-2.2.2 → flinventory-2.2.4}/LICENSE +0 -0
  6. {flinventory-2.2.2 → flinventory-2.2.4}/README.md +0 -0
  7. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/__init__.py +0 -0
  8. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/__main__.py +0 -0
  9. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/box.py +0 -0
  10. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/constant.py +0 -0
  11. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/defaulted_data.py +0 -0
  12. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/font_location.py +0 -0
  13. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/generate_labels.py +0 -0
  14. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/inventory_io.py +0 -0
  15. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/location.py +0 -0
  16. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/sign.py +0 -0
  17. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/signprinter_latex.py +0 -0
  18. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/thing.py +0 -0
  19. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/thingtemplate_typst/dummyImage.jpg +0 -0
  20. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/thingtemplate_typst/label.typ +0 -0
  21. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/thingtemplate_typst/out/bowdenzugklemmung1.svg +0 -0
  22. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/thingtemplate_typst/out/things.log +0 -0
  23. {flinventory-2.2.2 → flinventory-2.2.4}/flinventory/thingtemplate_typst/thinglist.typ +0 -0
  24. {flinventory-2.2.2 → flinventory-2.2.4}/tests/__init__.py +0 -0
  25. {flinventory-2.2.2 → flinventory-2.2.4}/tests/test_defaulted_data.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: flinventory
3
- Version: 2.2.2
3
+ Version: 2.2.4
4
4
  Summary: An inventory system for self-help repair shops
5
5
  Author-Email: flukx <flinventory-flukx@612211124.xyz>
6
6
  License: GPL3
@@ -10,6 +10,7 @@ import logging
10
10
  import string
11
11
 
12
12
  import yaml
13
+ from typing import Optional
13
14
 
14
15
  from . import constant, labelprinter_typst
15
16
  from . import inventory_io
@@ -114,7 +115,7 @@ def add_arg_parsers(subparsers):
114
115
  ),
115
116
  )
116
117
  parser_levelname.add_argument("levelname", help="The new levelname.")
117
- parser_levelname.set_defaults(func=set_levelname)
118
+ parser_levelname.set_defaults(func=set_levelname_from_args)
118
119
 
119
120
  parser_schemaname = subparsers.add_parser(
120
121
  "setSchemaname", description="Set the name for a location schema."
@@ -131,10 +132,35 @@ def add_arg_parsers(subparsers):
131
132
  ),
132
133
  )
133
134
  parser_schemaname.add_argument("name", help="The new name.")
134
- parser_schemaname.set_defaults(func=set_schema_name)
135
+ parser_schemaname.set_defaults(func=set_schema_name_from_args)
135
136
 
136
137
 
137
- def get_schema(args) -> tuple[location.Schema, inventory_io.Inventory]:
138
+ def get_schema_from_args(
139
+ args,
140
+ ) -> tuple[location.Schema, inventory_io.Inventory]:
141
+ """Wrapper for get_schema based on command-line arguments.
142
+
143
+ Args:
144
+ args.level: see level_spec in get_schema
145
+ args.directory: directory of the inventory data
146
+ Returns:
147
+ a schema and its surrounding inventory.
148
+ Raises:
149
+ ValueError: if get_schema raises. Error is printed.
150
+ """
151
+ level_spec = args.level
152
+ if not level_spec:
153
+ print("No level specified.")
154
+ return
155
+ inventory = inventory_io.Inventory.from_json_files(directory=args.dataDirectory)
156
+ try:
157
+ return get_schema(inventory, args), inventory
158
+ except ValueError as wrong_spec:
159
+ print(wrong_spec.args[0])
160
+ return
161
+
162
+
163
+ def get_schema(inventory: inventory_io.Inventory, level_spec: str) -> location.Schema:
138
164
  """Get a schema in the inventory.
139
165
 
140
166
  Args:
@@ -146,58 +172,102 @@ def get_schema(args) -> tuple[location.Schema, inventory_io.Inventory]:
146
172
  args.directory: directory of the inventory data
147
173
  Returns:
148
174
  a schema and its surrounding inventory
175
+ Raises:
176
+ ValueError: if the level_spec was invalid. Exception.args[0] contains error message
149
177
  """
150
- level_spec = args.level
151
- if not level_spec:
152
- print("No level specified.")
153
- return
154
- inventory = inventory_io.Inventory.from_json_files(directory=args.dataDirectory)
155
178
  separator = level_spec[0]
156
179
  if separator in string.digits + string.ascii_letters + " ":
157
- print(
180
+ raise ValueError(
158
181
  "Probably separator missing as first character. Use non-digit, non-letter, non-space"
159
182
  )
160
- return
161
183
  schema = inventory.schema
162
184
  for schema_name in level_spec.split(separator)[1:]:
163
185
  print(
164
186
  f"debug: Currently at schema {schema.name if not schema.is_default() else '<default>'}"
165
187
  )
166
188
  if schema_name:
167
- print(f"choose subschema {schema_name}")
189
+ print(f"debug: choose subschema {schema_name}")
168
190
  schema = schema.get_subschema(schema_name)
169
191
  else:
170
- print("choose sub schema default")
192
+ print("debug: choose sub schema default")
171
193
  schema = schema.sub_schema_default
172
- print(schema)
173
- return schema, inventory
194
+ print("debug", schema)
195
+ return schema
174
196
 
175
197
 
176
- def set_levelname(args):
198
+ def set_levelname_from_args(args):
177
199
  """Set the levelname of one location schema."""
178
200
  new_levelname = args.levelname
179
- schema, inventory = get_schema(args)
201
+ schema, inventory = get_schema_from_args(args)
202
+ set_levelname(inventory, schema, new_levelname)
203
+
204
+
205
+ def set_levelname(
206
+ inventory: inventory_io.Inventory, schema: location.Schema, new_levelname: str
207
+ ):
208
+ """Set the levelname of one location schema.
209
+
210
+ Strip off whitespace.
211
+
212
+ Empty levelname raises ValueError if sub schemas exist.
213
+ Otherwise, it removes the possibility of this schema having subschemas.
214
+
215
+ Save the changes to disk.
216
+
217
+ Args:
218
+ inventory: inventory with schema and things (both needed)
219
+ schema: schema (level) to be changed
220
+ new_levelname: the new levelname
221
+ Raises:
222
+ ValueError: if the new levelname is empty or whitespace-only and sub schemas exist
223
+ """
224
+ schema_name = "a default schema" if schema.is_default() else schema.name
225
+ new_levelname = new_levelname.strip()
180
226
  try:
181
227
  print(
182
- f"Change level name of {args.level} from {schema.levelname} to {new_levelname}."
228
+ f"Change level name of {schema_name} from {schema.levelname} to {new_levelname}."
183
229
  )
184
230
  except location.InvalidLocation:
185
- print(f"Set level name of {args.level} from nothing to {new_levelname}.")
231
+ print(f"Set level name of {schema_name} from nothing to {new_levelname}.")
186
232
  schema.levelname = new_levelname
187
233
  inventory.save()
188
234
 
189
235
 
190
- def set_schema_name(args):
191
- """Set the same of a schema.
236
+ def set_schema_name_from_args(args):
237
+ """Set the name of a schema based on comand-line arguments.
192
238
 
193
239
  Fails on default schemas.
240
+
241
+ Raises:
242
+ ValueError: if level_spec is invalid
243
+ ValueError: if new name is empty except for whitespace
244
+ """
245
+ schema, inventory = get_schema_from_args(args)
246
+ set_schema_name(inventory, schema, args.name)
247
+
248
+
249
+ def set_schema_name(
250
+ inventory: inventory_io.Inventory, schema: location.Schema, new_name: str
251
+ ):
252
+ """Set the name of a schema.
253
+
254
+ Fails on default schemas.
255
+
256
+ Args:
257
+ inventory: inventory with schema and things (both needed)
258
+ schema: schema (level) to be changed
259
+ new_name: new name of the schema. Is stripped of surrounding whitespace.
260
+ Raises:
261
+ ValueError: if new name is empty except for whitespace
194
262
  """
195
- new_name = args.name
196
- schema, inventory = get_schema(args)
197
263
  if schema.is_default():
198
- print(f"Cannot change name of default schema {args.level}")
199
- return
200
- print(f"Change name of {args.level} from {schema.name} to {new_name}")
264
+ raise ValueError(f"Cannot change name of default schema.")
265
+ if not new_name.strip():
266
+ raise ValueError(
267
+ f"The new name '{new_name}' is empty (or only whitespace). This is invalid."
268
+ )
269
+ new_name = new_name.strip()
270
+ print(f"debug: Change schema name from {schema.name} to {new_name}")
201
271
  schema.name = new_name
202
272
  inventory.save()
203
273
 
@@ -134,7 +134,7 @@ class LabelPrinter:
134
134
  thing: thing with sign and location. Use information from sign if it has it.
135
135
  Otherwise, from label in location. Otherwise, None.
136
136
  key: the queried dimension
137
- maximum: Maximum value. If None, do not check for maximum.
137
+ maximum: Maximum value (in unit `unit`). If None, do not check for maximum.
138
138
  unit: unit of the output
139
139
  """
140
140
  assert not isinstance(
@@ -143,8 +143,9 @@ class LabelPrinter:
143
143
  value = self.in_unit(self.get_label_value(thing, key), default_unit=unit)
144
144
  if value is None:
145
145
  return None
146
+ value = value / TYPST_UNITS[unit]
146
147
  value = value if maximum is None else min(value, maximum)
147
- return f"{value}{unit}" if isinstance(value, int) else f"{value:3f}{unit}"
148
+ return f"{value}{unit}" if int(value) == value else f"{value:.3f}{unit}"
148
149
 
149
150
  def thing_data(self, thing: BoxedThing) -> dict[str, str]:
150
151
  """Get values for the insertion into the templates for one thing."""
@@ -154,13 +155,13 @@ class LabelPrinter:
154
155
  "name_1": thing.sign.get(("name", 0), None),
155
156
  "name_1_height": self.get_label_value(thing, ("name_height", 0)),
156
157
  "name_1_font_size": self.controlled_length(
157
- thing, ("font_size", 0), unit="pt"
158
+ thing, ("font_size", 0), unit=FONT_UNIT
158
159
  ),
159
160
  "lang_1": thing.options.languages[0], # one language is guaranteed
160
161
  "name_2": thing.sign.get(("name", 1), None),
161
162
  "name_2_height": self.get_label_value(thing, ("name_height", 1)),
162
163
  "name_2_font_size": self.controlled_length(
163
- thing, ("font_size", 1), unit="pt"
164
+ thing, ("font_size", 1), unit=FONT_UNIT
164
165
  ),
165
166
  "lang_2": (thing.options.languages + [None])[1], # None is default
166
167
  # Following 8 cases exist:
@@ -181,7 +182,7 @@ class LabelPrinter:
181
182
  else str(thing.where)
182
183
  ),
183
184
  "where_font_size": self.controlled_length(
184
- thing, "font_size_location", unit="pt"
185
+ thing, "font_size_location", unit=FONT_UNIT
185
186
  ),
186
187
  }
187
188
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "flinventory"
3
- version = "2.2.2"
3
+ version = "2.2.4"
4
4
  description = "An inventory system for self-help repair shops"
5
5
  authors = [
6
6
  { name = "flukx", email = "flinventory-flukx@612211124.xyz" },
File without changes
File without changes