示例#1
0
def cleanup(mountpoint, tc_mountpoint, tempdir, value_from_argparser):
    try:
        cleanupLogger = ParaLogger('cleanup')
        parser = configtransport()

        #
        # Unmounting Truecrypt
        #
        try:
            if os.path.exists(tc_mountpoint) and os.path.ismount(tc_mountpoint):
                cleanupLogger.info("Unmounting Truecrypt Container")
                cleanupLogger.debug('UNMOUNT COMMAND: ' + parser.get('truecrypting', 'unmount'))
                subprocess.check_call(shlex.split(parser.get('truecrypting', 'unmount')))

        except OSError:
            cleanupLogger.error("Could not unmount tc container on {}").format(tc_mountpoint)
            cleanupLogger.exception("Could not unmount tc container on {}").format(tc_mountpoint)

        #
        # Unmounting USB-Stick
        #

        try:
            if value_from_argparser and os.path.exists(mountpoint) and os.path.ismount(mountpoint) is True:
                cleanupLogger.info("Unmounting USB-Stick")
                if (sys.platform == "darwin"):
                    subprocess.check_call(['diskutil', 'eject', mountpoint])
                else:
                    subprocess.check_call(["umount", mountpoint])
        except OSError:
            cleanupLogger.error("Could not umount {}").format(mountpoint)
            cleanupLogger.exception("Could not umount {}").format(mountpoint)

        #
        # Removing Temporary Directories
        #

        cleanupLogger.info("Cleaning up Temporary Directories")

        try:
            if value_from_argparser and os.path.exists(mountpoint) and os.path.ismount(mountpoint) is False:
                shutil.rmtree(mountpoint)
            if os.path.exists(tc_mountpoint) and os.path.ismount(tc_mountpoint) is False:
                shutil.rmtree(tc_mountpoint)
            if (sys.platform == "darwin") and os.path.exists(tempdir+"/dmg") and os.path.ismount(tempdir+"/dmg"):
                subprocess.check_call(['diskutil', 'eject', os.path.join(tempdir+"/dmg/")])
            elif os.path.exists(tempdir+"/dmg") and os.path.ismount(tempdir+"/dmg"):
                subprocess.check_call(['umount', os.path.join(tempdir+"/dmg/")])
            if os.path.exists(tempdir):
                shutil.rmtree(tempdir)
        except OSError:
            cleanupLogger.error("Some temporary Directories could not be removed")
            cleanupLogger.exception("Some temporary Directories could not be removed")

    except KeyboardInterrupt:
        cleanupLogger.error("You've hit Strg+C for interrupting Parabird. Now clean up your own mess. Exiting...")
        sys.exit()
示例#2
0
import zipfile
import subprocess
import sys
import os
import tempfile
import shlex
import shutil
import requests
import plistlib
import glob
from xml.dom import minidom
#from utils import *
from utils import ParaLogger


extractLogger = ParaLogger('extract')


def extract_tarfile(progname, filename, path):
    try:
        extractLogger.debug("Extracting {}" .format(progname))
        try:
            tar = tarfile.open(filename)
            tar.extractall(path)
            tar.close()
        except:
            extractLogger.error("[ERROR] Could not extract {}. exiting " .format(progname))
            extractLogger.exception("[ERROR] Could not extract {}. exiting " .format(progname))
            sys.exit()
    except KeyboardInterrupt:
        extractLogger.error("You've hit Strg+C for interrupting Parabird. Now clean up your own mess. Exiting...")
示例#3
0
    #getting the config
    #

    parser = configtransport()

    #
    # Creation of tempdirs.
    #

    tempdir = os.path.realpath(tempfile.mkdtemp())
    parser.set('DEFAULT', 'tempdir', tempdir)

    tc_mountpoint = os.path.realpath(tempfile.mkdtemp())
    logfile = os.path.realpath(tempdir + "/" + "parabirdy_log.txt")

    mainLogger = ParaLogger('main')

    #
    # Configuring Commandline Arguments and Config
    #

    # Parsing Arguments given as Parameter from Shell
    clparser = argparse.ArgumentParser()
    clparser = argparse.ArgumentParser(description='')
    clparser.add_argument("-v",
                          "--verbose",
                          help="increase output verbosity",
                          action="store_true")
    clparser.add_argument("-c",
                          "--cache",
                          help="use a cache in ~/.parabirdy/cache",