def get_parameters(self): """ Get common name and Org name from user """ while self.common_name == '': self.common_name = Avalon.gets('CA Common Name: ') while self.organization == '': self.organization = Avalon.gets('Organization Name: ')
def enroll_settings(): settings = {} settings['waifu2x_path'] = get_path('waifu2x-caffe-cui.exe path: ') settings['ffmpeg_path'] = get_path('ffmpeg binaries directory: ') settings['ffmpeg_arguments'] = [] while True: argument = Avalon.gets( 'Extra arguments passed to ffmpeg (empty=none): ') if argument: settings['ffmpeg_arguments'].append(argument) else: break settings['ffmpeg_hwaccel'] = Avalon.gets( 'ffmpeg hardware acceleration method (empty=auto): ') if settings['ffmpeg_hwaccel'] == '': settings['ffmpeg_hwaccel'] = 'auto' settings['video2x_cache_folder'] = Avalon.gets( 'Video2X cache folder (empty=system default): ') if settings['video2x_cache_folder'] == '': settings['video2x_cache_folder'] = False settings['preserve_frames'] = Avalon.ask( 'Preserve extracted or upscaled frames') return settings
def enroll_settings(): settings = {} settings['waifu2x_path'] = get_path('waifu2x-caffe-cui.exe path: ') settings['ffmpeg_path'] = get_path('ffmpeg binaries directory: ') settings['ffmpeg_arguments'] = [] while True: argument = Avalon.gets('Extra arguments passed to ffmpeg (empty when done): ') if argument: settings['ffmpeg_arguments'].append(argument) else: break settings['ffmpeg_hwaccel'] = Avalon.gets('ffmpeg hardware acceleration method (cuda): ') if settings['ffmpeg_hwaccel'] == '': settings['ffmpeg_hwaccel'] = 'cuda' settings['extracted_frames'] = Avalon.gets('Temporary directory for extracted frames (empty for mkdtemp): ') if settings['extracted_frames'] == '': settings['extracted_frames'] = False settings['upscaled_frames'] = Avalon.gets('Temporary directory for upscaled frames (empty for mkdtemp): ') if settings['upscaled_frames'] == '': settings['upscaled_frames'] = False settings['preserve_frames'] = Avalon.ask('Preserve extracted or upscaled frames') return settings
def add_peer(): """ Enroll a new peer Gets all the information needed to generate a new Peer class object. """ # Get peer tunnel address while True: address = Avalon.gets('Address (leave empty if client only): ') result = re.match('^(?:\d{1,3}\.){3}\d{1,3}/{1}(?:\d\d?)?$', address) if result is None: Avalon.error('Invalid address entered') Avalon.error('Please use CIDR notation (e.g. 10.0.0.0/8)') continue break # Get peer public IP address while True: public_address = Avalon.gets( 'Public address (leave empty if client only): ') result = re.match('^(?:\d{1,3}\.){3}\d{1,3}(?:/\d\d?)?$', public_address) if result is None and public_address != '': # field not required Avalon.error('Invalid IP address entered') continue break # Get peer listening port listen_port = Avalon.gets('Listen port (leave empty for client): ') # Get peer private key private_key = Avalon.gets( 'Private key (leave empty for auto generation): ') if private_key == '': private_key = wg.genkey() # Ask if this peer needs to be actively connected # if peer is behind NAT and needs to be accessed actively # PersistentKeepalive must be turned on (!= 0) keep_alive = Avalon.ask('Keep alive?', False) """ preshared_key = False if Avalon.ask('Use a preshared key?', True): preshared_key = Avalon.gets('Preshared Key (leave empty for auto generation): ') if preshared_key == '': preshared_key = wg.genpsk() peer = Peer(address, private_key, keep_alive, listen_port, preshared_key) """ peer = Peer(address, public_address, listen_port, private_key, keep_alive) pm.peers.append(peer) print_peer_config(peer)
def _get_controlled_interfaces(self): """ Get interfaces to be controlled by SCUTUM """ # Get controlled interfaces ifaces_selected = [] ifaces = [] # List all available interfaces with open('/proc/net/dev', 'r') as dev: for line in dev: try: if line.split(':')[1]: ifaces.append(line.split(':')[0]) except IndexError: pass # Enroll controlled interfaces while True: print(Avalon.FM.BD + '\nWhich interface do you want scutum to control?' + Avalon.FM.RST) if not len(ifaces) == 0: index = 0 for iface in ifaces: if iface.replace(' ', '') not in ifaces_selected: print(f'{str(index)}. {iface.replace(" ", "")}') index += 1 print('x. Manually Enter') print(Avalon.FM.BD + 'Press [ENTER] when complete' + Avalon.FM.RST) selection = Avalon.gets('Please select (index number): ') try: if selection == 'x': manif = Avalon.gets('Interface: ') if manif not in ifaces_selected: ifaces_selected.append(manif) elif selection == '': if len(ifaces_selected) != 0: break else: Avalon.error('You have not selected any interfaces yet') elif int(selection) >= len(ifaces): Avalon.error('Selected interface doesn\'t exist!') else: ifaces_selected.append(ifaces[int(selection)].replace(' ', '')) except ValueError: Avalon.error('Invalid Input!') Avalon.error('Please enter the index number!') # Put controlled interfaces into configuraion self.config['Interfaces']['interfaces'] = ifaces_selected
def _install_scutum_files(self): """ Install all SCUTUM files into system """ print(Avalon.FM.BD + 'Choose Installation Directory (Enter for default)' + Avalon.FM.RST) installation_dir = Avalon.gets('Choose Installation Path (\"/usr/share/scutum\"):') if installation_dir.strip(' ') != '' and installation_dir[-1] == '/': self.INSTALL_DIR = installation_dir[0:-1] # strip last '/' if exists. breaks program path format Avalon.info(f'Changed installation directory to: {Avalon.FM.BD}{self.INSTALL_DIR}{Avalon.FM.RST}') elif installation_dir.strip(' ') != '': self.INSTALL_DIR = installation_dir Avalon.info(f'Changed installation directory to: {Avalon.FM.BD}{self.INSTALL_DIR}{Avalon.FM.RST}') else: Avalon.info(f'Using default installation directory: {Avalon.FM.BD}{self.INSTALL_DIR}{Avalon.FM.RST}') # If files are not already in place if self.INSTALLER_DIR != self.INSTALL_DIR: if os.path.isdir(self.INSTALL_DIR): shutil.rmtree(self.INSTALL_DIR) # delete existing old scutum files shutil.copytree(self.INSTALLER_DIR, self.INSTALL_DIR) # Remove executable in PATH if exists if os.path.islink(self.SCUTUM_BIN_FILE) or os.path.isfile(self.SCUTUM_BIN_FILE): os.remove(self.SCUTUM_BIN_FILE) # Remove old file or symbolic links # Link scutum main executable to PATH # This will allow user to use the "scutum" command Utilities.execute(['ln', '-s', f'{self.INSTALL_DIR}/bin/scutum.py', self.SCUTUM_BIN_FILE])
def get_path(text): """ Get path and validate """ while True: path = Avalon.gets(text) if os.path.isdir(path): return path Avalon.error('{} id not a directory/folder'.format(path))
def enroll_settings(): settings = {} settings['waifu2x_path'] = get_path('waifu2x-caffe-cui.exe path: ') settings['ffmpeg_path'] = get_path('ffmpeg binaries directory: ') settings['ffmpeg_arguments'] = [] while True: argument = Avalon.gets( 'Extra arguments passed to ffmpeg (empty when done): ') if argument: settings['ffmpeg_arguments'].append(argument) else: break settings['ffmpeg_hwaccel'] = Avalon.gets( 'ffmpeg hardware acceleration method (cuda): ') if settings['ffmpeg_hwaccel'] == '': settings['ffmpeg_hwaccel'] = 'cuda' return settings
def get_psk_length(): """Asks the user for desired password length Returns: int -- length of PSK """ while 1: try: psk_length = int(Avalon.gets("Desired PSK Length: ")) if psk_length < 8 or psk_length > 63: Avalon.error("PSK length should be between 8 and 63") continue break except ValueError: Avalon.error("Invalid Input") return psk_length
def _get_arp_controller_driver(self): """ Choose ARP controller driver """ print(Avalon.FM.BD + '\nConfigure ARP Controller Driver' + Avalon.FM.RST) # Inform the user which driver is active on current system if shutil.which('nft'): Avalon.info('nftables is available') if shutil.which('arptables'): Avalon.info('arptables is available') while True: driver = Avalon.gets('Please choose an ARP controller driver (nftables/arptables): ') if driver == 'nftables' or driver == 'arptables': self.config['ArpController']['driver'] = driver break else: Avalon.error('Invalid ARP controller driver chosen')
def _get_controlled_nm(self): """ Ask which network controller to hook to """ while True: print(Avalon.FM.BD + '\nWhich network controller do you want to install for?' + Avalon.FM.RST) print('1. WICD') print('2. Network-Manager') print('3. Both') selection = Avalon.gets('Please select: (index number): ') if selection == '1': if self.install_wicd_scripts() is not True: Avalon.error('SCUTUM Script for WICD has failed to install!') Avalon.error('Aborting Installation...') exit(1) self.config['NetworkControllers']['controllers'] = 'wicd' break elif selection == '2': if self.install_nm_scripts(self.config['Interfaces']['interfaces']) is not True: Avalon.error('SCUTUM Script for NetworkManager has failed to install!') Avalon.error('Aborting Installation...') exit(1) self.config['NetworkControllers']['controllers'] = 'NetworkManager' break elif selection == '3': ifaces = ['wicd', 'NetworkManager'] if self.install_wicd_scripts() is not True: Avalon.warning('Deselected WICD from installation') ifaces.remove('wicd') if self.install_nm_scripts(self.config['Interfaces']['interfaces']) is not True: Avalon.warning('Deselected NetworkManager from installation') ifaces.remove('NetworkManager') if len(ifaces) == 0: Avalon.error('All SCUTUM Scripts have failed to install!') Avalon.error('Aborting Installation...') exit(1) self.config['NetworkControllers']['controllers'] = ifaces break else: Avalon.error('Invalid Input!')
def _install_defense_matrix(self): """ Installs defense matrix to system and link defense matrix executable to bin path. """ # Get installation destination from user user_install_dir = Avalon.gets( 'Installation destination (\"/usr/share/defense-matrix\")') if user_install_dir != '': self.install_dir = user_install_dir # If files already at the correct directory, pass if self.current_dir == self.install_dir: pass # Check if destination directory occupied else: if os.path.isdir(self.install_dir) or os.path.islink( self.install_dir): if not Avalon.ask('Target directory exists. Overwrite?', True): Avalon.warning( 'Aborting installation: target directory not writable') if os.path.isdir(self.install_dir): shutil.rmtree(self.install_dir) else: os.remove(self.install_dir) # Copy defense matrix to destination directory shutil.copytree(self.current_dir, self.install_dir) # If defense-matrix is already linked to path, remove it if os.path.islink(self.executable) or os.path.isfile(self.executable): os.remove(self.executable) # Remove old file or symbolic links # Link current defense-matrix.py to path os.symlink('{}/bin/defense-matrix.py'.format(self.current_dir), self.executable)
def get_parameters(self): while self.username == '': self.username = Avalon.gets('Username: ')
raise ArgumentError('both scaling ration and width/height specified') if (args.width and not args.height) or (not args.width and args.height): Avalon.error('You must specify both width and height') raise ArgumentError('only one of width or height is specified') # check available memory if driver is waifu2x-based if args.driver in ['waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan']: check_memory() # anime4k runs significantly faster with more threads if args.driver == 'anime4k' and args.threads <= 1: Avalon.warning('Anime4K runs significantly faster with more threads') if Avalon.ask('Use more threads of Anime4K?', True): while True: try: threads = Avalon.gets('Amount of threads to use [5]: ') args.threads = int(threads) break except ValueError: if threads == '': args.threads = 5 break else: Avalon.error(f'{threads} is not a valid integer') # read configurations from JSON config = read_config(args.config) config = absolutify_paths(config) # load waifu2x configuration if args.driver == 'waifu2x_caffe':
def add_peer(): """ Enroll a new peer Gets all the information needed to generate a new Peer class object. """ # Get peer tunnel address while True: address = Avalon.gets( 'Address (leave empty if client only) [IP/CIDR]: ') if re.match('^(?:\d{1,3}\.){3}\d{1,3}/{1}(?:\d\d?)?$', address) is None: Avalon.error('Invalid address entered') Avalon.error('Please use CIDR notation (e.g. 10.0.0.0/8)') continue break # Get peer public IP address while True: public_address = Avalon.gets( 'Public address (leave empty if client only) [IP|FQDN]: ') # Check if public_address is valid IP or FQDN valid_address = False if re.match('^(?:\d{1,3}\.){3}\d{1,3}(?:/\d\d?)?$', public_address) is not None: valid_address = True if re.match( '(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)', public_address) is not None: valid_address = True if not valid_address and public_address != '': # field not required Avalon.error('Invalid public address address entered') Avalon.error('Please enter an IP address or FQDN') continue break # Get peer listening port listen_port = Avalon.gets( 'Listen port (leave empty for client) [1-65535]: ') # Get peer private key private_key = Avalon.gets( 'Private key (leave empty for auto generation): ') if private_key == '': private_key = wg.genkey() # Ask if this peer needs to be actively connected # if peer is behind NAT and needs to be accessed actively # PersistentKeepalive must be turned on (!= 0) keep_alive = Avalon.ask('Keep alive?', False) """ preshared_key = False if Avalon.ask('Use a preshared key?', True): preshared_key = Avalon.gets('Preshared Key (leave empty for auto generation): ') if preshared_key == '': preshared_key = wg.genpsk() peer = Peer(address, private_key, keep_alive, listen_port, preshared_key) """ # Get peer alias alias = Avalon.gets('Alias (optional): ') # Get peer description description = Avalon.gets('Description (optional): ') # Create peer and append peer into the peers list peer = Peer(address, public_address, listen_port, private_key, keep_alive=keep_alive, alias=alias, description=description) pm.peers.append(peer) print_peer_config(peer)
# check available memory if driver is waifu2x-based if args.driver in [ 'waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan' ]: check_memory() # anime4k runs significantly faster with more threads if args.driver == 'anime4k' and args.threads <= 1: Avalon.warning('Anime4K runs significantly faster with more threads') if Avalon.ask('Use more threads of Anime4K?', default=True, batch=args.batch): while True: try: threads = Avalon.gets('Amount of threads to use [5]: ', default=5, batch=args.batch) args.threads = int(threads) break except ValueError: if threads == '': args.threads = 5 break else: Avalon.error(f'{threads} is not a valid integer') # read configurations from JSON config = read_config(args.config) # load waifu2x configuration waifu2x_settings = config[args.driver]
# check available memory if driver is waifu2x-based if args.driver in [ 'waifu2x_caffe', 'waifu2x_converter', 'waifu2x_ncnn_vulkan' ]: check_memory() # anime4k runs significantly faster with more processes if args.driver == 'anime4k' and args.processes <= 1: Avalon.warning('Anime4K runs significantly faster with more processes') if Avalon.ask('Use more processes of Anime4K?', default=True, batch=args.batch): while True: try: processes = Avalon.gets('Amount of processes to use [5]: ', default=5, batch=args.batch) args.processes = int(processes) break except ValueError: if processes == '': args.processes = 5 break Avalon.error(f'{processes} is not a valid integer') # read configurations from configuration file config = read_config(args.config) # config = absolutify_paths(config) # load waifu2x configuration
#Project Link:https://github.com/mnixry/Tieba2MD ''' 百度贴吧下载器主程序 遵守GPL协议,侵权必究 ''' from API import api from avalon_framework import Avalon import os USE_IMAGE_BED = True GENERAL_DEBUG_MODE = False while True: link = Avalon.gets('请输入帖子链接:') try: postID = int((link.split('/'))[-1].split('?')[0]) except: Avalon.warning('输入错误!') pass else: postID = str(postID) Avalon.info('帖子ID:' + postID) break onlySeeLZ = Avalon.ask('只看楼主?', True) while True: fileName = Avalon.gets('请输入要保存的文件名,必须以.md为后缀:') if fileName.split('.')[-1] != 'md':
This method sets the servo to a certain angle whereL MAX = 90 deg MIN = -90 deg Neutral = 0 deg (horizon) This method is designed to take an input of an angle of the dgree above horizon, aka the elevation. """ angle *= -1 angle += 90 self._setup() self.p.start(self._convert_angle(angle)) time.sleep(1) self.p.stop() # --------------------------------- Begin Self Testing """ The code below is for self-testing when this file is ran independently. It takes an angle and sets the servo to that angle. """ if __name__ == "__main__": servo = Servo(16) # Using pin 16 (BOARD) while True: servo.set_angle(float(Avalon.gets("Angle: ")))
the iss pointer. """ # 360 degrees / steps per revolution * current steps current_angle = 360 * self.current_pos / (self.steps_per_revolution) angle_to_rotate = azimuth - current_angle # print("azimuth: {0:4.3f}\tcurrent angle: {1:4.3f}\tTo rotate: {2:4.4f}".format(azimuth,current_angle,angle_to_rotate)) if angle_to_rotate == 0: # Do not rotate when change in angle is 0 pass elif angle_to_rotate > 0: # Rotate clockwise GPIO.output(self.dir_pin, 0) self.rotate(angle_to_rotate) elif angle_to_rotate < 0: # Rotate counter-clockwise # Send signal to the direction pin so it rotates ccw GPIO.output(self.dir_pin, 1) self.rotate(-1 * angle_to_rotate, False) GPIO.output(self.dir_pin, 0) # Cut signal # --------------------------------- Begin Self Testing """ The code below is for self-testing when this file is ran independently. It takes an integer and a direction then rotates the motor. """ if __name__ == '__main__': GPIO.setmode(GPIO.BOARD) stepper = Stepper([12, 11, 13, 15]) while True: stepper.rotate(int(Avalon.gets("Angle")), Avalon.ask("CW?", True))
pageHTMLContent = post.getContent(i) pageMarkdownContent = post.contentToMarkdown(pageHTMLContent, useImageBed=imageBed) except KeyboardInterrupt: Avalon.critical('用户强制退出') quit(1) except SystemExit: pass else: lastContext.append(pageMarkdownContent) lastContext = ''.join(lastContext) post.saveToFile(savedFileName, lastContext) return True filePath = Avalon.gets('请输入帖子目录文件路径:') pathName = os.path.splitext(os.path.split(filePath)[-1])[0] if not os.path.exists(pathName): os.mkdir(pathName) with open(filePath) as f: perLink = f.readlines() perID = [] for i in perLink: postID = int((i.split('/'))[-1].split('?')[0]) perID.append(postID) #Avalon.info(str(perID)) for i in perID: childFileName = str(i) + '.md' childPath = os.path.join(pathName, childFileName) # fullBehavior(postID=postID, fileName=fileName, onlySeeLZ=False) singleBehavior(postID=i, seeLZ=False, savedFileName=childPath)