Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

Commit

Permalink
Correct some English strings and some comments syntax.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierrick Le Brun committed Feb 16, 2013
1 parent 69c0c59 commit 727c8cc
Show file tree
Hide file tree
Showing 16 changed files with 103 additions and 97 deletions.
3 changes: 1 addition & 2 deletions src/salix_livetools_library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# -*- coding: utf-8 -*-
# vim: set et ai sta sw=2 ts=2 tw=0:
"""
Salix Live Installer library for using with either the graphical or ncurses dialogs
in order to help installing Salix.
Salix Live Installer library used by both the GUI and the Ncurses installers.
"""
from bootloader import *
from chroot import *
Expand Down
16 changes: 8 additions & 8 deletions src/salix_livetools_library/assertPlus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/evn python
#!/bin/env python
# -*- coding: utf-8 -*-
# vim: set et ai sta sw=2 ts=2 tw=0:
"""
Expand All @@ -10,23 +10,23 @@
- assertException(exceptionType, function)
- assertNoException(function)
to pass a function, you can use lambda expression like:
To pass a function, you can use lambda expression like:
assertException(lambda: myfunction())
"""
def assertTrue(expression):
"Expect the expression to be true"
"""Expect the expression to be true"""
assert expression, "'{0}' was expected to be true".format(expression)
def assertFalse(expression):
"Expect the expression to be false"
"""Expect the expression to be false"""
assert (not expression), "'{0}' was expected to be false".format(expression)
def assertEquals(expected, expression):
"Expect that the expression equals to the expected value"
"""Expect the expression to be equal to the expected value"""
assert expression == expected, "'{0}' expected, got '{1}'".format(expected, expression)
def assertNotEquals(expected, expression):
"Expect that the expression does not equals to the expected value"
"""Expect the expression not to be equal to the expected value"""
assert expression != expected, "'{0}' not expected, got '{1}'".format(expected, expression)
def assertException(exceptionType, function):
"Expect that the function trigger an exception of type exceptionType"
"""Expect the function to trigger an exception with exceptionType type"""
triggered = False
try:
function()
Expand All @@ -35,7 +35,7 @@ def assertException(exceptionType, function):
triggered = True
assert triggered, "Exception '{0}' expected with '{1}'".format(exceptionType, function.__doc__)
def assertNoException(function):
"Expect that the function does not trigger any exception"
"""Expect the function not to trigger any exception"""
triggered = False
unExpectedE = None
try:
Expand Down
2 changes: 1 addition & 1 deletion src/salix_livetools_library/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# vim: set et ai sta sw=2 ts=2 tw=0:
"""
Launching the boot loader setup tool with some defaults:
Function to launch the boot loader setup tool with some defaults:
- runBootsetup
"""
from execute import *
Expand Down
4 changes: 2 additions & 2 deletions src/salix_livetools_library/chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
def execChroot(path, cmd, shell = False):
"""
Execute cmd in the chroot defined by path.
pathes in cmd should be relative to the new root.
Paths in cmd should be relative to the new root directory.
"""
checkRoot()
if not path:
raise IOError("You should provide a path to change root.")
raise IOError("You should provide a path to change the root directory.")
elif not os.path.isdir(path):
raise IOError("'{0}' does not exist or is not a directory.".format(path))
chrootCmd = ['chroot', path]
Expand Down
22 changes: 13 additions & 9 deletions src/salix_livetools_library/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
# vim: set et ai sta sw=2 ts=2 tw=0:
"""
Get information of the disks and partitions in the system.
For now it only handles (S/P)ATA disks and partitions. RAID and LVM are not supported.
/proc and /sys should be mounted for getting information
Get information from the system disks and partitions.
For now it only handles (S/P)ATA disks and partitions, RAID and LVM are not supported yet.
/proc and /sys should be mounted to retrieve information.
Functions:
- getDisks
- getDiskInfo
Expand All @@ -21,7 +21,10 @@
from stat import *

def getDisks():
"Returns the disks devices (without /dev/) connected to the computer. RAID and LVM are not supported yet."
"""
Return the disks devices (without /dev/) connected to the computer.
RAID and LVM are not supported yet.
"""
ret = []
for l in open('/proc/partitions', 'r').read().splitlines():
if re.search(r' sd[^0-9]+$', l):
Expand All @@ -30,8 +33,9 @@ def getDisks():

def getDiskInfo(diskDevice):
"""
Returns a dictionary with the model name, size in bytes, size in human and if is removable for the disk device.
diskDevice should no be prefilled with '/dev/'
Return a dictionary with the following disk device's info:
model name, size in bytes, human readable size and whether it is removable or not.
diskDevice should no be prefixed with '/dev/'
dictionary key: model, size, sizeHuman, removable
"""
if S_ISBLK(os.stat('/dev/{0}'.format(diskDevice)).st_mode):
Expand All @@ -49,7 +53,7 @@ def getDiskInfo(diskDevice):

def getPartitions(diskDevice, skipExtended = True, skipSwap = True):
"""
Returns partitions following exclusion filters.
Return partitions matching exclusion filters.
"""
if S_ISBLK(os.stat('/dev/{0}'.format(diskDevice)).st_mode):
parts = [p.replace('/sys/block/{0}/'.format(diskDevice), '') for p in glob.glob('/sys/block/{0}/{0}*'.format(diskDevice))]
Expand All @@ -64,7 +68,7 @@ def getPartitions(diskDevice, skipExtended = True, skipSwap = True):

def getSwapPartitions():
"""
Returns partition devices that are of type Linux Swap.
Return partition devices with Linux Swap type.
"""
ret = []
for diskDevice in getDisks():
Expand All @@ -74,7 +78,7 @@ def getSwapPartitions():

def getPartitionInfo(partitionDevice):
"""
Returns a dictionary of partion information:
Return a dictionary with the partition information:
- fstype
- label
- size
Expand Down
14 changes: 7 additions & 7 deletions src/salix_livetools_library/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# vim: set et ai sta sw=2 ts=2 tw=0:
"""
Module to execute native commands and get their output:
Functions to execute native commands and get their output:
- execCall
- execCheck
- execGetOutput
Expand All @@ -15,24 +15,24 @@
def execCall(cmd, shell = True, env = {'LANG' : 'en_US'}):
"""
Execute a command and return the exit code.
The command is executed by default in a /bin/sh shell and using english locale.
The output of the command is not read. With some commands, it hangs if the output is not read when run in a shell.
For this type of command, prefer using execGetOutput even if you don't read the return value or using shell = False.
The command is executed by default in a /bin/sh shell with en_US locale.
The output of the command is not read. With some commands, it may hang if the output is not read when run in a shell.
For this type of command, it is preferable to use execGetOutput even the return value is not read or to use shell = False.
"""
return subprocess.call(cmd, shell = shell, env = env)

def execCheck(cmd, shell = True, env = {'LANG' : 'en_US'}):
"""
Execute a command and return 0 if ok or a subprocess.CalledProcessorError exception in case of error.
The command is executed by default in a /bin/sh shell and using english locale.
Execute a command and return 0 if OK or a subprocess.CalledProcessorError exception in case of error.
The command is executed by default in a /bin/sh shell with en_US locale.
"""
return subprocess.check_call(cmd, shell = shell, env = env)

def execGetOutput(cmd, withError = False, shell = True, env = {'LANG' : 'en_US'}):
"""
Execute a command and return its output in a list, line by line.
In case of error, it returns a subprocess.CalledProcessorError exception.
The command is executed by default in a /bin/sh shell and using english locale.
The command is executed by default in a /bin/sh shell with en_US locale.
"""
stdErr = None
if withError:
Expand Down
13 changes: 8 additions & 5 deletions src/salix_livetools_library/freesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
from execute import *

def _getMountPoint(device):
"Copied from 'mounting' module to break circular dependancies"
"""
Find the mount point of 'device' or None if not mounted
Copied from 'mounting' module to break circular dependencies
"""
mountpoint = None
for line in execGetOutput('mount', shell = False):
p, _, mp, _ = line.split(' ', 3) # 3 splits max, _ is discarded
Expand All @@ -26,7 +29,7 @@ def _getMountPoint(device):
return mountpoint

def getHumanSize(size):
"Returns the human readable format of the size in bytes"
"""Return the human readable format of the size in bytes"""
units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
unit = 0
sizeHuman = float(size)
Expand All @@ -38,7 +41,7 @@ def getHumanSize(size):
def getSizes(path):
"""
Compute the different sizes of the fileystem denoted by path (either a device or a file in filesystem).
Returns the following sizes (in a dictionary):
Return the following sizes (in a dictionary):
- size (total size)
- free (total free size)
- uuFree (free size for unprivileged users)
Expand Down Expand Up @@ -80,9 +83,9 @@ def getSizes(path):

