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

Commit

Permalink
Corrections in the password strength method, to not mix updating the …
Browse files Browse the repository at this point in the history
…interface and getting info at the same time.
  • Loading branch information
Cyrille Pontvieux committed Feb 16, 2013
1 parent 952db23 commit 9889395
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 75 deletions.
4 changes: 0 additions & 4 deletions src/salix-live-installer.glade
Original file line number Diff line number Diff line change
Expand Up @@ -3367,8 +3367,6 @@ If you already have all the needed partitions, please click on the button 'Do no
<property name="visible">True</property>
<property name="app_paintable">True</property>
<property name="can_focus">False</property>
<signal name="enter-notify-event" handler="on_user_pass_strength_enter_notify_event" swapped="no"/>
<signal name="leave-notify-event" handler="on_user_pass_strength_leave_notify_event" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
Expand Down Expand Up @@ -3603,8 +3601,6 @@ If you already have all the needed partitions, please click on the button 'Do no
<property name="visible">True</property>
<property name="app_paintable">True</property>
<property name="can_focus">False</property>
<signal name="enter-notify-event" handler="on_root_pass_strength_enter_notify_event" swapped="no"/>
<signal name="leave-notify-event" handler="on_root_pass_strength_leave_notify_event" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
Expand Down
44 changes: 25 additions & 19 deletions src/salix-live-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def __init__(self, is_test = False, is_test_clone = False):
self.LinuxNewMountColumn = builder.get_object("linux_newmount_column")
self.WinPartColumn = builder.get_object("win_part_column")
self.WinSizeColumn = builder.get_object("win_size_column")
self.WinOldSysColumn = builder.get_object("win_oldsys_column")
self.WinOldSysColumn = builder.get_object("win_oldsys_column")
self.WinNewMountColumn = builder.get_object("win_newmount_column")
# Initialize the contextual help box
self.context_intro = _("Contextual help.")
Expand All @@ -204,7 +204,7 @@ def __init__(self, is_test = False, is_test_clone = False):
# Connect signals
self.add_custom_signals()
builder.connect_signals(self)

# General contextual help
def on_leave_notify_event(self, widget, data=None):
self.ContextLabel.set_text(self.context_intro)
Expand All @@ -222,7 +222,7 @@ def on_install_button_enter_notify_event(self, widget, data=None):
def on_launch_eventbox_enter_notify_event(self, widget, data=None):
self.ContextLabel.set_text(_("Launch Salix installation. This button will not be active until \
all settings are configured correctly."))

# Time contextual help
def on_time_tab_enter_notify_event(self, widget, data=None):
self.ContextLabel.set_text(_("Access the time settings."))
Expand Down Expand Up @@ -1125,37 +1125,42 @@ def on_clone_login_undo_clicked(self, widget, data=None):
self.users_settings_liveclone()
def get_password_strength(self, pwd):
"""
Return a number from 0 to 4 to indicate the strength of the password.
Returns tuple containing:
- a number from 0 to 4 to indicate the strength of the password.
- a contextual message.
"""
if not pwd:
score = 0
context_msg = ''
else:
score = 1
self.ContextLabel.set_markup(_("<b>Password strength:</b>\nLess than 5 characters"))
if len(pwd) >= 5:
min_chars = 5
context_msg = _("Less than {min} characters").format(min = min_chars)
if len(pwd) >= min_chars:
score += 1
contextLabelText = _("<b>Password strength:</b>\n")
context_msg = ''
if re.search(r'[A-Z]', pwd):
score += 0.5
else:
contextLabelText += _("No upper case letter...\n")
context_msg += "\n" + _("No upper case letter...")
if re.search(r'[1-9]', pwd):
score += 0.5
else:
contextLabelText += _("No number...\n")
context_msg += "\n" + _("No number...")
if re.search(r'[-_.,;:!?"\']', pwd):
score += 0.5
else:
contextLabelText += _("No punctuation...\n")
context_msg += "\n" + _("No punctuation...")
if re.search(r'[][(){}/\<>$%*#@^]', pwd):
score += 0.5
else:
contextLabelText += _("No symbol...\n")
context_msg += "\n" + _("No symbol...")
score = int(math.floor(score))
self.ContextLabel.set_markup(_(contextLabelText))
return score
if score == 4:
context_msg = _("Satisfactory!")
return (score, context_msg)
def set_progressbar_strength(self, pwd, draw_widget):
strength = self.get_password_strength(pwd)
strength, context_msg = self.get_password_strength(pwd)
gc = draw_widget.window.new_gc()
bg_color = draw_widget.get_colormap().alloc_color("#FFFFFF")
border_color = draw_widget.get_colormap().alloc_color("#000000")
Expand All @@ -1167,17 +1172,18 @@ def set_progressbar_strength(self, pwd, draw_widget):
progress_color = draw_widget.get_colormap().alloc_color("#CCCC00")
elif strength == 4:
progress_color = draw_widget.get_colormap().alloc_color("#00FF00")
self.ContextLabel.set_markup(_("<b>Password strength:</b>\n\nSatisfactory!"))
gc.set_foreground(bg_color)
draw_widget.window.draw_rectangle(gc, True, 0, 1, 80, 20)
gc.set_foreground(progress_color)
draw_widget.window.draw_rectangle(gc, True, 0, 1, 20 * strength, 20)
gc.set_foreground(border_color)
draw_widget.window.draw_rectangle(gc, False, 0, 1, 80, 20)
context_label_text = "<b>" + _("Password strength:") + "</b>\n"
self.ContextLabel.set_markup(context_label_text + context_msg)

