Move GetVolumeID to common lib
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import lib
|
||||
import os
|
||||
import re
|
||||
import string
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
class GrubUpdater(object):
|
||||
|
||||
_VOLUME_ID_REGEX = re.compile(b'^Volume id: (?P<volume_id>.+)$', re.MULTILINE)
|
||||
_HOTKEYS = string.digits + string.ascii_letters
|
||||
|
||||
def __init__(self, image_dir, boot_dir):
|
||||
@@ -20,15 +18,6 @@ class GrubUpdater(object):
|
||||
|
||||
self._image_path = '/' + os.path.relpath(self._image_dir, self._boot_dir)
|
||||
|
||||
def _GetVolumeID(self, path):
|
||||
isoinfo = subprocess.check_output([
|
||||
'isoinfo',
|
||||
'-d',
|
||||
'-i', path,
|
||||
])
|
||||
match = self._VOLUME_ID_REGEX.search(isoinfo)
|
||||
return match.group('volume_id').decode('ascii')
|
||||
|
||||
def Update(self):
|
||||
grub_dir = os.path.join(self._boot_dir, 'grub')
|
||||
|
||||
@@ -63,7 +52,7 @@ menuentry "%(image_filename)s (%(volume_id)s)" --hotkey=%(hotkey)s {
|
||||
'image_filename': filename,
|
||||
'image_path': self._image_path,
|
||||
'hotkey': self._HOTKEYS[i],
|
||||
'volume_id': self._GetVolumeID(os.path.join(self._image_dir, filename)),
|
||||
'volume_id': lib.GetVolumeID(os.path.join(self._image_dir, filename)),
|
||||
})
|
||||
|
||||
fh.flush()
|
||||
|
||||
Reference in New Issue
Block a user