def getUsedSize(path, blocksize = None):
"""
Returns the size of the space used by files and folders under 'path'.
Return the size of the space used by files and folders under 'path'.
If 'blocksize' is specified, mimic the space that will be used if the blocksize of the underlying filesystem where the one specified.
This could be useful if to be used to transfering files from one directory to another when the target filesystem use another blocksize.
This could be useful if used to transfer files from one directory to another when the target filesystem use another blocksize.
Return a tuple with (size, sizeHuman)
"""
cmd = ['du', '-c', '-s']
Expand Down
26 changes: 13 additions & 13 deletions src/salix_livetools_library/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

def getFsType(partitionDevice):
"""
Returns the file system type for that partition.
'partitionDevice' should no be prefilled with '/dev/' if it's a block device.
It can be a full path if the partition is contains in a file.
Returns 'Extended' if the partition is an extended partition and has no filesystem.
Return the file system type for that partition.
'partitionDevice' should no be prefixed with '/dev/' if it's a block device.
It can be a full path if the partition is contained in a file.
Return 'Extended' if the partition is an extended partition and has no filesystem.
"""
if os.path.exists('/dev/{0}'.format(partitionDevice)) and S_ISBLK(os.stat('/dev/{0}'.format(partitionDevice)).st_mode):
path = '/dev/{0}'.format(partitionDevice)
Expand All @@ -45,9 +45,9 @@ def getFsType(partitionDevice):

