def install_theme(name, url, listing): if name is None and not listing: print "This command needs either the -n or the -l option." return False data = urllib2.urlopen(url).read() data = json.loads(data) if listing: print "Themes:" print "-------" for theme in sorted(data.keys()): print theme return True else: if name in data: if os.path.isfile("themes"): raise IOError, "the 'themes' isn't a directory!" elif not os.path.isdir("themes"): try: os.makedirs("themes") except: raise OSError, "mkdir 'theme' error!" print "Downloading: %s" % data[name] zip_file = StringIO() zip_file.write(urllib2.urlopen(data[name]).read()) print "Extracting: %s into themes" % name utils.extract_all(zip_file) else: print "Can't find theme %s" % name return False
def install_theme(name, url, listing): if name is None and not listing: print "This command needs either the -n or the -l option." return False data = urllib2.urlopen(url).read() data = json.loads(data) if listing: print "Themes:" print "-------" for theme in sorted(data.keys()): print theme return True else: if name in data: print 'Downloading: %s' % data[name] zip_file = StringIO() zip_file.write(urllib2.urlopen(data[name]).read()) print 'Extracting: %s into themes' % name utils.extract_all(zip_file) else: print "Can't find theme %s" % name return False
def __init__(self, B, T, g_E, g_H, d_E, d_H, d_dropout, g_lr=1e-3, d_lr=1e-3, n_sample=16, generate_samples=20, init_eps=0.1, real_packets_file="real_packet_sizes.txt"): self.top = os.getcwd() self.B, self.T = B, T self.g_E, self.g_H = g_E, g_H self.d_E, self.d_H = d_E, d_H self.d_dropout = d_dropout self.generate_samples = generate_samples self.g_lr, self.d_lr = g_lr, d_lr self.eps = init_eps self.init_eps = init_eps self.real_packets = real_packets_file self.pos_sequences, self.V = extract_all(real_packets_file) self.all_signatures = signatureExtractionAll(self.pos_sequences, 2, 6, 5, 4) self.pos_sequences = split_sequences(self.pos_sequences, T - 2) self.neg_sequences = [] self.agent = Agent(B, self.V, g_E, g_H, g_lr) self.g_beta = Agent(B, self.V, g_E, g_H, g_lr) self.discriminator = Discriminator(self.V, d_E, d_H, d_dropout) self.signature_discriminator = SignatureDiscriminator(signatureCount( self.all_signatures), H=200) self.env = Environment(self.discriminator, self.signature_discriminator, self.all_signatures, self.B, self.V, self.g_beta, n_sample) self.generator_pre = GeneratorPretraining(self.V, g_E, g_H) self.g_pre_path, self.d_pre_path = None, None
if choice not in ['bfs', 'dfs', 'random', 'dijkstra', 'greedy', 'a-star']: print('Try again.') continue break if animated_flag: stdscr = curses.initscr() curses.cbreak() curses.noecho() curses.curs_set(False) curses.start_color() utils.initialize_colors() else: stdscr = None arguments = (stdscr, *utils.extract_all(sys.argv[1]), animated_flag) result = choice if choice == 'bfs': result = result, *bfs.bfs_iterative(*arguments) elif choice == 'dfs': result = result, *dfs.dfs_iterative(*arguments) elif choice == 'random': result = result, *random_search.random_search(*arguments) elif choice == 'dijkstra': result = result, *dijkstra.dijkstra(*arguments) elif choice == 'greedy': result = result, *greedy_search.greedy_search(*arguments) elif choice == 'a-star': result = result, *a_star.a_star(*arguments)