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()
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()
def cleanup(mountpoint, tc_mountpoint, tempdir): mainLogger=ParaLogger('main') parser = configtransport() clparser = argparse.ArgumentParser() clparser = argparse.ArgumentParser(description='') clparser.add_argument("-d", "--device", help="Device Flag to specify USB Stick") args = clparser.parse_args() # # Unmounting Truecrypt # try: if os.path.exists(tc_mountpoint) and os.path.ismount(tc_mountpoint): mainLogger.info("Unmounting Truecrypt Container") mainLogger.debug('UNMOUNT COMMAND: ' + parser.get('truecrypting', 'unmount')) subprocess.check_call(shlex.split(parser.get('truecrypting', 'unmount'))) except OSError: mainLogger.error("Could not unmount tc container on {}").format(tc_mountpoint) mainLogger.exception("Could not unmount tc container on {}").format(tc_mountpoint) # # Unmounting USB-Stick # try: if args.device and os.path.exists(mountpoint) and os.path.ismount(mountpoint) == True: mainLogger.info("Unmounting USB-Stick") if (sys.platform == "darwin"): subprocess.check_call(['diskutil', 'eject', mountpoint]) else: subprocess.check_call(["umount", mountpoint]) except OSError: mainLogger.error("Could not umount {}").format(mountpoint) mainLogger.exception("Could not umount {}").format(mountpoint) # # Removing Temporary Directories # mainLogger.info("Cleaning up Temporary Directories") try: if args.device and os.path.exists(mountpoint) and os.path.ismount(mountpoint) == False: shutil.rmtree(mountpoint) if os.path.exists(tc_mountpoint) and os.path.ismount(tc_mountpoint) == False: shutil.rmtree(tc_mountpoint) if (sys.platform == "darwin") and if os.path.exists(tempdir+"/dmg"): subprocess.check_call(['diskutil', 'eject', os.path.join(tempdir+"/dmg/")]) else: subprocess.check_call(['umount', os.path.join(tempdir+"/dmg/")]) if os.path.exists(tempdir): shutil.rmtree(tempdir) except OSError: mainLogger.error("Some temporary Directories could not be removed") mainLogger.exception("Some temporary Directories could not be removed")
update_config("truecrypting", "size", args.container_size) print "=" * 60, "\nMounting and Truecrypting\n", "=" * 60 # # Use an USB-Stick given by a Parameter or a detected one: # if args.device: try: mountpoint = os.path.realpath(tempfile.mkdtemp()) update_config("DEFAULT", "device", args.device) except NameError: mainLogger.error("[ERROR] Hier ist was ganz arg schiefgelaufen") # FIXME: Translate mainLogger.exception("[ERROR] Hier ist was ganz arg schiefgelaufen") else: stick = detect_stick() # did autodetection work? and can we write? # if we can write to the mountpoint of the stick, no need to re-mount it if stick["mountpoint"] and (not (os.access(str(stick["mountpoint"]), os.W_OK))): # aka we cant write or stick detection did not work # question is: does it make sense to continue at this point? # which scenarios are possible (except detection not working) mountpoint = os.path.realpath(tempfile.mkdtemp()) mainLogger.error("Stick detection did not work, try to run with what you specified") mainLogger.info("Mounting USB Stick to" + mountpoint) try: subprocess.check_call(["mount", parser.get("DEFAULT", "device"), mountpoint])
update_config("truecrypting", "size", args.container_size) print "=" * 60, "\nMounting and Truecrypting\n", "=" * 60 # # Use an USB-Stick given by a Parameter or a detected one: # if args.device: try: mountpoint = os.path.realpath(tempfile.mkdtemp()) update_config("DEFAULT", "device", args.device) except NameError: mainLogger.error("[ERROR] Something went terribly wrong") mainLogger.exception("[ERROR] Something went terribly wrong") else: stick = detect_stick() #did autodetection work? and can we write? #if we can write to the mountpoint of the stick, no need to re-mount it if stick['mountpoint'] and (not(os.access(str(stick['mountpoint']), os.W_OK))): #aka we cant write or stick detection did not work #question is: does it make sense to continue at this point? #which scenarios are possible (except detection not working) mountpoint = os.path.realpath(tempfile.mkdtemp()) mainLogger.error("Stick detection did not work, try to run with what you specified") mainLogger.info('Mounting USB Stick to' + mountpoint) try: subprocess.check_call(["mount", parser.get('DEFAULT', 'device'), mountpoint])
# try: update_config("DEFAULT", "device", args.device) update_config("thunderbird_linux", "version", args.thunder) update_config("thunderbird_windows", "version", args.thunder) update_config("thunderbird_mac", "version", args.thunder) update_config("vidalia_linux", "version", args.vidalia) update_config("vidalia_windows", "version", args.vidalia) update_config("vidalia_mac", "version", args.vidalia) update_config("DEFAULT", "container_name", args.container_name) update_config("truecrypting", "size", args.container_size) except NameError: mainLogger.error("[ERROR] Hier ist was ganz arg schiefgelaufen") mainLogger.exception("[ERROR] Hier ist was ganz arg schiefgelaufen") print "=" * 60, "\nMounting and Truecrypting\n", "=" * 60 # # Use an USB-Stick given by a Parameter or a detected one: # if args.device: try: mountpoint = os.path.realpath(tempfile.mkdtemp()) update_config("DEFAULT", "device", args.device) except NameError: mainLogger.error("[ERROR] Hier ist was ganz arg schiefgelaufen") mainLogger.exception("[ERROR] Hier ist was ganz arg schiefgelaufen")
update_config("truecrypting", "size", args.container_size) print "=" * 60, "\nMounting and Truecrypting\n", "=" * 60 # # Use an USB-Stick given by a Parameter or a detected one: # if args.device: try: mountpoint = os.path.realpath(tempfile.mkdtemp()) update_config("DEFAULT", "device", args.device) except NameError: mainLogger.error("[ERROR] Something went terribly wrong") mainLogger.exception("[ERROR] Something went terribly wrong") else: stick = detect_stick() #did autodetection work? and can we write? #if we can write to the mountpoint of the stick, no need to re-mount it if stick['mountpoint'] and (not (os.access(str(stick['mountpoint']), os.W_OK))): #aka we cant write or stick detection did not work #question is: does it make sense to continue at this point? #which scenarios are possible (except detection not working) mountpoint = os.path.realpath(tempfile.mkdtemp()) mainLogger.error( "Stick detection did not work, try to run with what you specified" ) mainLogger.info('Mounting USB Stick to' + mountpoint)