dom0/qubesutils: move parse_size() from qvm-grow-private to qubesutils (#421)
This commit is contained in:
parent
f7d84c9a27
commit
6b59f5c7c8
@ -70,6 +70,23 @@ def size_to_human (size):
|
||||
else:
|
||||
return str(round(size/(1024.0*1024*1024),1)) + ' GiB'
|
||||
|
||||
def parse_size(size):
|
||||
units = [ ('K', 1024), ('KB', 1024),
|
||||
('M', 1024*1024), ('MB', 1024*1024),
|
||||
('G', 1024*1024*1024), ('GB', 1024*1024*1024),
|
||||
]
|
||||
|
||||
size = size.strip().upper()
|
||||
if size.isdigit():
|
||||
return size
|
||||
|
||||
for unit, multiplier in units:
|
||||
if size.endswith(unit):
|
||||
size = size[:-len(unit)].strip()
|
||||
return int(size)*multiplier
|
||||
|
||||
raise QubesException("Invalid size: {0}.".format(size))
|
||||
|
||||
def print_stdout(text):
|
||||
print (text)
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
from qubes.qubes import QubesVmCollection
|
||||
from qubes.qubes import QubesException
|
||||
from qubesutils import parse_size
|
||||
from optparse import OptionParser
|
||||
import subprocess
|
||||
import os
|
||||
@ -30,24 +31,6 @@ import sys
|
||||
|
||||
qvm_run_path = "/usr/bin/qvm-run"
|
||||
|
||||
def parse_size(size):
|
||||
units = [ ('K', 1024), ('KB', 1024),
|
||||
('M', 1024*1024), ('MB', 1024*1024),
|
||||
('G', 1024*1024*1024), ('GB', 1024*1024*1024),
|
||||
]
|
||||
|
||||
size = size.strip().upper()
|
||||
if size.isdigit():
|
||||
return size
|
||||
|
||||
for unit, multiplier in units:
|
||||
if size.endswith(unit):
|
||||
size = size[:-len(unit)].strip()
|
||||
return int(size)*multiplier
|
||||
|
||||
print >> sys.stderr, "Invalid size: {0}.".format(size)
|
||||
exit(1)
|
||||
|
||||
def main():
|
||||
usage = "usage: %prog <vm-name> <size>"
|
||||
parser = OptionParser (usage)
|
||||
|
Loading…
Reference in New Issue
Block a user