#!/usr/bin/env python
import subprocess
import os
import sys
try:
    import ConfigParser as configparser  # Python2
except ImportError:
    import configparser

    import device_inventory

def load_config():
    # https://docs.python.org/3.4/library/configparser.html
    path = os.path.dirname(__file__)
    config_file = os.path.join(path, 'config.ini')
    assert os.path.exists(config_file), config_file

    config = configparser.ConfigParser()
    config.read(config_file)  # donator.cfg merged here
    
    #print(config['DEFAULT']['DISC'])
    #print(config['DEFAULT'].getboolean('DISC'))
    #print(config['donator']['email'])
    
    # TODO set fallback values if config is empty
    # https://docs.python.org/3.4/library/configparser.html#fallback-values
    
    return config

def get_hdinfo(path,value):
    return subprocess.Popen(["lsblk",path,"--nodeps","-no",value], stdout=subprocess.PIPE)

def get_user_input(sdx_path):
    size = get_hdinfo(sdx_path,"size").stdout.read()
    model = get_hdinfo(sdx_path,"model").stdout.read()
    disk = get_hdinfo(sdx_path,"tran").stdout.read()
    print "Selected %s (Model: %s) (Size:%s) (Type: %s)." % (sdx_path,model.rstrip(" \n"),size.rstrip(" \n"),disk.rstrip(" \n"))
    config_erase = raw_input("Do you want to erase \"{0}\"? [y/N] ".format(sdx_path))
    return config_erase

def erasetor(dev, steps="0"):
     try:
         subprocess.call(["shred","-zvn",steps,dev])
     except ValueError:
         print "Cannot erase the hard drive '{0}'".format(dev)
        

def do_erasure(sdx):
    config = load_config()
    erase = config.get('DEFAULT', 'ERASE')

    if erase == "yes":
        print erasetor(sdx)
    elif erase == "ask":
        erase = get_user_input(sdx)
        if erase.lower().strip() == "y" or erase.lower().strip() == "yes":
            print erasetor(sdx)

def main(argv=None):
    device = sys.argv[1]
    do_erasure(device)

if __name__ == "__main__":
# checking priveleges
    if os.geteuid() !=  0:
        sys.exit("Must be root to erase data.")

    try:
        arg_var = sys.argv[1]
    except IndexError:
        exit("No devices selected.")

    if len(arg_var) < 7:
        exit("Device not valid.")
        
    # Start
    if os.path.exists(arg_var):
        sys.exit(main(sys.argv))
    else:
        exit("Device does not exit.")

@@ -50,19 +50,61 @@
 %0Aimport 
-sys
+time%0Aimport sys%0Afrom datetime import datetime
 %0Atry:%0A  
@@ -953,30 +953,29 @@
 E)%0A%0Adef 
-get_user_input
+show_selected
 (sdx_pat
@@ -1267,16 +1267,75 @@
 (%22 %5Cn%22))
+%0A%0Adef get_user_input(sdx_path):%0A    show_selected(sdx_path)
 %0A    con
@@ -1460,178 +1460,833 @@
 ev, 
-steps=%220%22)
+erase_mode=%220%22):%0A    if erase_mode == %220%22:%0A        standard = %22All zeros, lower Standard%22%0A        step = %220%22%0A    elif erase_mode == %221%22
 :%0A     
+ 
-try:%0A         subprocess.call(%5B%22shred%22,%22-zvn%22,steps,dev%5D)%0A     except ValueError:%0A         print %22Cannot erase the hard drive '%7B0%7D'%22.format(dev)%0A        
+  standard = %22Sector by sector, high Standard%22%0A    time_start = time.strftime(%22%25Y-%25m-%25d %25H:%25M:%25S%22)%0A    FMT = %22%25Y-%25m-%25d %25H:%25M:%25S%22%0A    try:%0A         #subprocess.call(%5B%22shred%22,%22-zvn%22,steps,dev%5D)%0A         state = %22Successful%22%0A         time_end = time.strftime(%22%25Y-%25m-%25d %25H:%25M:%25S%22)%0A    except ValueError:%0A        state = %22With errors.%22%0A        print %22Cannot erase the hard drive '%7B0%7D'%22.format(dev)%0A    elapsed = datetime.strptime(time_end, FMT) - datetime.strptime(time_start, FMT)%0A    dict = %7B'erasure_standard_name': standard,%0A            'state': state,%0A            'elapsed_time': str(elapsed),%0A            'start_time': time_start,%0A            'end_time': time_end %7D%0A    return dict
 %0A%0Ade
@@ -2390,32 +2390,64 @@
 erase == %22yes%22:%0A
+        show_selected(sdx_path)%0A
         print er
@@ -2598,37 +2598,38 @@
 s%22:%0A            
-print
+return
  erasetor(sdx)%0A%0A
@@ -2678,16 +2678,22 @@
 %5B1%5D%0A    
+print 
 do_erasu
@@ -2702,16 +2702,21 @@
 (device)
+%0A    
 %0A%0Aif __n

Output log