<s> import builtins <EOL> import configparser <EOL> import logging <EOL> import os <EOL> import requests <EOL> import random <EOL> import shutil <EOL> import subprocess <EOL> import sys <EOL> import tarfile <EOL> import urllib . request <EOL> from . import ui as UI <EOL> def extractTar ( src , dst ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> checkPath ( dst ) <EOL> UI . logDebug ( "<STR_LIT>" + getPath ( src ) + "<STR_LIT>" + getPath ( dst ) ) <EOL> xz = tarfile . open ( getPath ( src ) , '<STR_LIT>' ) <EOL> xz . extractall ( getPath ( dst ) ) <EOL> xz . close ( ) <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def download ( url ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> UI . logDebug ( "<STR_LIT>" + url + "<STR_LIT>" + getPath ( os . path . basename ( url ) ) ) <EOL> with urllib . request . urlopen ( url ) as src , open ( getPath ( os . path . basename ( url ) ) , '<STR_LIT:wb>' ) as out_file : <EOL> shutil . copyfileobj ( src , out_file ) <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def unlinkFile ( src ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if os . path . isfile ( getPath ( src ) ) : <EOL> UI . logDebug ( "<STR_LIT>" + getPath ( src ) ) <EOL> os . unlink ( getPath ( src ) ) <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def touch ( fname , mode = <NUM_LIT> , dir_fd = None , ** kwargs ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> UI . logDebug ( "<STR_LIT>" + getPath ( fname ) ) <EOL> flags = os . O_CREAT | os . O_APPEND <EOL> with os . fdopen ( os . open ( getPath ( fname ) , flags = flags , mode = mode , dir_fd = dir_fd ) ) as f : <EOL> os . utime ( f . fileno ( ) if os . utime in os . supports_fd else getPath ( fname ) , dir_fd = None if os . supports_fd else dir_fd , ** kwargs ) <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def checkPath ( path ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if os . path . exists ( getPath ( path ) ) == False : <EOL> UI . logDebug ( "<STR_LIT>" + getPath ( path ) ) <EOL> os . makedirs ( getPath ( path ) ) <EOL> UI . logExiting ( ) <EOL> return getPath ( path ) <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def isPath ( path ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if os . path . exists ( getPath ( path ) ) == False : <EOL> return False <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def getPath ( path ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> p = os . path . join ( os . getcwd ( ) , path . strip ( '<STR_LIT:/>' ) ) <EOL> UI . logDebug ( "<STR_LIT>" + path + "<STR_LIT>" + p ) <EOL> UI . logExiting ( ) <EOL> return p <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def checkFile ( file ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if os . path . isfile ( file ) : <EOL> UI . logDebug ( file + "<STR_LIT>" ) <EOL> return True <EOL> else : <EOL> UI . logDebug ( file + "<STR_LIT>" ) <EOL> return False <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def appendFile ( file , lines ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> with open ( file , "<STR_LIT:a>" ) as f : <EOL> for line in lines : <EOL> UI . logDebug ( file + "<STR_LIT>" + line ) <EOL> f . write ( line + "<STR_LIT:\n>" ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def readArmStrapConfig ( ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> config = readConfig ( src = "<STR_LIT>" ) <EOL> if config == False : <EOL> config = configparser . ConfigParser ( ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> if getConfigSection ( config , '<STR_LIT>' ) != False : <EOL> if getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) == "<STR_LIT>" : <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> else : <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> else : <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT::>' . join ( map ( lambda x : "<STR_LIT>" % x , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , random . randint ( <NUM_LIT> , <NUM_LIT> ) , random . randint ( <NUM_LIT> , <NUM_LIT> ) , random . randint ( <NUM_LIT> , <NUM_LIT> ) ] ) ) ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> if getConfigSection ( config , '<STR_LIT>' ) != False : <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> getConfigValue ( config , "<STR_LIT>" , '<STR_LIT>' , "<STR_LIT:2>" ) <EOL> getConfigValue ( config , "<STR_LIT>" , '<STR_LIT>' , "<STR_LIT>" ) <EOL> if getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' ) == False : <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> else : <EOL> getConfigValue ( config , '<STR_LIT>' , '<STR_LIT>' , "<STR_LIT>" ) <EOL> with open ( getPath ( "<STR_LIT>" ) , '<STR_LIT:w>' ) as configfile : <EOL> config . write ( configfile ) <EOL> UI . logExiting ( ) <EOL> return config <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def readConfig ( src ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if checkFile ( src ) : <EOL> UI . logDebug ( "<STR_LIT>" + getPath ( src ) ) <EOL> config = configparser . ConfigParser ( ) <EOL> config . sections ( ) <EOL> config . read ( getPath ( src ) ) <EOL> else : <EOL> UI . logDebug ( "<STR_LIT>" + getPath ( src ) + "<STR_LIT>" ) <EOL> config = False <EOL> UI . logExiting ( ) <EOL> return config <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def getConfigSection ( config , section ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if isinstance ( config , configparser . ConfigParser ) : <EOL> if config . has_section ( section ) : <EOL> UI . logDebug ( section + "<STR_LIT>" ) <EOL> UI . logExiting ( ) <EOL> return config [ section ] <EOL> elif isinstance ( config , dict ) : <EOL> if section in config : <EOL> UI . logDebug ( section + "<STR_LIT>" ) <EOL> UI . logExiting ( ) <EOL> return config [ section ] <EOL> UI . logDebug ( "<STR_LIT>" + section + "<STR_LIT>" ) <EOL> UI . logExiting ( ) <EOL> return False <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def getConfigValue ( config , section , key , defaultValue = False ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if isinstance ( config , configparser . ConfigParser ) : <EOL> if config . has_section ( section ) : <EOL> if config . has_option ( section , key ) : <EOL> UI . logDebug ( "<STR_LIT>" + key + "<STR_LIT>" + section ) <EOL> UI . logExiting ( ) <EOL> return config [ section ] [ key ] <EOL> else : <EOL> UI . logDebug ( "<STR_LIT>" + key + "<STR_LIT>" + section ) <EOL> if defaultValue != False : <EOL> setConfigValue ( config = config , section = section , key = key , value = defaultValue ) <EOL> UI . logExiting ( ) <EOL> return config [ section ] [ key ] <EOL> else : <EOL> UI . logDebug ( section + "<STR_LIT>" ) <EOL> if defaultValue != False : <EOL> setConfigValue ( config = config , section = section , key = key , value = defaultValue ) <EOL> UI . logExiting ( ) <EOL> return config [ section ] [ key ] <EOL> return False <EOL> elif isinstance ( config , dict ) : <EOL> if section in config : <EOL> if key in config [ section ] : <EOL> UI . logDebug ( "<STR_LIT>" + key + "<STR_LIT>" + section ) <EOL> UI . logExiting ( ) <EOL> return config [ section ] [ key ] <EOL> else : <EOL> UI . logDebug ( "<STR_LIT>" + key + "<STR_LIT>" + section ) <EOL> if defaultValue != False : <EOL> setConfigValue ( config = config , section = section , key = key , value = defaultValue ) <EOL> UI . logExiting ( ) <EOL> return config [ section ] [ key ] <EOL> else : <EOL> UI . logDebug ( section + "<STR_LIT>" ) <EOL> if defaultValue != False : <EOL> setConfigValue ( config = config , section = section , key = key , value = defaultValue ) <EOL> UI . logExiting ( ) <EOL> return config [ section ] [ key ] <EOL> return False <EOL> else : <EOL> UI . logDebug ( "<STR_LIT>" ) <EOL> UI . logExiting ( ) <EOL> return False <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def setConfigValue ( config , section , key , value ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if isinstance ( config , configparser . ConfigParser ) : <EOL> if not config . has_section ( section ) : <EOL> UI . logDebug ( "<STR_LIT>" + section ) <EOL> config [ section ] = { } <EOL> if not config . has_option ( section , key ) : <EOL> UI . logDebug ( "<STR_LIT>" + key + "<STR_LIT>" + value + "<STR_LIT>" + section ) <EOL> config [ section ] [ key ] = value <EOL> elif isinstance ( config , dict ) : <EOL> if not section in config : <EOL> UI . logDebug ( "<STR_LIT>" + section ) <EOL> config [ section ] = { } <EOL> if not key in config [ section ] : <EOL> UI . logDebug ( "<STR_LIT>" + key + "<STR_LIT>" + value + "<STR_LIT>" + section ) <EOL> config [ section ] [ key ] = value <EOL> else : <EOL> UI . logExiting ( ) <EOL> return False <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def captureCommand ( command ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> UI . logDebug ( "<STR_LIT>" + command ) <EOL> p = subprocess . Popen ( command , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> ( cmd_stdout_bytes , cmd_stderr_bytes ) = p . communicate ( ) <EOL> UI . logExiting ( ) <EOL> return ( str ( cmd_stdout_bytes . decode ( '<STR_LIT:utf-8>' ) ) , str ( cmd_stderr_bytes . decode ( '<STR_LIT:utf-8>' ) ) ) <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def captureChrootCommand ( command ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> UI . logDebug ( "<STR_LIT>" + command + "<STR_LIT>" ) <EOL> p = subprocess . Popen ( "<STR_LIT>" + getPath ( "<STR_LIT>" ) + "<STR_LIT:U+0020>" + command , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) <EOL> ( cmd_stdout_bytes , cmd_stderr_bytes ) = p . communicate ( ) <EOL> UI . logExiting ( ) <EOL> return ( str ( cmd_stdout_bytes . decode ( '<STR_LIT:utf-8>' ) ) , str ( cmd_stderr_bytes . decode ( '<STR_LIT:utf-8>' ) ) ) <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def runCommand ( command ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> UI . logDebug ( "<STR_LIT>" + command ) <EOL> err = os . system ( command + "<STR_LIT>" ) <EOL> UI . logDebug ( "<STR_LIT>" + str ( err ) + "<STR_LIT:U+002CU+0020>" + os . strerror ( err ) ) <EOL> if err != os . EX_OK : <EOL> Exit ( text = "<STR_LIT>" + command + "<STR_LIT>" + str ( err ) + "<STR_LIT:U+002CU+0020>" + os . strerror ( err ) , title = "<STR_LIT>" , timeout = <NUM_LIT:5> , exitStatus = err ) <EOL> UI . logExiting ( ) <EOL> return err <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def runChrootCommand ( command ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> UI . logDebug ( "<STR_LIT>" + command + "<STR_LIT>" ) <EOL> err = os . system ( "<STR_LIT>" + getPath ( "<STR_LIT>" ) + "<STR_LIT:U+0020>" + command + "<STR_LIT>" ) <EOL> if err != os . EX_OK : <EOL> UI . logWarning ( "<STR_LIT>" + command + "<STR_LIT>" + str ( err ) + "<STR_LIT:U+002CU+0020>" + os . strerror ( err ) ) <EOL> raise OSError <EOL> UI . logExiting ( ) <EOL> return err <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def runChrootAptGet ( command , arguments = False ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> if ( arguments != False ) : <EOL> UI . logDebug ( "<STR_LIT>" + command + "<STR_LIT:U+0020>" + "<STR_LIT:U+0020>" . join ( arguments ) ) <EOL> UI . chrootProgressBox ( cmd = "<STR_LIT>" + command + "<STR_LIT:U+0020>" + "<STR_LIT:U+0020>" . join ( arguments ) , path = getPath ( "<STR_LIT>" ) , title = "<STR_LIT>" + command ) <EOL> else : <EOL> UI . logDebug ( "<STR_LIT>" + command ) <EOL> UI . chrootProgressBox ( cmd = "<STR_LIT>" + command , path = getPath ( "<STR_LIT>" ) , title = "<STR_LIT>" + command ) <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def loadJson ( type , args = False ) : <EOL> try : <EOL> if args == False : <EOL> url = builtins . urlInfo [ '<STR_LIT>' ] + "<STR_LIT:/>" + builtins . urlInfo [ '<STR_LIT>' ] + "<STR_LIT>" + type <EOL> else : <EOL> url = builtins . urlInfo [ '<STR_LIT>' ] + "<STR_LIT:/>" + builtins . urlInfo [ '<STR_LIT>' ] + "<STR_LIT>" + type + "<STR_LIT:&>" + "<STR_LIT:&>" . join ( args ) <EOL> UI . logDebug ( "<STR_LIT>" + url ) <EOL> return ( requests . get ( url ) . json ( ) ) <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def copyFiles ( src , dst ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> UI . logDebug ( "<STR_LIT>" + src + "<STR_LIT>" + dst ) <EOL> shutil . copy ( src , dst ) <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def listKernels ( ) : <EOL> try : <EOL> kFormat = "<STR_LIT>" <EOL> print ( "<STR_LIT>" ) <EOL> print ( kFormat . format ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> print ( kFormat . format ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> Kernels = loadJson ( type = "<STR_LIT>" , args = "<STR_LIT>" . split ( ) ) <EOL> for section in sorted ( Kernels ) : <EOL> print ( kFormat . format ( section , Kernels [ section ] [ '<STR_LIT>' ] , "<STR_LIT:U+0020>" . join ( Kernels [ section ] [ '<STR_LIT>' ] ) ) ) <EOL> print ( "<STR_LIT>" ) <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def listRootFS ( ) : <EOL> try : <EOL> rFormat = "<STR_LIT>" <EOL> print ( "<STR_LIT>" ) <EOL> print ( rFormat . format ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> print ( rFormat . format ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> rootFSList = loadJson ( type = "<STR_LIT>" ) <EOL> for arch in sorted ( rootFSList ) : <EOL> for family in sorted ( rootFSList [ arch ] ) : <EOL> print ( rFormat . format ( family , arch , "<STR_LIT:U+002CU+0020>" . join ( sorted ( list ( rootFSList [ arch ] [ family ] . keys ( ) ) ) ) ) ) <EOL> print ( "<STR_LIT>" ) <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def listBoards ( ) : <EOL> try : <EOL> bFormat = "<STR_LIT>" <EOL> print ( "<STR_LIT>" ) <EOL> print ( bFormat . format ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> print ( bFormat . format ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> armStrapCfg = loadJson ( type = "<STR_LIT>" , args = ( "<STR_LIT>" . split ( ) ) ) <EOL> for type in sorted ( armStrapCfg [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) : <EOL> boardsCfg = loadJson ( type = "<STR_LIT>" , args = ( "<STR_LIT>" + type ) . split ( ) ) <EOL> for model in boardsCfg [ '<STR_LIT>' ] [ '<STR_LIT>' ] : <EOL> print ( bFormat . format ( model , boardsCfg [ '<STR_LIT>' ] [ '<STR_LIT>' ] + boardsCfg [ '<STR_LIT>' ] [ '<STR_LIT>' ] , boardsCfg [ model ] [ '<STR_LIT>' ] ) ) <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_SOFTWARE ) <EOL> def mountPartitions ( Device , partList ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> order = <NUM_LIT:1> <EOL> sortedList = [ ] <EOL> builtins . Status . update ( name = "<STR_LIT>" , value = "<STR_LIT>" ) <EOL> while len ( sortedList ) != len ( partList ) : <EOL> for p in partList : <EOL> if int ( p [ '<STR_LIT>' ] ) == order : <EOL> order += <NUM_LIT:1> <EOL> sortedList . append ( { '<STR_LIT>' : p [ '<STR_LIT>' ] , '<STR_LIT>' : p [ '<STR_LIT>' ] } ) <EOL> for p in sortedList : <EOL> d = checkPath ( "<STR_LIT>" + p [ '<STR_LIT>' ] . strip ( '<STR_LIT:/>' ) ) <EOL> builtins . Status . update ( text = "<STR_LIT>" + p [ '<STR_LIT>' ] + "<STR_LIT>" + d , percent = builtins . Status . getPercent ( ) ) <EOL> runCommand ( command = "<STR_LIT>" + p [ '<STR_LIT>' ] + "<STR_LIT:U+0020>" + d ) <EOL> UI . logExiting ( ) <EOL> return sortedList <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> sys . exit ( os . EX_IOERR ) <EOL> def unmountPartitions ( ) : <EOL> try : <EOL> UI . logEntering ( ) <EOL> for p in builtins . partList [ : : - <NUM_LIT:1> ] : <EOL> d = checkPath ( "<STR_LIT>" + p [ '<STR_LIT>' ] . strip ( '<STR_LIT:/>' ) ) <EOL> if builtins . Status != False : <EOL> builtins . Status . update ( text = "<STR_LIT>" + p [ '<STR_LIT>' ] + "<STR_LIT>" + d , percent = builtins . Status . getPercent ( ) ) <EOL> runCommand ( command = "<STR_LIT>" + d ) <EOL> if builtins . Device . find ( "<STR_LIT>" ) != - <NUM_LIT:1> : <EOL> runCommand ( command = "<STR_LIT>" + builtins . Device ) <EOL> UI . logExiting ( ) <EOL> return True <EOL> except SystemExit : <EOL> pass <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> pass <EOL> def Exit ( text = "<STR_LIT>" , title = "<STR_LIT>" , timeout = <NUM_LIT:0> , exitStatus = os . EX_OK ) : <EOL> try : <EOL> UI . logDebug ( "<STR_LIT>" ) <EOL> mp = getPath ( "<STR_LIT>" ) <EOL> mountList = [ ] <EOL> with open ( "<STR_LIT>" , "<STR_LIT:r>" ) as f : <EOL> for mount in f . readlines ( ) : <EOL> if mount . find ( mp ) != - <NUM_LIT:1> : <EOL> mountList . append ( mount . split ( ) [ <NUM_LIT:1> ] ) <EOL> for mount in sorted ( mountList , reverse = True ) : <EOL> os . system ( "<STR_LIT>" + mount + "<STR_LIT>" ) <EOL> if builtins . Status != False : <EOL> builtins . Status . end ( ) <EOL> builtins . Dialog . pause ( text = text , title = title , seconds = timeout , backtitle = builtins . Header ) <EOL> logging . shutdown ( ) <EOL> logFile = os . path . join ( os . getcwd ( ) , "<STR_LIT>" ) <EOL> if os . path . isfile ( logFile ) : <EOL> if os . stat ( logFile ) . st_size == <NUM_LIT:0> : <EOL> os . unlink ( logFile ) <EOL> os . _exit ( exitStatus ) <EOL> except : <EOL> logging . exception ( "<STR_LIT>" ) <EOL> os . _exit ( exitStatus ) </s>
