diff --git a/ereuse_devicehub/migrations/versions/17288b2a7440_change_firewire.py b/ereuse_devicehub/migrations/versions/17288b2a7440_change_firewire.py new file mode 100644 index 00000000..cfb23427 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/17288b2a7440_change_firewire.py @@ -0,0 +1,36 @@ +"""change firewire + +Revision ID: 17288b2a7440 +Revises: 8571fb32c912 +Create Date: 2022-03-29 11:49:39.270791 + +""" +from alembic import op, context +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql +import citext + + +# revision identifiers, used by Alembic. +revision = '17288b2a7440' +down_revision = '8571fb32c912' +branch_labels = None +depends_on = None + + +def get_inv(): + INV = context.get_x_argument(as_dictionary=True).get('inventory') + if not INV: + raise ValueError("Inventory value is not specified") + return INV + + +def upgrade(): + op.alter_column('motherboard', 'firewire', citext.CIText(), schema=f'{get_inv()}') + op.add_column('computer', sa.Column('uuid', postgresql.UUID(as_uuid=True), + nullable=True), + schema=f'{get_inv()}') + + +def downgrade(): + op.alter_column('motherboard', 'firewire', sa.SmallInteger(), schema=f'{get_inv()}') diff --git a/ereuse_devicehub/parser/computer.py b/ereuse_devicehub/parser/computer.py index 4b93ec4c..54e75093 100644 --- a/ereuse_devicehub/parser/computer.py +++ b/ereuse_devicehub/parser/computer.py @@ -319,7 +319,7 @@ class Motherboard(Component): super().__init__(node) self.from_lshw(node) self.usb = self.num_interfaces(node, 'usb') - self.firewire = self.num_interfaces(node, 'firewire') + self.firewire = str(self.num_interfaces(node, 'firewire')) self.serial = self.num_interfaces(node, 'serial') self.pcmcia = self.num_interfaces(node, 'pcmcia') self.slots = int(2) diff --git a/ereuse_devicehub/parser/parser.py b/ereuse_devicehub/parser/parser.py index 0ee98f1a..73b8aa6a 100644 --- a/ereuse_devicehub/parser/parser.py +++ b/ereuse_devicehub/parser/parser.py @@ -136,7 +136,7 @@ class ParseSnapshot: return self.dmi.get("BIOS")[0].get("Release Date", self.default) def get_firmware(self): - return int(float(self.dmi.get("BIOS")[0].get("Firmware Revision", 1))) + return self.dmi.get("BIOS")[0].get("Firmware Revision", '1') def get_max_ram_size(self): size = 0 @@ -354,8 +354,8 @@ class ParseSnapshotLsHw: def set_basic_datas(self): pc, self.components_obj = Computer.run(self.lshw_raw, self.hwinfo_raw) - # import pdb; pdb.set_trace() self.device = pc.dump() + self.device['uuid'] = self.dmi.get("System")[0].get("UUID") def set_components(self): memory = None diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 98227c4c..fe95460b 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -663,6 +663,7 @@ class Computer(Device): db.ForeignKey(User.id), nullable=True) receiver = db.relationship(User, primaryjoin=receiver_id == User.id) + uuid = db.Column(UUID(as_uuid=True), nullable=True) def __init__(self, *args, **kwargs) -> None: if args: @@ -955,7 +956,7 @@ class Motherboard(JoinedComponentTableMixin, Component): slots = Column(SmallInteger, check_range('slots', min=0)) slots.comment = """PCI slots the motherboard has.""" usb = Column(SmallInteger, check_range('usb', min=0)) - firewire = Column(SmallInteger, check_range('firewire', min=0)) + firewire = Column(CIText()) serial = Column(SmallInteger, check_range('serial', min=0)) pcmcia = Column(SmallInteger, check_range('pcmcia', min=0)) bios_date = Column(db.Date) diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 0c265d78..ef4c163b 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -136,6 +136,7 @@ class Computer(Device): owner_id = UUID(data_key='ownerID') transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment) receiver_id = UUID(data_key='receiverID') + uuid = UUID(required=False) class Desktop(Computer): @@ -271,7 +272,8 @@ class Motherboard(Component): slots = Integer(validate=Range(0, 20), description=m.Motherboard.slots.comment) usb = Integer(validate=Range(0, 20), description=m.Motherboard.usb.comment) - firewire = Integer(validate=Range(0, 20), description=m.Motherboard.firewire.comment) + # firewire = Integer(validate=Range(0, 20), description=m.Motherboard.firewire.comment) + firewire = String(description=m.Motherboard.firewire.comment) serial = Integer(validate=Range(0, 20), description=m.Motherboard.serial.comment) pcmcia = Integer(validate=Range(0, 20), description=m.Motherboard.pcmcia.comment) bios_date = Date(validate=Range(datetime.date(year=1980, month=1, day=1),