Skip to content

Commit

Permalink
- Convert the old size stored as human readable size to bytes size as…
Browse files Browse the repository at this point in the history
… used in biomaj3
  • Loading branch information
horkko committed Feb 18, 2016
1 parent f3cd008 commit 76d69d7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bin/biomaj-migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import argparse
import bitmath
import datetime
import time
import logging
Expand All @@ -15,6 +16,23 @@
from biomaj.config import BiomajConfig
from biomaj.workflow import UpdateWorkflow, RemoveWorkflow, Workflow

def convert_size(size):
"""Convert old size from BioMAJ 1.2.x to size in bytes"""
supported_units = ['K', 'M', 'G', 'T', 'P']
pattern_size = re.compile("^([\d,]+)(\w)$")
relmatch = pattern_size.match(size)
if relmatch:
if relmatch.group(2) in supported_units:
size = relmatch.group(1)
unit = relmatch.group(2)
unit += 'iB'
size = size.replace(',', '.')
try:
new_size = bitmath.parse_string(size + ' ' + unit).to_Byte()
return float(new_size)
except ValueError as err:
raise Exception("Can't convert size: %s" % str(err))
return 0

def migrate_bank(cur, bank, history=False):
"""
Expand Down Expand Up @@ -44,7 +62,7 @@ def migrate_bank(cur, bank, history=False):
'session': row[1],
'creation': row[2],
'remove': row[3],
'size': row[4],
'size': convert_size(row[4]),
'release': row[5],
'remoterelease': row[5],
'logfile': row[6]
Expand Down

0 comments on commit 76d69d7

Please sign in to comment.