PEPify fstab

This commit is contained in:
Teo Mrnjavac 2014-07-29 14:26:19 +02:00
parent 906560ffee
commit 98b62808de

View File

@ -18,9 +18,6 @@
# along with Calamares. If not, see <http://www.gnu.org/licenses/>.
import os
import subprocess
import sys
import tempfile
import libcalamares
@ -39,64 +36,54 @@ FS_MAP = {
}
def mkdir_p( path ):
if not os.path.exists( path ):
os.makedirs( path )
def mkdir_p(path):
if not os.path.exists(path):
os.makedirs(path)
def listUuids():
dct = {}
uuidDir = "/dev/disk/by-uuid"
for uuid in os.listdir( uuidDir ):
devicePath = os.readlink( os.path.join( uuidDir, uuid ) )
devicePath = os.path.join( "/dev", os.path.basename( devicePath ) )
dct[ devicePath ] = uuid
return dct
def generate_fstab_line(partition):
fs = partition["fs"]
mount_point = partition["mountPoint"]
fs = FS_MAP.get(fs, fs)
def generateFstabLine( partition ):
fs = partition[ "fs" ]
mountPoint = partition[ "mountPoint" ]
fs = FS_MAP.get( fs, fs )
if not mountPoint and not fs == "swap":
if not mount_point and not fs == "swap":
return
options = "defaults"
if mountPoint == "/":
if mount_point == "/":
check = 1
elif mountPoint:
elif mount_point:
check = 2
else:
check = 0
return "UUID={} {:<14} {:<7} {:<10} 0 {}".format(
partition[ "uuid" ],
mountPoint or "none",
partition["uuid"],
mount_point or "none",
fs,
options,
check)
def run():
partitions = libcalamares.globalStorage.value( "partitions" )
rootMountPoint = libcalamares.globalStorage.value( "rootMountPoint" )
partitions = libcalamares.globalstorage.value("partitions")
root_mount_point = libcalamares.globalstorage.value("rootMountPoint")
# Create fstab
mkdir_p( os.path.join( rootMountPoint, "etc" ) )
fstabPath = os.path.join( rootMountPoint, "etc", "fstab" )
with open( fstabPath, "w" ) as fl:
print( HEADER, file = fl )
mkdir_p(os.path.join(root_mount_point, "etc"))
fstab_path = os.path.join(root_mount_point, "etc", "fstab")
with open(fstab_path, "w") as fl:
print(HEADER, file=fl)
for partition in partitions:
line = generateFstabLine( partition )
line = generate_fstab_line(partition)
if line:
print( line, file = fl )
print(line, file=fl)
# Create mount points
for partition in partitions:
if partition[ "mountPoint" ]:
mkdir_p( rootMountPoint + partition[ "mountPoint" ] )
if partition["mountPoint"]:
mkdir_p(root_mount_point + partition["mountPoint"])
return "All done"
return None