def configIf(interface): '''Configure a network interface ''' if myConfig.getVar('net.%s.enable' % interface) == True: # Display existing config, if it exists print 'Interface: %s' % interface proto = myConfig.getVar('net.%s.proto' % interface) if proto == 'dhcp': print 'Protocol: %s' % proto else: print 'Address: %s' % myConfig.getVar('net.%s.addr4' % interface) print 'Netmask: %s' % myConfig.getVar( 'net.%s.netmask4' % interface) # This is up here so we can skip the rest if we disable the interface if not confirm('Enable interface %s' % interface): myConfig.setVar('net.%s.enable' % interface, False) print 'Interface %s disabled' % interface return True # Prompt and enter the network information addr4 = raw_input('Enter IPv4 address or "dhcp": ').lower() if addr4 != 'dhcp': if not network.isAddr4(addr4): print 'IPv4 address is malformed. Cancelling configuration.' return False netmask4 = raw_input('Enter netmask: ') if not network.isAddr4(netmask4): print 'Netmask is malformed. Cancelling configuration.' return False # TODO: write facilities for entering IPv6 information here # addr6 = raw_input('Enter IPv6 address or hit Enter to cancel: ') # Confirm the config variables print 'Interface: %s' % interface if addr4 == 'dhcp': print 'Protocol: %s' % addr4 else: print 'IPv4 Address: %s' % addr4 print 'Netmask: %s' % netmask4 #print 'IPv6 Address: %s' % addr4 if confirm('Are these settings correct? [y/N]'): myConfig.setVar('net.%s.enable' % interface, True) if addr4 == 'dhcp': myConfig.setVar('net.%s.proto' % interface, addr4) else: myConfig.setVar('net.%s.proto' % interface, 'static') myConfig.setVar('net.%s.addr4' % interface, addr4) myConfig.setVar('net.%s.netmask4' % interface, netmask4) else: print 'Configuration of %s canceled.' % interface
def main(): if myConfig.getVar('sys.firstrun'): # TODO: Create a first run wizard pass else: # Display the main menu items = { '1': 'Configuration Menu', '2': 'Command Line', '3': 'Utilities', '4': 'Reboot', '5': 'Shutdown' } actions = { '1': confMenu, '2': cmdLine, '3': utilsMenu, '4': reboot, '5': halt } menu = Menu('%s Main Menu' % osName, items, actions) menu.run() if myConfig.needCommit: if confirm('Changes on configuration were made. Save to NVRAM?'): myConfig.save() exit(0)
def init_dest_dir(directory): if not os.path.isdir(directory): os.mkdir(directory) print(f"Directory [{directory}] created") fnum = len(os.listdir(directory)) if fnum > 0: print(f"{fnum} items found in {directory}") if menu.confirm("REBUILD the directory (old files will be erased)?", False): shutil.rmtree(directory) os.mkdir(directory) print(f"{directory} rebuilt from scratch")
def configGw(): '''Configure the default gateway ''' print 'Current Gateway: %s' % (myConfig.getVar('net.gateway4')) gateway4 = raw_input( 'Enter IP Address of gateway or hit Enter to cancel: ') if network.isAddr4(gateway4): if confirm('Is "%s" correct? [y/N]' % gateway4): myAppliance.netSetGw(gateway4) return True else: print 'Invalid address specified. Cancelling.' return False
def configDns(): '''Configure the DNS settings ''' domain = myConfig.getVar('net.domain') nameserver4 = myConfig.getVar('nameserver4') print 'Domain: %s' % (domain) print 'Nameservers: %s' % (nameserver4) domain = raw_input('Enter domain: ') nameserver4 = raw_input('Enter nameservers, seperated by spaces: ') nameserver4 = nameserver4.split(' ') if confirm('Are these settings correct?'): myConfig.setVar('net.domain', domain) myConfig.setVar('net.nameserver4', nameserver4) #myAppliance.netSetDns(domain, nameserver4.split(' ')) print 'Settings will not take effect until reboot.'
def pyvis(directory: str): html_file = "zettel_pyvis.html" net = Network("90%", "100%") filenames = get_filenames(directory) zid_headers = zid_header_db(filenames) connections = zid_links_db(filenames) if menu.confirm("Add non-existent nodes?", False): add_none = True else: add_none = False # build nodes for zid in zid_headers: net.add_node(zid, label=zid_headers[zid]) # build connections net.add_node("None") i = 0 for item in connections: n1, n2 = item if add_none and (not n1 or not n2): continue if n1 not in zid_headers: n1 = "None" if n2 not in zid_headers: n2 = "None" net.add_edge(n1, n2) i += 1 net.show_buttons() net.show(html_file) copy_text = f"open {html_file}" pyperclip.copy(copy_text) print(f"Graph build done") print(f"{len(net.nodes)} nodes") print(f"{len(net.edges)} edges, of projected {len(connections)}") print(f"Edges to non-existent nodes mode: {add_none}") print(f"The data has been stored in {html_file}") print(f"[{copy_text}] has been placed in the clipboard and can be Ctr-V") print("----")
def main(): source = "/Users/kg/Dropbox/academic" destination = "/Users/kg/Dropbox/obsidian" print(f"Zettel-Obsidian rough formatter v0.1") print(f"Source directory: {source}") print(f"Destination directory: {destination}") files_list = dir.list_dir(source, [".md"]) print(f"{len(files_list)} .md files found") num_title_collection = collect.get_nums_headers(files_list) print(f"{len(num_title_collection)} of {len(files_list)} entries collected") if menu.confirm("Do you wish to continue?"): dir.init_dest_dir(destination) for filename in files_list: new_file_data = replace.replace_hashes_inside( filename, num_title_collection ) n = collect.get_header(filename) new_filename = ( os.path.join(destination, n.strip("\n") + ".md") if n else filename ) print(os.path.basename(new_filename), len(new_file_data)) files.save_new(new_filename, new_file_data) print("Obsidian module completed")
def saveConfig(): if confirm('Save configuration database to flash memory?'): if not myAppliance.cfgSave(): return False return True
def halt(): if confirm(): myAppliance.shutdown('halt')
def reboot(): if confirm(): myAppliance.shutdown('reboot')