move files and fix bugs
This commit is contained in:
parent
25714d3703
commit
326c122213
2
example/migrations/device-lots.csv
Normal file
2
example/migrations/device-lots.csv
Normal file
|
@ -0,0 +1,2 @@
|
|||
"lot_name";"dhid"
|
||||
"Moravia202205y06";"N9EEG"
|
|
12
example/migrations/dhids.csv
Normal file
12
example/migrations/dhids.csv
Normal file
|
@ -0,0 +1,12 @@
|
|||
"dhid";"uuid"
|
||||
"JGMLO";"ae36bd1b-a0a5-4860-ad67-1644d2ce0c7b"
|
||||
"MLVKL";"8ad8022b-e1d7-4c9a-bfad-e3677beb9f8d"
|
||||
"D8BWP";"9868c6d4-a96c-4ae6-b2bd-1ec72a1891a4"
|
||||
"D8BYP";"b3a1fff7-24f9-4a72-9362-86934d03b20a"
|
||||
"MLVKL";"5d2f7902-ceb4-452c-832c-adaf3cbc3686"
|
||||
"9GRZ5";"e48b2121-7edf-4a6e-ba0c-9f2e1a87c7f9"
|
||||
"V9XRK";"e6f5a76f-4905-4553-b4d4-bc73bf1a8022"
|
||||
"V9XBK";"7aa682aa-77c5-43a5-91e4-1ef9a2736156"
|
||||
"7DVLE";"522a4403-bfb3-4fe6-b454-4db6c3040a58"
|
||||
"QPAVE";"946fd30b-68f7-425f-aca4-1ae39a86d35"
|
||||
"N9EEG";"0cf11287-5603-45e4-9dd6-075871286de9"
|
|
2
example/migrations/lot.csv
Normal file
2
example/migrations/lot.csv
Normal file
|
@ -0,0 +1,2 @@
|
|||
"name";"type"
|
||||
"Moravia202205y06";"Incoming"
|
|
|
@ -81,6 +81,10 @@ def open_snapshot(uuid):
|
|||
|
||||
### migration snapshots ###
|
||||
def create_custom_id(dhid, uuid, user):
|
||||
|
||||
if not uuid or not dhid:
|
||||
return
|
||||
|
||||
tag = Annotation.objects.filter(
|
||||
uuid=uuid,
|
||||
type=Annotation.Type.SYSTEM,
|
||||
|
@ -88,7 +92,7 @@ def create_custom_id(dhid, uuid, user):
|
|||
owner=user.institution
|
||||
).first()
|
||||
|
||||
if tag:
|
||||
if tag or not uuid or not dhid:
|
||||
return
|
||||
|
||||
Annotation.objects.create(
|
||||
|
@ -104,19 +108,28 @@ def create_custom_id(dhid, uuid, user):
|
|||
def migrate_snapshots(row, user):
|
||||
if not row or not user:
|
||||
return
|
||||
|
||||
dhid = row.get("dhid")
|
||||
uuid = row.get("uuid")
|
||||
snapshot, snapshot_path = open_snapshot(uuid)
|
||||
if not snapshot or not snapshot_path:
|
||||
return
|
||||
|
||||
logger.info(snapshot.get("version"))
|
||||
if snapshot.get('version') == "2022.12.2-beta":
|
||||
return
|
||||
|
||||
# insert snapshot
|
||||
path_name = save_in_disk(snapshot, user.institution.name)
|
||||
Build(snapshot, user)
|
||||
move_json(path_name, user.institution.name)
|
||||
|
||||
# insert dhid
|
||||
create_custom_id(dhid, uuid, user)
|
||||
try:
|
||||
create_custom_id(dhid, uuid, user)
|
||||
except Exception as err:
|
||||
logger.error(err)
|
||||
logger.error("DHID: %s uuid: %s", dhid, uuid)
|
||||
|
||||
### end migration snapshots ###
|
||||
|
||||
|
@ -133,14 +146,15 @@ def migrate_lots(row, user):
|
|||
user=user
|
||||
)
|
||||
|
||||
lot = Lot.objects.filter(name=tag, owner=user.institution).first()
|
||||
if not lot:
|
||||
lot = Lot.objects.create(
|
||||
name=name,
|
||||
owner=user.institution,
|
||||
user=user,
|
||||
type=ltag
|
||||
)
|
||||
if Lot.objects.filter(name=tag, owner=user.institution).first():
|
||||
return
|
||||
|
||||
Lot.objects.create(
|
||||
name=name,
|
||||
owner=user.institution,
|
||||
user=user,
|
||||
type=ltag
|
||||
)
|
||||
|
||||
|
||||
def add_device_in_lot(row, user):
|
||||
|
@ -157,6 +171,10 @@ def add_device_in_lot(row, user):
|
|||
owner=user.institution,
|
||||
).first()
|
||||
|
||||
if not dev:
|
||||
logger.warning("Not exist dhid %s", dhid)
|
||||
return
|
||||
|
||||
lot = Lot.objects.filter(
|
||||
name=lot_name,
|
||||
owner=user.institution,
|
||||
|
@ -170,9 +188,9 @@ def add_device_in_lot(row, user):
|
|||
user=user,
|
||||
)
|
||||
|
||||
if DeviceLot.objects.filter(lot=lot, device_id=dev.uuid).exists():
|
||||
if DeviceLot.objects.filter(lot=lot, device_id=dhid).exists():
|
||||
return
|
||||
DeviceLot.objects.create(lot=lot, device_id=dev.uuid)
|
||||
DeviceLot.objects.create(lot=lot, device_id=dhid)
|
||||
|
||||
### end migration lots ###
|
||||
|
||||
|
@ -184,7 +202,7 @@ def prepare_logger():
|
|||
|
||||
console_handler = logging.StreamHandler()
|
||||
console_handler.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter('[%(asctime)s] workbench: %(levelname)s: %(message)s')
|
||||
formatter = logging.Formatter('[%(asctime)s] migrate: %(levelname)s: %(message)s')
|
||||
console_handler.setFormatter(formatter)
|
||||
logger.addHandler(console_handler)
|
||||
|
||||
|
@ -205,7 +223,7 @@ def parse_args():
|
|||
help="path to the csv file with relation lot_name and type of lot."
|
||||
)
|
||||
parser.add_argument(
|
||||
'--csv-lots',
|
||||
'--csv-lots-dhid',
|
||||
help="path to the csv file with relation lot_name and type of lot."
|
||||
)
|
||||
parser.add_argument(
|
||||
|
@ -231,7 +249,7 @@ def main():
|
|||
|
||||
if args.csv_dhid:
|
||||
# migration snapthots
|
||||
for row in open_csv(args.csv):
|
||||
for row in open_csv(args.csv_dhid):
|
||||
migrate_snapshots(row, user)
|
||||
|
||||
# migration lots
|
||||
|
@ -239,5 +257,9 @@ def main():
|
|||
for row in open_csv(args.lots):
|
||||
migrate_lots(row, user)
|
||||
|
||||
# migration dhids in lots
|
||||
if args.csv_lots_dhid:
|
||||
for row in open_csv(args.csv_lots_dhid):
|
||||
add_device_in_lot(row, user)
|
||||
if __name__ == '__main__':
|
||||
main()
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +0,0 @@
|
|||
"lot_name";"dhid"
|
||||
"t1";"ZZZZ"
|
|
|
@ -1,5 +0,0 @@
|
|||
"name";"type"
|
||||
"t1";"temporal"
|
||||
"o2";"outgoing"
|
||||
"i3";"incoming"
|
||||
"o4";"outgoing"
|
|
|
@ -1,2 +0,0 @@
|
|||
"dhid";"uuid"
|
||||
"ZZZZ";"db523f01-92b2-4282-af2a-d9a653f93d45"
|
|
Loading…
Reference in a new issue