def getFsLabel(partitionDevice):
"""
Returns the label for that partition (if any).
'partitionDevice' should no be prefilled with '/dev/' if it's a block device.
It can be a full path if the partition is contains in a file.
Return the label for that partition (if any).
'partitionDevice' should no be prefixed with '/dev/' if it is a block device.
It can be a full path if the partition is contained in a file.
"""
if os.path.exists('/dev/{0}'.format(partitionDevice)) and S_ISBLK(os.stat('/dev/{0}'.format(partitionDevice)).st_mode):
path = '/dev/{0}'.format(partitionDevice)
Expand All @@ -69,11 +69,11 @@ def getFsLabel(partitionDevice):

def makeFs(partitionDevice, fsType, label=None, force=False, options=None):
"""
Creates a filesystem on the device.
'partitionDevice' should no be prefilled with '/dev/' if it's a block device.
Create a filesystem on the device.
'partitionDevice' should no be prefixed with '/dev/' if it is a block device.
'fsType' could be ext2, ext3, ext4, xfs, reiserfs, jfs, btrfs, ntfs, fat16, fat32, swap
Use 'force=True' if you want to force creating the filesystem and if 'partitionDevice' is a full path to a file (not a block device).
Use 'options' to force passing these options to the creation process (use a list)
Use 'force=True' if you want to force the creation of the filesystem and if 'partitionDevice' is a full path to a file (not a block device).
Use 'options' to force options on the creation process (use a list)
"""
if force and os.path.exists(partitionDevice):
path = partitionDevice
Expand Down Expand Up @@ -104,7 +104,7 @@ def makeFs(partitionDevice, fsType, label=None, force=False, options=None):
return None # should not append

def _makeExtFs(path, version, label, options, force):
"ExtX block size: 4k per default in /etc/mke2fs.conf"
"""ExtX block size: 4k per default in /etc/mke2fs.conf"""
cmd = ['/sbin/mkfs.ext{0:d}'.format(version)]
if not options:
options = []
Expand All @@ -120,7 +120,7 @@ def _makeExtFs(path, version, label, options, force):
return execCall(cmd, shell = False)

def _makeXfs(path, label, options, force):
"http://blog.peacon.co.uk/wiki/Creating_and_Tuning_XFS_Partitions"
"""http://blog.peacon.co.uk/wiki/Creating_and_Tuning_XFS_Partitions"""
cmd = ['/sbin/mkfs.xfs']
if not options:
options = ['-f'] # -f is neccessary to have this or you cannot create XFS on a non-empty partition or disk
Expand Down
8 changes: 4 additions & 4 deletions src/salix_livetools_library/fstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# vim: set et ai sta sw=2 ts=2 tw=0:
"""
Used to create fstab entries:
Functions to generate fstab entries:
- createFsTab
- addFsTabEntry
"""
Expand All @@ -11,7 +11,7 @@

def createFsTab(fstabMountPoint):
"""
Creates a etc/fstab empty file
Generate an empty /etc/fstab file
"""
try:
os.mkdir('{0}/etc'.format(fstabMountPoint))
Expand All @@ -21,8 +21,8 @@ def createFsTab(fstabMountPoint):

def addFsTabEntry(fstabMountPoint, device, mountPoint, fsType = None, options = None, dumpFlag = 0, fsckOrder = 0):
"""
Add a line to etc/fstab
If fsType is None, then it will be guessed from the device and the by using blkid
Add a line to /etc/fstab
If fsType is None, then it will be guessed from the device by using blkid
If options is None, then it will be guessed from the fsType like this:
- 'proc', 'sysfs', 'devpts', 'tmpfs', 'swap' |=> 'defaults'
- 'ext2', 'ext3', 'ext4', 'xfs', 'reiserfs', 'btrfs', 'jfs' |=> 'defaults,noatime'
Expand Down
6 changes: 3 additions & 3 deletions src/salix_livetools_library/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# -*- coding: utf-8 -*-
# vim: set et ai sta sw=2 ts=2 tw=0:
"""
Functions for getting kernel parameters:
Functions to retrieve kernel parameters:
- hasKernelParam
- getKernelParamValue
"""
import os

def hasKernelParam(param):
"""
Defines if the kernel parameter param has been defined on the kernel command line or not
Define if the kernel parameter param has been defined on the kernel command line or not
"""
if os.path.exists('/proc/cmdline'):
cmdline = open('/proc/cmdline', 'r').read().split()
Expand All @@ -21,7 +21,7 @@ def hasKernelParam(param):

def getKernelParamValue(param):
"""
Return the value of the kernel parameter, None if this param has no value and False if this param does not exist
Return the value of the kernel parameter, None if this param has no value and False if this param does not exist.
"""
if os.path.exists('/proc/cmdline'):
cmdline = open('/proc/cmdline', 'r').read().split()
Expand Down
Loading

0 comments on commit 727c8cc

Please sign in to comment.