Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 58239 Details for
Bug 91761
Various patches to clean up GLIStorageDevice, GLIUtility, and SimpleXMLParser.
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
GLIUtility.py.patch
GLIUtility.py.patch (text/plain), 9.27 KB, created by
Christopher Hotchkiss
on 2005-05-06 20:41:29 UTC
(
hide
)
Description:
GLIUtility.py.patch
Filename:
MIME Type:
Creator:
Christopher Hotchkiss
Created:
2005-05-06 20:41:29 UTC
Size:
9.27 KB
patch
obsolete
>Index: GLIUtility.py >=================================================================== >RCS file: /var/cvsroot/gentoo/src/installer/src/GLIUtility.py,v >retrieving revision 1.48 >diff -a -u -r1.48 GLIUtility.py >--- GLIUtility.py 14 Apr 2005 15:44:03 -0000 1.48 >+++ GLIUtility.py 7 May 2005 03:36:21 -0000 >@@ -6,7 +6,7 @@ > The GLIUtility module contians all utility functions used throughout GLI. > """ > >-import string, os, re, signal, time, shutil, sys, random, commands, crypt >+import string, os, re, shutil, random, commands, crypt > from GLIException import * > > ## >@@ -209,7 +209,7 @@ > # @param input Parameter description > def strtobool(input): > if type(input) != str: >- raise GLIException("InputError", 'fatal','strtobool',"The input must be a string!") >+ raise GLIException("GLIUtilityError", 'fatal','strtobool',"The input must be a string!") > > if string.lower(input) == 'true': > return True >@@ -227,13 +227,17 @@ > return False > > # Create a regular expression to test the specified device. >- expr = re.compile('^(eth|wlan|ppp)([0-9]{1,2})(:[0-9]{1,2})?$') >+# expr = re.compile('^(eth|wlan|ppp)([0-9]{1,2})(:[0-9]{1,2})?$') > > # Run the match >- res = expr.match(device) >- >+# res = expr.match(device) >+ >+# if res != None: >+ status, output = spawn("/sbin/ifconfig -a | grep -e '^[A-Za-z]'| cut -d ' ' -f 1 | grep '"+ device + "'", return_output=True) >+ if output: >+ return True > # Return True only if there are results >- return(res != None) >+ return False > > ## > # Brief description of function >@@ -262,17 +266,14 @@ > # @param netmask Parameter description > def set_ip(dev, ip, broadcast, netmask): > if not is_ip(ip) or not is_ip(netmask) or not is_ip(broadcast): >- raise GLIException("IPAddressError", 'fatal','set_ip', "ip, netmask and broadcast must be a valid IP's!") >+ raise GLIException("GLIUtilityError", 'fatal','set_ip', ip + ", " + netmask + "and, " + broadcast + "must be a valid IP's!") > > if not is_eth_device(dev): >- raise GLIException("EthDeviceError", 'fatal','set_ip',"dev must be a valid ethernet device!") >+ raise GLIException("GLIUtilityError", 'fatal','set_ip', dev + "is not a valid ethernet device!") > > options = "%s inet %s broadcast %s netmask %s" % (dev, ip, broadcast, netmask) > >- status = spawn("ifconfig " + options, quiet=True) >- >- if not exitsuccess(status): >- return False >+ spawn("ifconfig " + options, quiet=True) > > return True > >@@ -281,12 +282,9 @@ > # @param route Parameter description > def set_default_route(route): > if not is_ip(route): >- raise GLIException("IPAddressError", 'fatal', 'set_default_route', "The default route must be an IP address!") >+ raise GLIException("GLIUtilityError", 'fatal', 'set_default_route', route + " is not an ip address!") > >- status = spawn("route add default gw " + route, quiet=True) >- >- if not exitsuccess(status): >- return False >+ spawn("route add default gw " + route, quiet=True) > > return True > >@@ -320,6 +318,10 @@ > > # print "Running command: " + cmd > ret, output = commands.getstatusoutput(cmd) >+ >+ if not os.WIFEXITED(ret) and os.WEXITSTATUS(ret) == 0: >+ #raise GLIException('GLIExceptionError', 'fatal', 'spawn', "WIFEXITED = " + str(os.WIFEXITED(ret)) + ", WEXITSTATUS = " + str(os.WEXITSTATUS(ret))) >+ raise GLIException('GLIUtilityError', 'fatal', 'spawn', "Process exited abnormally while trying to run " + cmd + " with status of " + ret + " and output of " + output) > if return_output: > return ret, output > else: >@@ -327,17 +329,10 @@ > > ## > # Brief description of function >-# @param status Parameter description >-def exitsuccess(status): >- if os.WIFEXITED(status) and os.WEXITSTATUS(status) == 0: >- return True >- print "WIFEXITED = " + str(os.WIFEXITED(status)) + ", WEXITSTATUS = " + str(os.WEXITSTATUS(status)) >- >- return False >- > def spawn_bash(): > os.putenv("PROMPT_COMMAND","echo \"Type 'exit' to return to the installer.\"") >- return spawn("bash") >+ status = spawn("bash") >+ return status > > ## > # Brief description of function >@@ -345,46 +340,40 @@ > # @param path Parameter description > def get_uri(uri, path): > uri = uri.strip() >- status = 1 > > if re.match('^(ftp|http(s)?)://',uri): >- status = spawn("wget --quiet " + uri + " -O " + path) >+ spawn("wget --quiet " + uri + " -O " + path) > > elif re.match('^rsync://', uri): >- status = spawn("rsync --quiet " + uri + " " + path) >+ spawn("rsync --quiet " + uri + " " + path) >+ > > elif re.match('^file://', uri): >- file = uri[7:] >- if os.path.isfile(file): >- shutil.copy(file, path) >- if os.path.isfile(path): >- status = 0 >- else: >- status = 1 >+ r_file = uri[7:] >+ if os.path.isfile(r_file): >+ shutil.copy(r_file, path) >+ if not os.path.isfile(path): >+ raise GLIException("GLIUtilityError", 'fatal', 'get_uri', "Cannot copy " + r_file + " to " + path) > else: > # Just in case a person forgets file:// > if os.path.isfile(uri): > shutil.copy(uri, path) >- if os.path.isfile(path): >- status = 0 >- else: >- status = 1 >+ if not os.path.isfile(path): >+ raise GLIException("GLIUtilityError", 'fatal', 'get_uri', "Cannot copy " + uri + " to " + path) > else: >- print "I don't know how to download/copy that profile!" >- >- if exitsuccess(status): >- return True >- >- return False >+ raise GLIException("GLIUtilityError", 'fatal', 'get_uri', "I don't know how to handle " + uri + " or " + path + " that!") > > ## > # Brief description of function > # @param host Parameter description > def ping(host): >- host = str(host) >- status = spawn("ping -n -c 3 " + host,quiet=True) >- if not exitsuccess(status): >+ if not (is_hostname(host) or is_ip(host)): >+ raise GLIException("GLIUtilityError", 'fatal', 'ping', host + " is not a valid hostname or ip!") >+ try: >+ spawn("ping -n -c 3 " + host,quiet=True) >+ except: > return False >+ > return True > > ## >@@ -396,37 +385,38 @@ > Order is hw_addr, ip_addr, mask, bcast, route, and > whether it's up (True or False). > """ >- device = str(device) >- if device: >- hw_addr = 'None' >- ip_addr = 'None' >- mask = 'None' >- bcast = 'None' >- gw = 'None' >- up = False >- device_info = commands.getstatusoutput("ifconfig eth" + device) >- if device_info[0] == 0: >- for line in device_info[1].splitlines(): >- line = line.strip() >- if 'HWaddr' in line: >- hw_addr = line.split('HWaddr',1)[1].strip() >- if 'inet addr' in line: >- ip_addr = line.split(' ')[0].split(':')[1] >- if 'Bcast' in line: >- bcast = line.split(' ')[1].split(':')[1] >- if 'Mask' in line: >- mask = line.split(' ')[2].split(':')[1] >- if line.startswith('UP'): >- up = True >- else: return (device_info[0], device_info[1]) >- route_info = commands.getstatusoutput("netstat -nr") >- if route_info[0] == 0: >- for line in route_info[1].splitlines(): >- if line.startswith('0.0.0.0'): >- gw = line.split('0.0.0.0')[1].strip() >- else: return (route_info[0], route_info[1]) >- return (hw_addr, ip_addr, mask, bcast, gw, up) >- else: return False >+ hw_addr = 'None' >+ ip_addr = 'None' >+ mask = 'None' >+ bcast = 'None' >+ gw = 'None' >+ up = False >+ >+ if not is_eth_device("eth" + str(device)): >+ raise GLIException("GLIUtilityError", 'fatal', "get_eth_info", "eth" + str(device) +" is not a valid ethernet device!") >+ >+ status, device_info = spawn("/sbin/ifconfig eth" + str(device), return_output=True) >+ if status==0: >+ for line in device_info.splitlines(): >+ line = line.strip() >+ if 'HWaddr' in line: >+ hw_addr = line.split('HWaddr',1)[1].strip() >+ if 'inet addr' in line: >+ ip_addr = line.split(' ')[0].split(':')[1] >+ if 'Bcast' in line: >+ bcast = line.split(' ')[1].split(':')[1] >+ if 'Mask' in line: >+ mask = line.split(' ')[2].split(':')[1] >+ if line.startswith('UP'): >+ up = True >+ else: >+ raise GLIException("GLIUtilityError", 'fatal', "get_eth_info", device_info) >+ status, route_info = spawn("netstat -nr", return_output=True) >+ for line in route_info[1].splitlines(): >+ if line.startswith('0.0.0.0'): >+ gw = line.split('0.0.0.0')[1].strip() >+ >+ return (hw_addr, ip_addr, mask, bcast, gw, up) > > ## > # Brief description of function >@@ -459,12 +449,13 @@ > tar_options = tar_options + "p" > > # Unpack the tarball >- exitstatus = spawn("tar -" + tar_options + " -f " + temp_directory + "/" + tarball_filename + " -C " + target_directory, display_on_tty8=True, logfile="/tmp/compile_output.log", append_log=True) # change this to the logfile variable >- >- if not exitsuccess(exitstatus): >- raise GLIException("UnpackTarballError", 'fatal', 'fetch_and_unpack_tarball',"Could not unpack tarball!") >- >+ try: >+ spawn("tar -" + tar_options + " -f " + temp_directory + "/" + tarball_filename + " -C " + target_directory, display_on_tty8=True, logfile="/tmp/compile_output.log", append_log=True) # change this to the logfile variable >+ except: >+ raise GLIException("GLIUtilityError", 'fatal', 'fetch_and_unpack_tarball',"Could not unpack " + tarball_uri + " to " + target_directory) > >+## >+# Brief description of function > def generate_random_password(): > s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$%^&*[]{}-=+_,|'\"<>:/" > s = list(s) >@@ -487,7 +478,8 @@ > # @param filename Parameter description > # @param value Parameter description > def get_value_from_config(filename, value): >- return string.strip(commands.getoutput("source " + filename + " && echo $" + value)) >+ status, output = spawn("source " + filename + " && echo $" + value, return_output=True) >+ return string.strip(output) > > ## > # Brief description of function
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 91761
:
58238
| 58239 |
58240