Changeset 16313


Ignore:
Timestamp:
Jul 15, 2016, 5:21:59 PM (3 years ago)
Author:
dcorreia
Message:

Added debug messages, docstrings and tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • internals/2016/linuxloginsmartcardwizard/trunk/project1/configpart1.py

    r16312 r16313  
    1313    Installs package using apt-get
    1414    :param packageName: name of the package
    15     :return: True if package is installed and False otherwise
     15    :return: True if package was installed with success and False otherwise
    1616    '''
    1717    if not hasPackage(packageName):
    1818        # install package
    19         print("DEBUG: need to install", packageName, file=sys.stderr)
     19        print("DEBUG: installPackage - need to install", packageName, file=sys.stderr)
    2020        command = "apt-get install " + packageName
    2121        try:
    22             subprocess.check_call(command, shell=True, stdout=open(os.devnull, "wb"), stderr=sys.stdout)
     22            proc = subprocess.Popen(command, shell=True, stdout=open(os.devnull, "wb"), stderr=subprocess.PIPE)
     23            print("DEBUG: installPackage - ", proc.stderr.read(), file=sys.stderr)
     24
    2325        except subprocess.CalledProcessError as error:
    24             print("DEBUG: ", error, file=sys.stderr)
    25         else:
    26             print("DEBUG:", packageName, "installed", file=sys.stderr)
    27 
     26            print("DEBUG: installPackage - ", error, file=sys.stderr)
     27    return hasPackage(packageName)
    2828
    2929def hasPackage(packageName):
     
    3434    '''
    3535    command = "dpkg -s " + packageName
    36     proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
     36    proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     37    print("DEBUG: hasPackage - ", proc.stderr.read(), file=sys.stderr)
    3738    try:
    38         subprocess.check_output("grep Status", shell=True, stdin=proc.stdout)
     39        subprocess.check_output("grep Status", shell=True, stdin=proc.stdout, stderr=sys.stdout)
    3940    except subprocess.CalledProcessError as error:
    40         print("DEBUG:", error, file=sys.stderr)
     41        print("DEBUG: hasPackage - ", error.output, file=sys.stderr)
    4142        return False
    4243    else:
    4344        return True
    4445
    45 
    46 installPackage(PAMPKCS11_PACKAGE)
    47 installPackage("hello1")
     46# Tests for package installation module
     47if installPackage(PAMPKCS11_PACKAGE):
     48    print("Package", PAMPKCS11_PACKAGE, "is installed")
     49if installPackage("hello1"):
     50    print("Package", "hello1", "is installed")
     51else:
     52    print("Failed to install package", "hello1")
    4853
    4954# TODO Create directories to support configuration files
Note: See TracChangeset for help on using the changeset viewer.