#!/usr/bin/python#program: backup_v2_2.py - main module##################### IMPORTS###################import osimport sys################################################# FUNCTIONS##################################################################### SCREEN HANDLER#####################newline functiondef newline(): print '\n'#clearscreen function (CLS is Clear screen on DOS)def cls(): os.system('clear')###################### PRINTABLES##################### splash displaydef splash(a): print ''' BackupPy - a python backup script Copyright (c) 2006-2007 by Sean Wahl This Software is Placed under the MIT License see LICENSE for the full text. press enter to contine''' return a# this prints the found appsdef zeo_found(a): if a == 'a': print ' We Found tar ........................' elif a == 'b': print ' We Found zip ........................' elif a == 'c': print ' We Found bzip2 ......................' elif a == 'ab': print ' We Found tar and zip ................' elif a == 'ac': print ' We Found tar and bzip2 ..............' elif a == 'bc': print ' We Found zip and bzip2, where\'s tar?' elif a == 'abc': print ' We Found tar, zip and bzip2 .........' else: print ' NOTHING FOUND '###################### APP TESTING###################### tests each app by running themdef app_test(a, b, c): auto_menu = '' if os.system(a) == 0: auto_menu = auto_menu + 'a' elif os.system(a) == 1: auto_menu = auto_menu + x else: auto_menu = auto_menu + x if os.system(b) == 0: auto_menu = auto_menu + 'b' elif os.system(b) == 1: auto_menu = auto_menu + x else: auto_menu = auto_menu + x if os.system(c) == 0: auto_menu = auto_menu + 'c' elif os.system(c) == 1: auto_menu = auto_menu + x else: auto_menu = auto_menu + x if auto_menu == 'a': return auto_menu elif auto_menu == 'b': return auto_menu elif auto_menu == 'c': return auto_menu elif auto_menu == 'ab': return auto_menu elif auto_menu == 'ac': return auto_menu elif auto_menu == 'bc': return auto_menu elif auto_menu == 'abc': return auto_menu else: return auto_menu###################### MENUS - PRINT###################### Main Menudef menu_main(): print ''' BackupPy 1.) Backup a Directory 2.) Backup a Drive 3.) Options 4.) Quit/Exit/End/Depart '''## Menu with every selectiondef menu_all(): print ''' 1.) Make a tarball 2.) Make a zip 3.) Make a bzip'ed tarball 4.) Make a gzip'ed tarball 5.) Make a 7zip'ed tarball '''## Menu for tardef menu_tar(): print ''' 1.) Make a tarball '''## Menu for zipdef menu_zip(): print ''' 1.) Make a zip '''## Menu for zip and tardef menu_tar_zip(): print ''' 1.) Make a tarball 2.) Make a zip '''## Menu for tar and bzip2def menu_tar_bz2(): print ''' 1.) Make a tarball 2.) Make a bzip'ed tarball '''## Menu for tar and gzipdef menu_tar_gz(): print ''' 1.) Make a tarball 2.) Make a gzip'ed tarball '''## Menu for tar and 7zipdef menu_tar_lz(): print ''' 1.) Make a tarball 2.) Make a 7zip'ed tarball '''## Menu for zip and bzip2def menu_zip_bz2(): print ''' 1.) Make a zip 2.) Make a bzip'ed zipball '''## Menu for zip and gzipdef menu_zip_gz(): print ''' 1.) Make a zip 2.) Make a gzip'ed zipball '''## Menu for zip and 7zipdef menu_zip_lz(): print ''' 1.) Make a zip 2.) Make a 7zip'ed zipball '''## Menu for tar, zip and bzip2def menu_tar_zip_bz2(): print ''' 1.) Make a tarball 2.) Make a zip 3.) Make a bzip'ed tarball '''## Menu for tar, zip and gzipdef menu_tar_zip_gz(): print ''' 1.) Make a tarball 2.) Make a zip 3.) Make a gzip'ed tarball '''## Menu for tar, zip and 7zipdef menu_tar_zip_lz(): print ''' 1.) Make a tarball 2.) Make a zip 3.) Make a 7zip'ed tarball '''## Menu for tar, bzip2, and gzipdef menu_tar_bz2_gz(): print ''' 1.) Make a tarball 2.) Make a bzip'ed tarball 3.) Make a gzip'ed tarball '''## Menu for tar, bzip2 and 7zipdef menu_tar_bz2_lz(): print ''' 1.) Make a tarball 2.) Make a bzip'ed tarball 3.) Make a 7zip'ed tarball '''## Menu for tar, gzip and 7zipdef menu_tar_gz_lz(): print ''' 1.) Make a tarball 2.) Make a gzip'ed tarball 3.) Make a 7zip'ed tarball '''## Menu for tar, zip, bzip2, and gzipdef menu_tar_zip_bz2_gz(): print ''' 1.) Make a tarball 2.) Make a zip 3.) Make a bzip'ed tarball 4.) Make a gzip'ed tarball '''## Menu for tar, zip, bzip2, and 7zipdef menu_tar_zip_bz2_lz(): print ''' 1.) Make a tarball 2.) Make a zip 3.) Make a bzip'ed tarball 4.) Make a 7zip'ed tarball '''## Menu for tar, zip, gzip, and 7zipdef menu_tar_zip_gz_lz(): print ''' 1.) Make a tarball 2.) Make a zip 3.) Make a gzip'ed tarball 4.) Make a 7zip'ed tarball '''###################### MENUS - GEN###################### this generates the menu pointer varible valuedef zeo_menu(a): if a == 'a': tyr_menu = 1 elif a == 'b': tyr_menu = 2 elif a == 'c': tyr_menu = 3 elif a == 'ab': tyr_menu = 12 elif a == 'ac': tyr_menu = 13 elif a == 'bc': tyr_menu = 23 elif a == 'abc': tyr_menu = 123 else: tyr_menu = 000 if tyr_menu == 1: return tyr_menu elif tyr_menu == 2: return tyr_menu elif tyr_menu == 3: return tyr_menu elif tyr_menu == 12: return tyr_menu elif tyr_menu == 13: return tyr_menu elif tyr_menu == 23: return tyr_menu elif tyr_menu == 123: return tyr_menu else: return tyr_menu###################### ERROR HANDLER###################### this generates error numbers based on inputdef script_error(a): if a == 'a': err = 7 elif a == 'b': err = 8 elif a == 'c': err = 5 elif a == 'ab': err = 2 elif a == 'ac': err = 7 elif a == 'bc': err = 8 elif a == 'abc': err = 1 else: err = 10 if err == 1: return err elif err == 2 : return err elif err == 3: return err elif err == 4: return err elif err == 5: return err elif err == 6: return err elif err == 7: return err elif err == 8: return err elif err == 9: return err else: return err## prints the error table, and error generated if fataldef error_print(a): cls() print ''' ##################### ERROR NUMBERS ###################### ## 1 - OK *NON FATAL, DUH ;^)* # ## 2 - NO BZIP2 *NON FATAL* # ## 3 - NO GZIP *NON FATAL* # ## 4 - NO LZMP *NON FATAL* # ########################################################## ## 5 - NO TAR *FATAL* # ## 6 - NO ZIP *FATAL IF NO TAR* # ## 7 - NO ZIP *NON FATAL* # ## 8 - NO TAR *NON FATAL* # ## 9 - NO ZIP OR TAR *NON FATAL* # ## 10 - ERROR IN MENU FUNCTION *FATAL* # ######## we need one directory preserving command ######## ''' print ' Heres the error: ', a## this is the error handler, returns non fatal errors to## the script varible NON_FATAL_ERRORdef error_exit(a): if a == 1: return a elif a== 2: return a elif a== 3: return a elif a== 4: return a elif a== 5: error_print(a) raise SystemExit, " Please Check the Error That Occured" elif a== 6: error_print(a) raise SystemExit, " Please Check the Error That Occured" elif a== 7: error_print(a) raise SystemExit, " Please Check the Error That Occured" elif a== 8: return a elif a== 9: return a else: error_print(a) raise SystemExit, " Please Check the Error That Occured"######################################################### START OF MAIN CODE BLOCK######################################################### touch the compression test, test dataos.system('touch /tmp/test.me')## setup the varibles that handle the programsprog_zip = 'zip'prog_bzip = 'bzip2'prog_tar = 'tar'#prog_gzip = 'gzip'#prog_lzma =## set other varibles neededmenu_type = ''blank_var=' 'app_error_var=''non_fatal_error = ''## set up the command lines for the testprog_a = prog_tar + ' --help &> /dev/null'prog_b = prog_zip + ' -h &> /dev/null'prog_c = prog_bzip + ' -9fkvv /tmp/test.me &> /dev/null'#prog_d = prog_gzip + ' -h &> /dev/null'#prog_e = prog_lzma + ''## Pass the above varibles to the test loop and return## them to another varible for usezeo = app_test(prog_a, prog_b,prog_c)#test zeo for "not found" errors and catch themerr = script_error(zeo)non_fatal_error = error_exit(err)## if app errors quit here## else return the non fatal error# send the zeo var's data to a func to convert to data the menu# function understandsmenu_type = zeo_menu(zeo)##remove the test fileos.system('rm /tmp/test.me*')# Display the Splash,# freeze the display at the spalsh screen ( how old skewl ;)print splash(blank_var)splashy = Truewhile splashy: splash_enter = raw_input('') if splash_enter >= '': cls() splashy = False else: cls() splashy = False# print what was found app wisezeo_found(zeo)print ' Press Enter'zeofnd = Truewhile zeofnd: zeofnd_enter = raw_input('') if zeofnd_enter >= '': cls() zeofnd = False else: cls() zeofnd = False#display menu : MAINmenu_main()#print menu_needed(menu_type)print zeoprint menu_type, 'o-o this is not finnished at all'