def _ask_existing_new_build(): """begin with choice of an existing build file or creation of a new build file """ stage = 'begin' pycone._print_log('', stage)## choice = pycone._choose_from(pyconeQ.level_list, pyconeQ.welcome_msg) # create a list of choices return the users choice pycone._print_log(pyconeQ.level_list, stage)## pycone._print_log(choice + 1, stage)## if choice == 0: #choose to use existing builder config pycone._print_log('use auto conf', stage)## print('not yet functional') pycone._exit() # no need to write to autoseed, read from it elif choice == 1: # choose to create a new builder config #_write_to_auto_seed('[autoseed]','', 'new') pycone._print_log('create a new conf', stage)## _pseed_ = pycone._os_prober(pycone._master_seed('')) _ask_source_system(_pseed_) else: pycone._do_help_quit(choice, pyconeQ.level_list)
def _ask_for_source_of_new_iso(base_sys, _b_prober, _pseed_): """Queries for Backup, from iso, or boostrap as the source for the build """ # pseed (pre-master-seed) is not used now that we know the system. stage = 'ask-for-source-of-new-iso' base_list = [] if base_sys == 'other': _mseed_ = _pseed_ else: base = pycone._base(base_sys) _mseed_ = pycone._master_seed(base) if _b_prober: base_list = pyconeQ.backup_list + pyconeQ.iso_list + pyconeQ.custom_list # create a list of choices return the users choice choice = pycone._choose_from(base_list, pyconeQ.base_type_msg + '\n' + stage) # choice_list with Backup choice_list = [_sys_backup, _from_iso, _bootstrap] else: ## go get the system wanted for operations base_list = pyconeQ.iso_list + pyconeQ.custom_list # create a list of choices return the users choice with Backup disabled choice = pycone._choose_from(base_list, pyconeQ.base_type_msg + '\n' + stage) # choice_list without Backup choice_list = [_from_iso, _bootstrap] # choice list without Backup # choices, System Backup, From ISO, or Bootstrap pycone._print_log(base_list, choice + 1, stage)## choice_list[choice](base_sys, _mseed_)
def _rsync_do(_mseed_): # choose a backup of current system stage = 'rsync-do' pycone._print_log(None, None, stage)## distro_dir = pycone._var_from_seed(_mseed_, 'directories', '_BUILD_DIR') for dir in distro_dir: dir = '/home/pyne' + dir pycone._rsync_live(_mseed_, dir)##
def _confirm_mount_chroot_fs(seed): """Requests the user confirm mounting of new fs """ stage = 'confirm-mount-chroot-fs' choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.mount_msg + '\n' + stage) # create a list of choices return the users choice choice_list = [_mount_chroot_fs, pycone._exit] pycone._print_log(pyconeQ.base_type_list, choice + 1, stage)## choice_list[choice](seed)
def _confirm_rsync(_mseed_): """Requests the user confirm rsync'ing of source system """ stage = 'confirm-rsync' # do _mkdir_p(_mseed_,source) choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.start_rsync_msg + '\n' + stage) # return the users choice choice_list = [ _rsync_do, pycone._exit] pycone._print_log(pyconeQ.base_type_list, choice + 1, stage)## choice_list[choice](_mseed_)
def _confirm_os_probe(_pseed_): """Probes the system, returns the result and asks user to confirm. Works with system backup, not needed for iso or bootstrap. """ stage = 'confirm-os-probe' _pseed_ = pycone._master_seed(None) # create a pre-master-seed; no <distro>-seed pycone._print_log('### pseed ###', _pseed_, 'test')## _probed_name = pycone._os_prober(_pseed_) # get the system through prober _probed_sys = pycone._base(_probed_name) # return the full distro-seed name, if exists c_pseed = str.capitalize(str(_probed_name)) # capitalized string just for use in query pycone._print_log(_probed_name, _probed_sys, stage)## if (_probed_sys != False): # be sure base did not return false(ie distro seed does not exist) choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.which_system % c_pseed + '\n' + stage) # probe current system, then user confirm choice_list = [_ask_for_source_of_new_iso, _ask_base_system] # on yes, go create master seed, then continue to question for Backup, etc # on no, continue to manual list of options, check with seedlist, then on to Backup (just a detour)if seedlist != False _b_prober = True # states os_prober returned a name, correct or not pycone._print_log(pyconeQ.yes_no_list, choice + 1, stage)## pycone._print_log(c_pseed, None, stage)## choice_list[choice](_probed_name, _b_prober, _pseed_) else: _b_prober = False _ask_base_system(None, _b_prober, _pseed_)
def _chroot(seed):## needs logging """Mount directories and chroot into new system """ stage = 'chroot' # mount the backup/bootstrap systems for chroot _mount_chroot_fs(seed) pycone._print_log('chrootfs', None, stage)## time.sleep(2) # chroot into new system _working_dir = pycone._var_from_seed(seed, 'directories', '_BUILD_DIR')[0] _rootfs = pycone._var_from_seed(seed, 'directories', '_ROOTFS')[0] + ' ' pycone._print_log(_working_dir, _rootfs, stage)## _bashfs = pycone._var_from_seed(seed, 'chroot', '_CHROOTFS')[0] _terminal_chroot_cmd = pycone._var_from_seed(seed, 'chroot', '_CHROOT_CMD')[0] + ' ' pycone._print_log(_bashfs, _chroot_cmd, stage)## _chroot_rootfs = _working_dir + _rootfs _chroot_ = _terminal_chroot_cmd + _chroot_rootfs + _bashfs pycone._print_log(_chroot_rootfs, _chroot_, stage)## # lxtermimal -e 'chroot <mount dir> /bin/bash' print(_chroot_) os.system('lxterminal -e \'inxi -F\'')
def _install_source_system_packages(base): """Install source packages needed to do a backup """ stage = 'install-source-system-packages' source_packages = pycone._var_from_seed(base, 'dist-packages', '_SOURCE') source_packages = source_packages + pycone._var_from_seed(base, 'packages', '_SOURCE') # list of packages required by the source system pycone._print_log(source_packages, None, stage)## pycone._package_db_update(base) # update the system database from repositories for item in source_packages: pycone._install(base, item)
def _ask_base_system(_probe, _b_prober, _pseed_): """Upon failed auto-os-probe, manually list available seeds """ stage = 'ask-base-system' pycone._print_log('##', stage, '##')## sys_q_list = pycone._system_list() # return a list of choices from available system seeds list_w_other = sys_q_list + ['Other'] # remember quit & help are added later, therefore are not part of len choice = pycone._choose_from(list_w_other, pyconeQ.user_source_system + pyconeQ.base_sys_msg) # this is the users choice, 'other' == (len(list) - 2) pycone._print_log(list_w_other, choice, stage)## base_system = str.lower(list_w_other[choice]) # make the choice to lower letter for manipulation pycone._print_log((len(list_w_other)), base_system, stage)## # if choice is other, source system is unsupported and cannot have 'Backup' if choice == (len(list_w_other)-1): _dist_seed_ = 'other' _b_prober = False else: _dist_seed_ = base_system # get the seed's complete name _b_prober = True pycone._print_log(_dist_seed_, _b_prober, stage)## _ask_for_source_of_new_iso(_dist_seed_, _b_prober, _pseed_)
def _confirm_install_source_system_packages(base):## fix """Install packages used on the source system to create iso from backup/bootstrap """ stage = 'install-source-system-packages' choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.source_paks_msg + '\n' + stage) # return the users choice choice_list = [_install_source_system_packages, pycone._exit()] pycone._print_log(pyconeQ.base_type_list, choice + 1, stage)## choice_list[choice](base) #end
def _copy_user_config_files(seed, user):### not yet working """Copy the user config files/folders from the home directory into /etc/skel that may be needed for live environment """ stage = 'copy-user-config-files' _file_conf = pycone._var_from_seed(seed, 'skeleton', '_CONFIG_FILE') _folder_conf = pycone._var_from_seed(seed, 'skeleton', '_CONFIG_FOLDER') pycone._print_log(_file_conf, _folder_conf, stage)## _working_dir = pycone._var_from_seed(seed, 'directories', '_BUILD_DIR')[0] _rootfs = pycone._var_from_seed(seed, 'directories', '_ROOTFS')[0] pycone._print_log(_working_dir, _rootfs, stage)## _etc_skel = pycone._var_from_seed(seed, 'skeleton', '_SKEL_DIR')[0] _build_dir = '/home/pyne' + _working_dir + _rootfs + _etc_skel configurations = _file_conf + _folder_conf src_dir = '/home/' + user dest_dir = _build_dir pycone._print_log(src_dir, src_dir, stage)## for item in configurations: pycone._print_log(src_dir, src_dir, stage)## #pycone._copy(src_dir + '/' + item, dest_dir + '/' + item) print('cp -rpv', src_dir + '/' + item, dest_dir + '/' + item) time.sleep(2)
def _confirm_base_system(empty): """Probes the system, returns the result and asks user to confirm. Works with system backup, not needed for iso or bootstrap. """ stage = 'confirm-base-system' _pseed_ = pycone._master_seed('') pycone._print_log('pseed ####', _pseed_, 'test')## _probe = pycone._os_prober(_pseed_) # get the system through prober _probed_sys = pycone._base(_probe) # return the full distro-seed name, if exists c_pseed = str.capitalize(str(_probe)) # capitalized string just for use in query pycone._print_log(_probe, _probed_sys, stage)## if (_probed_sys != False): # be sure base did not return false(ie distro seed does not exist) choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.which_system % c_pseed) # probe current system, then user confirm choice_list = [_seed_probe_match, _get_base_system] # on yes, go create master seed, then continue to question for Backup, etc # on no, continue to manual list of options, check with seedlist, then on to Backup (just a detour)if seedlist != False ## create the create-master-seed def pycone._print_log(pyconeQ.yes_no_list, choice + 1, stage)## pycone._print_log(c_system, '', stage)## choice_list[choice](_probe) else: pass
def _ask_existing_new_build(empty): """choice of an existing build file or creation of a new build file """ stage = 'ask-existing/new-build' _pseed_ = pycone._master_seed(None) # get a partial master seed (master seed without <distro>-seed choice = pycone._choose_from(pyconeQ.level_list, stage) # create a list of choices return the users choice choice_list = [_use_auto_seed, _ask_for_source_of_new_iso] pycone._print_log(pyconeQ.level_list, choice + 1, stage)## choice_list[choice](_pseed_)
def _confirm_new_auto_seed(empty): """Confirm creation of new auto-seed """ stage = 'confirm-new-auto-seed' # do _mkdir_p(_mseed_,source) choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.new_auto_seed_msg + '\n' + stage) # return the users choice # This will need to be changed so that the user may be able to name the # auto-seed file, and for this to ask for a name # *must be named <name>_auto_seed.conf* choice_list = [ _confirm_os_probe, pycone._exit] pycone._print_log(None, choice + 1, stage)## choice_list[choice](None)
def _ask_wizard_or_expert(): """choice of using the Wizard or goto Expert mode to adjust a previous build """ stage = 'ask-wizard-or-expert' choice = pycone._choose_from(pyconeQ.mode_list, pyconeQ.welcome_msg + '\n\n' + pyconeQ.mode_msg + '\n' + stage) # create a list of choices return the users choice if pycone._auto_seed_exits(): choice_list = [_ask_existing_new_build, _expert_mode] else: choice_list = [_confirm_new_auto_seed, _expert_mode] # list of decisions pycone._print_log(pyconeQ.mode_list, choice + 1, stage)## # print to log file choice_list[choice](None)
def _ask_for_user_config_backup(seed): """Confirm copy of chosen user config files """ stage = 'ask-for-user-config-backup' users = os.listdir('/home/') + ['None'] user_list = [] for item in users: if item != 'ftp': user_list.append(item) choice = pycone._choose_from(user_list, pyconeQ.which_user_msg) user = user_list[choice] pycone._print_log(choice, user, stage)## if user == 'None': pass else: _copy_user_config_files(seed, user)
def _mkdir_p(base, _mseed_): """Create the directories needed to store new system """ # make the dirs in the pyne dir, which doesn't get rsync'd stage = 'mkdir_p' pycone._print_log(None, None, stage)## distro_dir = pycone._var_from_seed(_mseed_, 'directories', '_BUILD_DIR') iso_creation_dir = pycone._var_from_seed(_mseed_, 'directories', '_ISO_DIR') required_dirs = distro_dir + iso_creation_dir for dir in required_dirs: dir = '/home/pyne' + dir pycone._print_log(dir, None, stage)## # if path is not already present, request to create it # else the dir exists, and PyneCone will use them if not os.path.exists(dir): print("making dir", dir) #os.makedirs(dir) time.sleep(2)
def _ask_source_system(_pseed_): """Queries for Backup, from iso, or boostrap as the source for the build """ # now choose the source of build stage = 'new configuration' pycone._print_log('', stage)## choice = pycone._choose_from(pyconeQ.base_type_list, pyconeQ.base_type_msg) # create a list of choices return the users choice pycone._print_log(pyconeQ.base_type_list, stage)## pycone._print_log(choice + 1, stage)## if choice == 0: # choose a backup of current system #_write_to_auto_seed('source :\n\t','backup', 'append') _q_my_system(_pseed_, 'backup') elif choice == 1: # choose to use an existing iso file #_new_config('iso') print("iso that thing") print("not working at this time") pycone._exit() elif choice == 2: # choose to install a new bootstrap system #_new_config('bootstrap') print("bootstrap new system") print("not working at this time") pycone._exit() else: pycone._do_help_quit(choice, pyconeQ.base_type_list)
def _confirm_base_system(empty):#### new version being worked on """Probes the system, returns the result and asks user to confirm. Works with system backup, not needed for iso or bootstrap. """ stage = 'confirm-base-system' _probe = pycone._os_prober(_pseed_) c_pseed = str.capitalize(_probe) #base = pycone._base(_pseed_) #_mseed_ = pycone._master_seed(str.lower(base)) choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.which_system % c_pseed + '\n' + stage) # probe current system, then user confirm choice_list = [_create_master_seed, _get_base_system] ## create the create-master-seed def ## use pycone._seedlist() and _os_prober() to compare and ## confirm a seed file exists for current system pycone._print_log(pyconeQ.yes_no_list, choice + 1, stage)## pycone._print_log(c_system, '', stage)## choice_list[choice](_probe)
def _q_base_system(): system = pycone._os_prober(pycone._master_seed('')) stage = 'rsync' pycone._print_log('', stage)## c_system = str.capitalize(system) choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.which_system % c_system) # return the users choice pycone._print_log(pyconeQ.yes_no_list, stage) pycone._print_log(choice + 1, stage) if choice == 0: # choose a backup of current system pycone._print_log(choice + 1, stage) #pycone._rsync_live(seed) print('use %s system' % c_system) elif choice == 1: # choose to use an existing iso file #_new_config('iso') pycone._print_log(choice + 1, stage) print("Nothing to do. Exiting") exit() else: _help_quit(choice, pyconeQ.yes_no_list)
def _sys_backup(base_sys, _mseed_): """Go through the Q&A session to build auto_seed.py """ stage = 'sys_backup' os.system('clear') _install_source_system_packages(_mseed_) # install packages used on the source system to create iso from backup/bootstrap time.sleep(2) _mkdir_p(base_sys, _mseed_) # create the directories pycone._print_log('mkdir', None, stage)## """ _copy_user_config_files(_mseed_) # install any /home/user/<config> files needed time.sleep(2) """ _rsync_do(_mseed_) # backup the current system pycone._print_log('rsync', None, stage)## time.sleep(2) _ask_for_user_config_backup(_mseed_) pycone._print_log('copy user config', None, stage)## time.sleep(2) _chroot(_mseed_) # chroot into new system thru new terminal window pycone._print_log('chroot', None, stage)## time.sleep(2) print('That is it for now in PyneCone, thanks for testing') pycone._print_log('That is it for now in PyneCone, thanks for testing', None, 'DONE')##
def _ask_rsync(_mseed_): stage = 'ask-rsync' pycone._print_log('', stage)## choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.start_rsync_msg) # return the users choice pycone._print_log(pyconeQ.yes_no_list, stage)## if choice == 0: # choose a backup of current system pycone._print_log(choice + 1, stage)## distro_dir = pycone._var_from_seed(_mseed_, 'directories', '_BUILD_DIR') for dir in distro_dir: dir = '/home/pyne' + dir pycone._rsync_live(_mseed_, dir) elif choice == 1: # choose to use an existing iso file #_new_config('iso') pycone._print_log(choice + 1, stage)## print("Nothing to do. Exiting") pycone._exit() else: pycone._do_help_quit(choice, pyconeQ.yes_no_list)
def _sys_backup(source): """Go through the Q&A session to build auto_seed.py """ master_seed_file = '/tmp/master_seed.conf' stage = 'sys_backup' pycone._print_log('', stage)## base_seed = _get_base_system('') pycone._print_log(base_seed, stage)## #_write_to_auto_seed('base_seed :\n\t', base_seed, 'append') # update the auto-seed file with base seed type master_seed = pycone._master_seed(base_seed) # get a master-seed file of all needed seeds pycone._print_log('master_seed', stage)## pycone._print_log(master_seed, stage)## _install_source_system_packages(master_seed) # install packages used on the source system to create iso from backup/bootstrap #time.sleep(1) _needed_dirs = _new_dirs(master_seed_file) # get directories needed by PyneCone pycone._print_log(_needed_dirs, stage)## _mkdir_p(_needed_dirs) # create the directories pycone._print_log('mkdir', stage)## #time.sleep(1) _rsync(master_seed) # backup the current system pycone._print_log('rsync', stage)## #time.sleep(1) _mount_chroot_fs(master_seed) # mount the backup/bootstrap systems for chroot pycone._print_log('chrootfs', stage)## _chroot(master_seed) pycone._print_log('chroot', stage)## print('Hello')
def _get_new_dirs(seed): stage = 'new_dirs' pycone._print_log('', stage) _working_dir = pycone._var_from_seed(seed, 'directories', '_BUILD_DIR') # dir to backup or bootstrap system pycone._print_log(_working_dir, stage) _iso_dir = pycone._var_from_seed(seed, 'directories', '_ISO_DIR') # dir to build iso in pycone._print_log(_iso_dir, stage) _cdfs = pycone._var_from_seed(seed, 'file_systems', '_CD_FS') # file system format for iso pycone._print_log(_cdfs, stage) _livefs = pycone._var_from_seed(seed, 'file_systems', '_LIVE_FS') # file system for iso builder pycone._print_log(_livefs, stage) _grub = pycone._var_from_seed(seed, 'directories', '_GRUBFS') # grub file directory pycone._print_log(_grub, stage) _rootfs = pycone._var_from_seed(seed, 'directories', '_ROOTFS') # rootfs for working dir pycone._print_log(_rootfs, stage) #_dir_list = pycone._dir_builder(_iso_dir, _livefs)# + _grub + _working_dir + _rootfs _dir_list = [_iso_dir[0]+ _livefs[0], _iso_dir[0] + _grub[0], _working_dir[0] + _rootfs[0]] pycone._print_log(_dir_list, stage) return _dir_list
def _mkdir_p(_mseed_, source): """Create the directories needed to store new system """ # make dirs in the pyne dir stage = 'mkdir_p' pycone._print_log('', stage)## distro_dir = pycone._var_from_seed(_mseed_, 'directories', '_BUILD_DIR') iso_creation_dir = pycone._var_from_seed(_mseed_, 'directories', '_ISO_DIR') required_dirs = distro_dir + iso_creation_dir for dir in required_dirs: dir = '/home/pyne' + dir pycone._print_log(dir, stage)## # if path is not already present, request to create it # else the dir exists, and PyneCone will use them if not os.path.exists(dir): choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.create_new_dir_msg % (source, dir)) # return the users choice pycone._print_log(pyconeQ.yes_no_list, stage)## if choice == 0: pycone._print_log(choice + 1, stage)## try: pycone._print_log('making dir', stage) print("making dir", dir) #os.makedirs(dir) except: # call error handler pycone._print_log('error making dir', stage) print("error creating backup directory") pycone._exit() elif choice == 1: pycone._print_log(choice + 1, stage)## print('PyneCone cannot continue. Exiting') pycone._exit() else: pycone._do_help_quit(choice, pyconeQ.yes_no_list)
def _install_source_system_packages(base): """Install packages used on the source system to create iso from backup/bootstrap """ stage = 'install source packages' pycone._print_log('', stage)## choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.source_paks_msg) # return the users choice pycone._print_log(pyconeQ.yes_no_list, stage)## pycone._print_log(choice + 1, stage)## # Check ok to install required packages if choice == 0: source_packages = pycone._var_from_seed(base, 'packages', '_SOURCE') # list of packages required by the source system pycone._print_log(choice + 1, stage)## pycone._print_log(source_packages, stage)## pycone._package_db_update(base) # update the database of available packages for item in source_packages: pycone._install(base, item) # install each required package elif choice == 1: pycone._print_log(choice + 1, stage)## pycone._print_log(source_packages, stage)## print('PyneCone cannot continue. Exiting') pycone._exit() else: pycone._do_help_quit(choice, pyconeQ.yes_no_list)
def _q_my_system(_pseed_, source): stage = 'q-my-system' pycone._print_log('', stage)## c_system = str.capitalize(_pseed_) choice = pycone._choose_from(pyconeQ.yes_no_list, pyconeQ.which_system % c_system) # probe current system, then user confirm pycone._print_log(c_system, stage)## pycone._print_log(pyconeQ.yes_no_list, stage)## pycone._print_log(choice + 1, stage)## if choice == 0: # choose a backup of current system pycone._print_log(choice + 1, stage)## #pycone._rsync_live(seed) base = pycone._base(_pseed_) pycone._print_log('pseed', stage)## pycone._print_log(_pseed_, stage)## _mseed_ = pycone._master_seed(str.lower(base)) pycone._print_log('mseed', stage)## pycone._print_log(_mseed_, stage)## _mkdir_p(_mseed_,source) _ask_rsync(_mseed_) elif choice == 1: # choose to use an existing iso file #_new_config('iso') pycone._print_log(choice + 1, stage)## _sys_backup('') pycone._exit() else: pycone._do_help_quit(choice, pyconeQ.yes_no_list)
def _get_base_system(source): stage = 'get base system' pycone._print_log('', stage) sys_q_list = pycone._system_list() # return a list of choices from available system seeds and quit/help pycone._print_log(sys_q_list, stage) choice_list = pycone._choice_list(sys_q_list) # return a numerated list of choices for user pycone._print_log(choice_list, stage) choice = pycone._choose_from(sys_q_list, pyconeQ.base_sys) # return the users choice pycone._print_log(choice + 1, stage) pycone._do_help_quit(choice, sys_q_list + pyconeQ.quit_help_list)## this seems incorrect # allows 'help' and 'quit' choices to work base_system = str.lower(sys_q_list[choice]) # make the choice to lower letter for easier manipulation pycone._print_log(base_system, stage) base_sys = pycone._base(base_system) # get the full seed name pycone._print_log(base_sys, stage) # master_seed = # creates a master seed from base + user + main seeds base_sys_seed = pycone.pyne_dir(base_sys) # get the full seed path and name pycone._print_log(base_sys_seed, stage) return base_sys