def show(self): utils.print_help('Target info:') i = 0 x = PrettyTable() x.field_names = ['index', 'host', 'port', 'brand', 'alternative', 'affective'] for target in self.__targets: # utils.print_info(' ' * 4 + utils.Color.GREEN + str(i) + ': ' + utils.Color.ENDC + # target.host + ':' + str(target.port) + # ', ' + utils.Color.GREEN + 'brand: ' + utils.Color.ENDC + ( # 'unknown' if not target.brand else target.brand) + # ', ' + utils.Color.GREEN + 'alternative exploit: ' + utils.Color.ENDC + ( # '[]' if not target.alternative_exploit else str(target.alternative_exploit)) + # ', ' + utils.Color.GREEN + 'affective exploit: ' + utils.Color.ENDC + # '[]' if not target.affective_exploit else str(target.affective_exploit)) x.add_row([i, target.host, target.port, target.brand, target.alternative_exploit, target.affective_exploit]) i += 1 utils.print_info(x) if self.get_current(): utils.print_help('Current: ', end='') utils.print_info(str(self.get_current().host)) utils.print_help('Threads: ', end='') utils.print_info(str(self.__threads)) utils.print_help('Timeout: ', end='') utils.print_info(str(self.__timeout)) utils.print_help('Output: ', end='') utils.print_info(None if not self.__output else self.__output)
def ytsub_dl(*args, sync=False, **kwargs): if len(args) > 2: print_help(short=True) return if sync: found = find_matching_pl(args[0] if args else "") for pl in found: sync_pl(pl) found = find_matching_pl(args[0] if args else "") ep_indexes = parse_arg_to_ep_indexes(args[1] if len(args) > 1 else "") for pl in found: if not ep_indexes: # download all not downloaded for ep in zfilter(lambda ep: not ep["downloaded"], pl["eps"]): download_ep(pl, ep) print("%s is downloaded" % ep["filename"]) save_pl(pl) else: # download ep by index for ep in zfilter(lambda ep: ep["index"] in ep_indexes, pl["eps"]): download_ep(pl, ep) print("%s is downloaded" % ep["filename"]) save_pl(pl)
def ytsub_add(*args, overwrite=False, **kwargs): if not args or len(args) > 1: print_help(short=True) return pl_id = parse_arg_to_pl(args[0])["id"] (existed, pl) = load_pl(pl_id, create_new=True) if existed and not overwrite: print(r"Playlist{%s} has existed" % pl["title"]) return if existed: print(r"Playlist{%s} will be overwritten" % pl["title"]) pl = fetch_pl(pl["url"]) save_pl(pl) print(r"Playlist{%s} is added" % pl["title"])
def console(image): while True: print(colors.BOLD + str(image.current_partition.number) + ":", end='') image.pwd() print(colors.END, end='') command = input(" >>> ").split(' ', 1) if command[0] == "ls": include_hidden = False long_list = False if len(command) > 1 and command[1][0] == '-': if 'a' in command[1][:4]: include_hidden = True if 'l' in command[1][:4]: long_list = True command = list([command[0], command[1][3:].strip()]) path = command[1] if len(command) > 1 else '' image.ls(path, include_hidden, long_list) elif command[0] == "cd": image.cd(command[1]) elif command[0] == "pwd": image.pwd() print() elif command[0] == "chpar": image.chpar(int(command[1])) elif command[0] == "cp": origin, destination = split_paths(command[1]) image.cp(origin, destination) elif command[0] == "mkdir": image.mkdir(command[1]) elif command[0] == "help": print_help() elif command[0] == "rm": recursive = False if len(command) > 1 and command[1][0] == '-': if 'r' in command[1][:3]: recursive = True command = list([command[0], command[1][2:].strip()]) image.rm(command[1], recursive) elif command[0] == "quit" or command[0] == "q" or command[0] == "exit": return else: print(colors.WARNING + "Unknown command:", command[0] + colors.END)
def handle_input_command(controller, command, args): # Determine which command was requested and (attempt to) execute it if command == utils.ADD: # Reload the file if there have been changes controller.load_from_file() data_type = utils.convert_char_to_data_key(args[0]) if data_type != "": data_info = args[1:] controller.add_item(data_type, data_info) controller.save_to_file() else: pass # Do nothing if an invalid type was supplied elif command == utils.LIST: # Reload the file if there have been changes controller.load_from_file() # There should be only one argument for list, but if there are multiple, # We only read the first one (No errors thrown, however) data_type = utils.convert_char_to_data_key(args[0]) if data_type != "": controller.list_items(data_type) else: pass # Do nothing if an invalid type was supplied elif command == utils.FLIGHT: # Reload the file if there have been changes controller.load_from_file() controller.search_for_flight(args[0:]) elif command == utils.QUIT: return False # Return False to end program execution elif command == utils.HELP: utils.print_help() else: # Invalid command entered; alert user print("Invalid command entered. Type 'h' for assistance") return True
def ytsub_rm(*args, **kwargs): rm_all = kwargs.get("all", False) if not rm_all and len(args) != 1: print_help(short=True) return if rm_all: for pl in load_pls(): remove(get_pl_path(pl["id"])) print(r"Playlist{%s} is removed" % pl["title"]) return mstr = str(args[0]) found = find_matching_pl(mstr) if not found: print("Can't match playlist by \"%s\"" % mstr) elif len(found) > 1: print("Found multiple matched playlists:") for pl in found: print("[%s] %s" % (pl["id"], pl["title"])) else: remove(get_pl_path(found[0]["id"]))
def ytsub_ls(*args, short=False, **kwargs): if len(args) > 1: print_help(short=True) return pls = load_pls() if not args: for pl in pls: print_pl(pl, short) if not short: print("\n") else: mstr = str(args[0]) found = find_matching_pl(mstr) if not found: print("Can't match playlist by \"%s\"" % mstr) elif len(found) > 1: print("Found multiple matched playlists:") for pl in found: print("[%s] %s" % (pl["id"], pl["title"])) else: print_pl(found[0], short)
def show(self): utils.print_help('"Target info') i = 0 x = PrettyTable() x.field_names = ['index', 'host', 'port'] for target in self.__targets: x.add_row([i, target.host, target.port]) i += 1 utils.print_info(x) utils.print_help('Threads: ', end='') utils.print_info(str(self.__threads)) utils.print_help('Timeout: ', end='') utils.print_info(str(self.__timeout)) utils.print_help('Output: ', end='') utils.print_info(self.__output)
try: import re, json, mechanize except ImportError as error: print(error) _, missing_moudle, _ = str(error).split("'") sys.exit("Usage: \"pip install %s\" or \"apt install python-%s\"" %(missing_moudle, missing_moudle) ) try: getcookie = open('cookie.dat', 'r') cookie = getcookie.read() getcookie.close() except: utils.printf("Error while reading cookie", "bad") sys.exit("Reading cookie.dat error") if len(sys.argv) == 1: utils.print_help() else: option = sys.argv[1] if option == "help" or option == "-h" or option == "--help": utils.print_full_help() else: utils.print_banner() utils.printf("\nPlease wait....") actions.get_data(option, cookie)
import sys import os.path as path import ytsub from utils import print_help VERSION = "1.0.1" if __name__ == "__main__": argv = sys.argv.copy() options = {} options["filename"] = path.basename(argv[0]) options["version"] = VERSION if len(argv) < 2: print_help(**options) exit(0) verb = argv[1].lower() try: getattr(sys.modules["ytsub"], "ytsub_%s" % verb) except AttributeError: print_help(**options) exit(0) clone_argv = argv.copy() for arg in clone_argv[2:]: if arg.startswith("--"): argv.pop(argv.index(arg)) options[arg[2:]] = True
from hosts import CinderHost from hosts import GlanceHost from hosts import NovaHost import utils from sys import argv if __name__ == "__main__": delete_pools = '--delete-pools' in argv reset_pools = '--reset-pools' in argv create_pools = '--create-pools' in argv create_keyrings = '--create-keyrings' in argv if "help" in argv: utils.print_help() if delete_pools and reset_pools: print "Unable to delete and reset the pools" utils.print_help() params = utils.get_config(argv[1]) ceph_host = utils.check_ceph_host(params) Ceph = CephHost(params, ceph_host[0]) if delete_pools: roles = argv[3:] Ceph.delete_pools(roles) exit()
def help_exit(self): utils.print_help('Exit script')
def main(self, loop, event, canvas): self.rows, self.columns = utils.terminal_size() self.song, self.artist, self.album, self.art_url = self.spotify.metadata( ) self.update_directories() self.update_lyrics() album_cover = canvas.create_placement( 'album_cover', x=self.columns // 2, y=4, scaler=ueberzug.ScalerOption.COVER.value) album_cover.path = self.image_file if self.album_hidden: album_cover.visibility = ueberzug.Visibility.INVISIBLE else: album_cover.visibility = ueberzug.Visibility.VISIBLE utils.hide_cursor() self.print_metadata() start_row = 5 with utils.KeyPoller() as key_poller: while event.is_set(): song, artist, album, art_url = self.spotify.metadata() if self.song != song or self.artist != artist: self.song = song self.artist = artist self.album = album self.art_url = art_url self.update_directories() self.update_lyrics() album_cover.path = self.image_file self.print_metadata() rows, columns = utils.terminal_size() if self.rows != rows or self.columns != columns: difference = rows - self.rows self.rows, self.columns = rows, columns if difference > 0: self.current_line -= difference self.current_line = max(0, self.current_line) self.current_line = min( self.current_line, self.total_lines - self.n_entries) album_cover.x = self.columns // 2 self.print_metadata() if self.changed: lines = self.lyrics.split('\n') wrapped_lines = [] for line in lines: wrapped_lines.extend( textwrap.fill(line, (columns if self.album_hidden else columns // 2 - 2)).split('\n')) self.total_lines = len(wrapped_lines) utils.move_cursor(0, start_row) self.n_entries = min(rows + self.current_line - start_row, self.total_lines) - self.current_line for i in range(self.current_line, self.current_line + self.n_entries): utils.delete_line() print(utils.boldify(wrapped_lines[i])) utils.move_cursor(0, self.n_entries + start_row) utils.delete_line() self.changed = False key = key_poller.poll(timeout=0.1) if key is not None: if key == 'q': os.system('clear') loop.quit() event.clear() break elif key == 'j' or ord(key) == 5: self.current_line += 1 elif key == 'k' or ord(key) == 25: self.current_line += -1 elif key == 'e': try: EDITOR = os.environ.get('EDITOR') album_cover.visibility = ueberzug.Visibility.INVISIBLE call([EDITOR, self.lyrics_file]) self.update_lyrics() self.print_metadata() utils.hide_cursor() if self.album_hidden: album_cover.visibility = ueberzug.Visibility.INVISIBLE else: album_cover.visibility = ueberzug.Visibility.VISIBLE except TypeError: os.system('clear') print('$EDITOR is not set') time.sleep(1) elif key == 'r': self.print_metadata() elif key == 'd': os.remove(self.lyrics_file) self.update_lyrics() elif key == 'n': self.spotify.next() elif key == 'p': self.spotify.prev() elif key == 't': self.spotify.toggle() elif key == 'i': self.album_hidden = not self.album_hidden self.changed = True if self.album_hidden: album_cover.visibility = ueberzug.Visibility.INVISIBLE else: album_cover.visibility = ueberzug.Visibility.VISIBLE elif key == 'h': os.system('clear') album_cover.visibility = ueberzug.Visibility.INVISIBLE utils.move_cursor(0, 0) utils.print_help() time.sleep(5) self.print_metadata() if self.album_hidden: album_cover.visibility = ueberzug.Visibility.INVISIBLE else: album_cover.visibility = ueberzug.Visibility.VISIBLE key_poller.flush() elif key == 'g': modified_key = key_poller.poll(timeout=1.0) if modified_key == 'g': self.current_line = 0 elif key == 'G': self.current_line = self.total_lines - self.n_entries