def on_user_pass1_entry_changed(self, widget, data=None):
self.set_progressbar_strength(widget.get_text().strip(), self.UserPassStrength)
def on_user_visible_checkbutton_toggled(self, widget, data=None):
def on_user_visible_checkbutton_toggled(self, widget, data=None):
self.UserPass1Entry.set_visibility(self.UserVisibleCheckButton.get_active())
self.UserPass2Entry.set_visibility(self.UserVisibleCheckButton.get_active())
def check_login(self, login):
Expand Down Expand Up @@ -1293,7 +1299,7 @@ def on_install_button_clicked(self, widget, data=None):
# Info window skeleton:
def info_dialog(message, parent = None):
"""
Display an information message.
Displays an information message.
"""
dialog = gtk.MessageDialog(parent = parent, type = gtk.MESSAGE_INFO, buttons = gtk.BUTTONS_OK, flags = gtk.DIALOG_MODAL)
Expand All @@ -1305,7 +1311,7 @@ def info_dialog(message, parent = None):
# Error window skeleton:
def error_dialog(message, parent = None):
"""
Display an error message.
Displays an error message.
"""
dialog = gtk.MessageDialog(parent = parent, type = gtk.MESSAGE_ERROR, buttons = gtk.BUTTONS_CLOSE, flags = gtk.DIALOG_MODAL)
dialog.set_markup(message)
Expand All @@ -1314,7 +1320,7 @@ def error_dialog(message, parent = None):
dialog.destroy()

# Launch the application
if __name__ == '__main__':
if __name__ == '__main__':
# If no root privilege, displays error message and exit
is_test = (len(sys.argv) > 1 and sys.argv[1] == '--test')
if is_test:
Expand Down
16 changes: 9 additions & 7 deletions src/salix_livetools_library/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

def getDisks():
"""
Return the disks devices (without /dev/) connected to the computer.
Returns the disks devices (without /dev/) connected to the computer.
RAID and LVM are not supported yet.
"""
ret = []
Expand All @@ -33,10 +33,12 @@ def getDisks():

def getDiskInfo(diskDevice):
"""
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.
Returns a dictionary with the following disk device's info:
- model: model name
- size: size in bytes
- sizeHuman: human readable size
- removable: 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):
modelName = open('/sys/block/{0}/device/model'.format(diskDevice), 'r').read().strip()
Expand All @@ -53,7 +55,7 @@ def getDiskInfo(diskDevice):

def getPartitions(diskDevice, skipExtended = True, skipSwap = True):
"""
Return partitions matching exclusion filters.
Returns 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 @@ -68,7 +70,7 @@ def getPartitions(diskDevice, skipExtended = True, skipSwap = True):

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

