diff --git a/pyproject.toml b/pyproject.toml index 7d79bc22..d6603770 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,7 +78,10 @@ default_item_type = "ref" [tool.poe.tasks.test] help = "Test with coverage" -cmd = "pytest -vv --cov" +sequence = [ + {ref = "generate-mo"}, + {cmd = "pytest -vv --cov"}, +] [tool.poe.tasks.test-fast] help = "Test until error" @@ -91,6 +94,7 @@ cmd = "pytest -vv --last-failed" [tool.poe.tasks.lint] help = "Check code" sequence = [ + {ref = "generate-mo"}, # {cmd = "flake8 --jobs 4 --statistics --show-source ${CODE}"}, # {cmd = "pylint --jobs 1 --rcfile=setup.cfg ${CODE}"}, {cmd = "black --skip-string-normalization --line-length=88 --check ${CODE}"}, @@ -101,12 +105,17 @@ sequence = [ [tool.poe.tasks.format] help = "Formating code" sequence = [ + {ref = "generate-mo"}, {cmd = "autoflake --recursive --in-place --remove-all-unused-imports ${CODE}"}, {cmd = "isort ${CODE}"}, {cmd = "black --skip-string-normalization --line-length=88 ${CODE}"}, {cmd = "unify --in-place --recursive ${CODE}"}, ] +[tool.poe.tasks.generate-mo] +help = "Generate mo files" +cmd = "python -m sportorg.language" + [tool.poe.tasks.run] help = "Run" cmd = "python SportOrg.pyw" diff --git a/sportorg/language.py b/sportorg/language.py index db8c7bfe..48965eb3 100644 --- a/sportorg/language.py +++ b/sportorg/language.py @@ -51,3 +51,8 @@ def get_languages() -> List[str]: translate = locale() + + +if __name__ == '__main__': + logger.info('Generate mo files') + generate_mo() diff --git a/sportorg/modules/teamwork/client.py b/sportorg/modules/teamwork/client.py index 32001538..5b02383a 100644 --- a/sportorg/modules/teamwork/client.py +++ b/sportorg/modules/teamwork/client.py @@ -73,7 +73,7 @@ def run(self): if len(full_data) >= hdr.size: command = Command( orjson.loads(full_data[: hdr.size].decode()), - Operations(hdr.opType).name, + Operations(hdr.op_type).name, ) self._out_queue.put(command) # for local full_data = full_data[hdr.size :] diff --git a/sportorg/modules/teamwork/packet_header.py b/sportorg/modules/teamwork/packet_header.py index 268bac0b..ce21b422 100644 --- a/sportorg/modules/teamwork/packet_header.py +++ b/sportorg/modules/teamwork/packet_header.py @@ -4,6 +4,13 @@ class ObjectTypes(Enum): + """ + ```python + obj_type = ObjectTypes['Race'] + obj_type.value + ``` + """ + Race = 0 Course = 1 Group = 2 @@ -24,6 +31,15 @@ def __repr__(self): class Operations(Enum): + """ + ```python + op = Operations['Create'] + + Operations(0).name + 'Create' + ``` + """ + Create = 0 Read = 1 Update = 2 @@ -39,46 +55,33 @@ def __repr__(self): return self.__str__() -""" -```python -obj_type = ObjectTypes['Race'] -obj_type.value - -op = Operations['Create'] - -Operations(0).name -'Create' -``` -""" - -""" -``` -?: boolean -H: Unsigned short -L: unsigned long -i: int -f: float -Q: Unsigned long long int -s: bytes string - -Header Tag: 2 Bytes -Operation type: 1 Byte (Unsigned Short) -Object type: 1 Byte (Unsigned Short) -uuid: 36 Bytes string -version: 4 Bytes (Unsigned Long) -size: 8 Bytes (Unsigned Long long) - -Total Header Size = 56 Bytes -``` -""" - - class Header: + """ + ``` + ?: boolean + H: Unsigned short + L: unsigned long + i: int + f: float + Q: Unsigned long long int + s: bytes string + + Header Tag: 2 Bytes + Operation type: 1 Byte (Unsigned Short) + Object type: 1 Byte (Unsigned Short) + uuid: 36 Bytes string + version: 4 Bytes (Unsigned Long) + size: 8 Bytes (Unsigned Long long) + + Total Header Size = 56 Bytes + ``` + """ + header_struck = '=2s2H36sLQ' header_size = struct.calcsize(header_struck) def __init__(self, obj_data=None, op_type=Operations.Update.name): - self.packTag = b'SO' + self.pack_tag = b'SO' if obj_data: try: obj_type = obj_data['object'] @@ -91,23 +94,23 @@ def __init__(self, obj_data=None, op_type=Operations.Update.name): obj_type, op_type, obj_uuid ) ) - self.opType = Operations[op_type].value - self.objType = ObjectTypes[obj_type].value + self.op_type = Operations[op_type].value + self.obj_type = ObjectTypes[obj_type].value self.uuid = obj_uuid self.version = 0 # int(obj_ver) self.size = len(obj_data) else: - self.opType = Operations[op_type].value - self.objType = 0 + self.op_type = Operations[op_type].value + self.obj_type = 0 self.uuid = '' self.version = 0 # int(obj_ver) self.size = 0 def unpack_header(self, header): ( - self.packTag, - self.opType, - self.objType, + self.pack_tag, + self.op_type, + self.obj_type, self.uuid, self.version, self.size, @@ -120,12 +123,12 @@ def prepare_header(self, obj_data, op_type): obj_uuid = obj_data['id'] except AttributeError: return False - self.opType = Operations[op_type].value + self.op_type = Operations[op_type].value try: - self.objType = ObjectTypes[obj_type].value + self.obj_type = ObjectTypes[obj_type].value except Exception: - self.objType = 255 # Unknown + self.obj_type = 255 # Unknown self.uuid = obj_uuid self.version = 0 # int(obj_ver) @@ -136,9 +139,9 @@ def pack_header(self, psize): self.size = psize return struct.pack( Header.header_struck, - self.packTag, - self.opType, - self.objType, + self.pack_tag, + self.op_type, + self.obj_type, bytes(self.uuid, 'ascii'), self.version, self.size, diff --git a/sportorg/modules/teamwork/server.py b/sportorg/modules/teamwork/server.py index 8826772f..1aed50a9 100644 --- a/sportorg/modules/teamwork/server.py +++ b/sportorg/modules/teamwork/server.py @@ -76,7 +76,7 @@ def run(self): if len(full_data) >= hdr.size: command = Command( json.loads(full_data[: hdr.size].decode()), - Operations(hdr.opType).name, + Operations(hdr.op_type).name, self.connect.addr, ) command.exclude(self.connect.addr)