def getPartitionInfo(partitionDevice):
"""
Return a dictionary with the partition information:
Returns a dictionary with the partition information:
- fstype
- label
- size
Expand Down
10 changes: 5 additions & 5 deletions src/salix_livetools_library/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@

def execCall(cmd, shell = True, env = {'LANG' : 'en_US'}):
"""
Execute a command and return the exit code.
Executes a command and return the exit code.
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.
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.
Executes 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.
Executes 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 with en_US locale.
"""
Expand Down Expand Up @@ -62,7 +62,7 @@ def execGetOutput(cmd, withError = False, shell = True, env = {'LANG' : 'en_US'}

def checkRoot():
"""
Raise an Exception if you run this code without root permissions
Raises an Exception if you run this code without root permissions
"""
if os.getuid() != 0:
raise Exception('You need root permissions.')
Expand Down
12 changes: 7 additions & 5 deletions src/salix_livetools_library/freesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

def _getMountPoint(device):
"""
Find the mount point of 'device' or None if not mounted
Finds the mount point of 'device' or None if not mounted
Copied from 'mounting' module to break circular dependencies
"""
mountpoint = None
Expand All @@ -29,7 +29,9 @@ def _getMountPoint(device):
return mountpoint

def getHumanSize(size):
"""Return the human readable format of the size in bytes"""
"""
Returns the human readable format of the size in bytes
"""
units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
unit = 0
sizeHuman = float(size)
Expand All @@ -40,7 +42,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).
Computes the different sizes of the fileystem denoted by path (either a device or a file in filesystem).
Return the following sizes (in a dictionary):
- size (total size)
- free (total free size)
Expand Down Expand Up @@ -83,10 +85,10 @@ def getSizes(path):

def getUsedSize(path, blocksize = None):
"""
Return the size of the space used by files and folders under 'path'.
Returns 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 used to transfer files from one directory to another when the target filesystem use another blocksize.
Return a tuple with (size, sizeHuman)
Returns a tuple with (size, sizeHuman)
"""
cmd = ['du', '-c', '-s']
if blocksize:
Expand Down
18 changes: 11 additions & 7 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):
"""
Return the file system type for that partition.
Returns 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.
Returns '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,7 +45,7 @@ def getFsType(partitionDevice):

def getFsLabel(partitionDevice):
"""
Return the label for that partition (if any).
Returns 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.
"""
Expand All @@ -69,11 +69,11 @@ def getFsLabel(partitionDevice):

def makeFs(partitionDevice, fsType, label=None, force=False, options=None):
"""
Create a filesystem on the device.
Creates 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 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)
Use 'options' to force these options on the creation process (use a list)
"""
if force and os.path.exists(partitionDevice):
path = partitionDevice
Expand Down Expand Up @@ -104,7 +104,9 @@ 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 +122,9 @@ 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
2 changes: 1 addition & 1 deletion src/salix_livetools_library/fstab.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

def createFsTab(fstabMountPoint):
"""
Generate an empty /etc/fstab file
Generates an empty /etc/fstab file
"""
try:
os.mkdir('{0}/etc'.format(fstabMountPoint))
Expand Down
4 changes: 2 additions & 2 deletions src/salix_livetools_library/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

def hasKernelParam(param):
"""
Define if the kernel parameter param has been defined on the kernel command line or not
Defines 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.
Returns 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
8 changes: 4 additions & 4 deletions src/salix_livetools_library/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def findCurrentKeymap(mountPoint = None):
- /etc/rc.d/rc.keymap, or
- in the 'keyb=' kernel parameter
The detected keymap is then checked against the first column of one of the files: {0}
Return None if not found
Returns None if not found
""".format(' '.join(_keymapsLocation))
if mountPoint and not os.path.isdir(mountPoint):
raise IOError("'{0}' does not exist or is not a directory.".format(mountPoint))
Expand Down Expand Up @@ -62,7 +62,7 @@ def findCurrentKeymap(mountPoint = None):

def listAvailableKeymaps(mountPoint = None):
"""
Return a list of couple (keymap, keyboardType).
Returns a list of couple (keymap, keyboardType).
'keymap' is a Console keymap as found in /usr/share/kbd/
'keyboardType' is either 'azerty', 'qwerty', 'qwertz', etc and is there only for information
The keymaps are extracted from one of the files: {0}
Expand Down Expand Up @@ -96,7 +96,7 @@ def listAvailableKeymaps(mountPoint = None):

def isNumLockEnabledByDefault(mountPoint = None):
"""
Return True if the num lock is enabled by default.
Returns True if the num lock is enabled by default.
To do this, the execute bit of /etc/rc.d/rc.numlock is checked.
"""
if mountPoint and not os.path.isdir(mountPoint):
Expand All @@ -107,7 +107,7 @@ def isNumLockEnabledByDefault(mountPoint = None):

def isIbusEnabledByDefault(mountPoint = None):
"""
Return True if the IBus is enabled by default.
Returns True if the IBus is enabled by default.
To do this, the execute bit of /usr/bin/ibus-daemon and /etc/profile.d/ibus.sh are checked.
"""
if mountPoint and not os.path.isdir(mountPoint):
Expand Down
Loading

0 comments on commit 9889395

Please sign in to comment.