def __init__(self, *args, captive=None, command=None, result_class=None, **kw): if captive is not None: self.captive = captive if result_class is not None: self.result_class = result_class if command is not None: self.command = command if not command and not self.command and args: self.command = args[0] args = args[1:] if self.args is None: self.args = tuple() else: self.args = tuple(self.args) self.args = (*self.args, *args) if self.kw is None: self.kw = Chibi_atlas() else: self.kw = Chibi_atlas(self.kw.copy()) self.kw.update(kw)
def post_load( self, data, **kw ): from chibi_4chan.chibi_4chan import thread, human_thread data = Chibi_atlas( data ) url = self.context[ 'url' ] human_url = human_thread.format( board=url.kw.board, thread_number=data[ 'id' ], replies=data[ 'replies' ], last_modified=data[ 'last_modified' ] ) data.url = thread.format( human_url=human_url, **human_url.kw ) return data
def post_load( self, data, **kw ): from chibi_4chan.chibi_4chan import image data = Chibi_atlas( data ) data.has_image = 'file_name' in data url = self.context[ 'url' ] if data.has_image: data.image_url = image.format( board=url.kw.board, image=data.tim, ext=data.ext, file_name=data.file_name ) return data
def set_env_vars(cls_obj, containers_with_env_vars): _env_vars = list(e for c in containers_with_env_vars for e in c.env_vars.items()) # _set_env_vars = set() env_vars = Chibi_atlas() for k, v in _env_vars: env_vars[k] = v env_vars.update(cls_obj.env_vars) cls_obj.env_vars = env_vars
def native( self ): try: return self._native except AttributeError: from tetrapod.laniidae.endpoints import Package_check raw_list = self._response.json() self._native = [] for u in raw_list: user = Chibi_atlas( u ) if self.from_endpoint: params = vars( self.from_endpoint )() params.pop( 'url', None ) user.check = Package_check( pk=user.pk, **params ) self._native.append( user ) return self._native
def native( self ): try: return self._native except AttributeError: raw_data = self._response.json() self._native = Chibi_atlas( raw_data ) return self._native
def provision(cls): config = cls.config.open().read() hosts = configuration.chibi_lxc.hosts for k, v in cls.provision_folders.items(): real_folder = cls.provision_folder[k] mount = (f"{real_folder} {cls.provision_root}/{k} " "none bind,create=dir 0 0") if "mount" not in config.lxc: config.lxc.mount = Chibi_atlas(entry=[]) entries = config.lxc.mount.entry if not isinstance(entries, list): entries = [entries] for entry in entries: if entry == mount: break else: entries.append(mount) cls.config.open().write(config) config = cls.config.open().read() if not real_folder.exists: real_folder.mkdir() if v.is_a_folder and not v.endswith('/'): v = str(v) + '/' if not real_folder.exists: real_folder.mkdir() Rsync.clone_dir().human().verbose().run(v, real_folder) if hosts and hosts.exists: hosts.copy(real_folder + 'hosts')
def parse_info(self): result = Chibi_atlas() result.media_metadata = self._parse_media_metadata() result.number = self._parse_episode_number() result.serie_title = result.media_metadata.series_title result.title = result.media_metadata.episode_title result.subtitles = self._parse_subtitles(result.title) result.playlist = self._parse_playlist() return result
def from_info(cls, url, **data): data = Chibi_atlas(data) result = cls(url) result.info.title = data.title result.info.name = data.name result.info.id = data.id result.info.default = data.default return result
def __new__(cls, *args, headers=None, **kw): obj = str.__new__(cls, *args) obj.response_class = kw.pop('response_class', Response) obj.kw = Chibi_atlas(kw) if headers is None: obj._headers = Chibi_atlas_default(str) else: obj._headers = Chibi_atlas_default(str, headers) return obj
def native( self ): try: return self._native except AttributeError: raw_list = self._response.json() self._native = [] for u in raw_list: user = Chibi_atlas( u ) self._native.append( user ) return self._native
def parse_metadata(self): return Chibi_atlas( cover_url=self.cover, #images_urls=[ image.image for image in self.images ], images_len=len(self.images), scan_at=datetime.datetime.utcnow(), tags=self.info.tags, title=self.info.title, upload_at=self.upload_at, url=self.url, )
def __init__(self, result, error, return_code): super().__init__(result, error, return_code) pre_parse = self.result.split('\n') result = {} for pre in pre_parse: if pre: k, v = pre.rsplit('=', 1) result[k.strip()] = v.strip() self.result = Chibi_atlas(result)
def __init__(self, result, error, return_code): super().__init__(result, error, return_code) pre_parse = self.result.split('\n') end_of_status = pre_parse.index('') status = pre_parse[:end_of_status] pre_messages = pre_parse[end_of_status:] messages = [json.loads(m) for m in pre_messages if m] if status: service = status[0].split()[1] else: service = '' if service: show = Systemctl.show(service).run().result else: show = Chibi_atlas() self.result = Chibi_atlas(service=service, human=status, messages=messages, properties=show)
def parse_result(self): if not self: return result = Chibi_atlas() for l in self.result.split('\n'): l = l.strip() if not l: continue k, v = l.split(':') v = v.strip() result[k.lower()] = v.lower() self.result = result
def parse_info(self): info = self.soup.find("div", id="info") tags = self._parse_tags(info) cover = self._parse_cover() images = self._parse_images() upload_at = datetime.datetime.fromisoformat( self.soup.time.attrs["datetime"]) return Chibi_atlas(title=info.h1.text, tags=tags, cover=cover, images=images, upload_at=upload_at)
def parse_info(self): result = Chibi_atlas() result.title = self.soup.select("h1.ellipsis")[0].text.strip() description = self.soup.find("p", {"class": "description"}) result.description = description.find("span", { "class": "more" }).text.strip() seasons = self.soup.find("ul", {"class": "list-of-seasons cf"}) result.seasons = [] for season in seasons.find_all("li", recursive=False): _season = Chibi_atlas() result.seasons.append(_season) _season.name = season.a.text.strip() _season.episodes = [] episodes = season.find_all("a", {"class": "episode"}) for episode in episodes: e = Episode(url=self.url + episode.attrs["href"]) _season.episodes.append(e) return result
def read(self): data = super().read() result = Chibi_atlas() for line in data.split('\n'): line = line.strip() if line.startswith('#') or not line: continue rule, value = line.split('=', 1) rule = rule.strip() value = value.strip() try: current = donkey.get(rule, result) if not isinstance(current, list): current = [current] except KeyError: current = None if current is None: donkey.setter(rule, result, value) else: current.append(value) donkey.setter(rule, result, current) return result
def build_functions(self, deterministic=False): l_out = self.layer_output x_sym = T.lmatrix() y_sym = T.lvector() output = lasagne.layers.get_output(l_out, x_sym, deterministic=deterministic) pred = output.argmax(-1) #loss = objectives.categorical_crossentropy( output, y_sym ).mean() loss = objectives.binary_crossentropy(output, y_sym).mean() params = lasagne.layers.get_all_params(l_out) acc = T.mean(T.eq(output, y_sym)) #grad = T.grad( loss, params ) #updates = lasagne.updates.sgd( grad, params, learning_rate=0.01 ) #updates = lasagne.updates.adam() updates = lasagne.updates.adam(loss, params) f_train = theano.function([x_sym, y_sym], [loss, acc], updates=updates) f_train_pred = theano.function([x_sym, y_sym], [loss, acc, output], updates=updates) f_val = theano.function([x_sym, y_sym], [loss, acc]) f_predict = theano.function([x_sym], pred) f_test_predict = theano.function([x_sym], output) self.functions = Chibi_atlas({ 'train': f_train, 'train_predict': f_train_pred, 'val': f_val, 'predict': f_predict, 'test_predict': f_test_predict, }) return self.functions
class Command: command = '' captive = False args = None kw = None kw_format = "{key} {value}" result_class = Command_result def __init__(self, *args, captive=None, command=None, result_class=None, **kw): if captive is not None: self.captive = captive if result_class is not None: self.result_class = result_class if command is not None: self.command = command if not command and not self.command and args: self.command = args[0] args = args[1:] if self.args is None: self.args = tuple() else: self.args = tuple(self.args) self.args = (*self.args, *args) if self.kw is None: self.kw = Chibi_atlas() else: self.kw = Chibi_atlas(self.kw.copy()) self.kw.update(kw) @property def stdout(self): if self.captive: return PIPE return None @property def stderr(self): if self.captive: return PIPE return None def _build_proccess(self, *args, stdin=None, **kw): if isinstance(stdin, str): stdin = PIPE arguments = self.build_tuple(*args, **kw) logger.debug('coamndo con argumentos "{}"'.format(str(arguments))) arguments = tuple(map(lambda x: str(x), arguments)) proc = Popen(arguments, stdin=stdin, stdout=self.stdout, stderr=self.stderr) return proc def build_tuple(self, *args, **kw): return (self.command, *self.build_kw(**kw), *self.args, *args) def build_kw(self, **kw): params = self.kw.copy() params.update(kw) result = [] for k, v in params.items(): r = self.kw_format.format(key=k, value=v) r = r.split(' ', 1) result += r return result def preview(self, *args, **kw): tuples = self.build_tuple(*args, **kw) tuples = map(lambda x: str(x), tuples) return " ".join(tuples) def run(self, *args, stdin=None, **kw): logger.debug('ejecutando "{}"'.format(self.preview(*args, **kw))) proc = self._build_proccess(*args, stdin=stdin, **kw) if isinstance(stdin, str): result, error = proc.communicate(stdin.encode()) else: result, error = proc.communicate() if result is not None: result = result.decode('utf-8') if error is not None: error = error.decode('utf-8') return self.result_class(result, error, proc.returncode) def __call__(self, *args, **kw): return self.run(*args, **kw) def __hash__(self): return hash(self.preview()) def __eq__(self, other): if isinstance(other, Command): return self.preview() == other.preview() else: raise NotImplementedError def __copy__(self): args = tuple(*self.args) kw = self.kw.copy() new_command = type(self)(*args, command=self.command, captive=self.captive, **kw) return new_command def add_args(self, *new_args, **new_kw): if new_args: self.args = tuple(itertools.chain(self.args, new_args)) if new_kw: self.kw.update(new_kw)
def params(self): current = parse_qs(self.parts[4], keep_blank_values=True) for k, v in current.items(): if isinstance(v, list) and len(v) == 1: current[k] = v[0] return Chibi_atlas(current)
def __init__(self): self._filters = Chibi_atlas() self._model = object
help="modo de escaneo de nmap default ( sn )") args = parser.parse_args() interfaces = ip_addr() if args.interface == 'all': interfaces_to_use = list(interfaces.keys()) else: if ',' in args.interface: interfaces_to_use = map(lambda x: x.strip(), args.interface.split(',')) else: interfaces_to_use = [args.interface] for current_interface in interfaces_to_use: interface = interfaces[current_interface] if current_interface == 'lo' or not interface.ip_v4: continue nmap_result = nmap("-{}".format(args.scan_mode), interface.ip_v4) print("interface: {}\tcommand: {}".format(current_interface, nmap_result.nmaprun.args)) for result in nmap_result.nmaprun.host: result = Chibi_atlas(result) if 'address' not in result: import pdb pdb.set_trace() o = '\tip: {}'.format(result.address.addr) if result.hostnames: o += "\thostname: {} ( {} )".format(result.hostnames.hostname.name, result.hostnames.hostname.type) print(o)
def parse_result( self ): rows = self.result.split( '\n' ) d = dict( ( tuple( r.rsplit( ':', 1 ) ) for r in rows if r ) ) self.result = Chibi_atlas( d )
def parse_info(self): galeries = self.soup.find_all("div", {"class": "gallery"}) links = [ self.episode_class(self.url + g.a.attrs['href']) for g in galeries ] return Chibi_atlas(galeries=links)
def provision_folder(cls): return Chibi_atlas( {k: cls.root + '..' + k for k, v in cls.provision_folders.items()})
class Container(metaclass=Container_meta): name = "unset" distribution = 'centos' arch = 'amd64' version = '8' provision_root = Chibi_path('home/chibi/provision/') provision_folders = Chibi_atlas() scripts = None status_scripts = None extra_hosts = None delegate = True env_vars = Chibi_atlas( {'PROVISION_PATH': '/' + str(provision_root) + 'scripts'}) @Class_property def lxc(cls): if cls.delegate: return lxc_delegate else: return lxc @Class_property def info(cls): result = cls.lxc.Info.name(cls.name).run() if not result: raise Not_exists_error(result.error) return result.result @Class_property def config(cls): if os.getuid() != 0: return Chibi_path(f'~/.local/share/lxc/{cls.name}/config', chibi_file_class=Chibi_lxc_config) return Chibi_path(f'/var/lib/lxc/{cls.name}/config', chibi_file_class=Chibi_lxc_config) @Class_property def exists(cls): result = cls.lxc.Info.name(cls.name).run() return bool(result) @Class_property def root(cls): if os.getuid() != 0: return Chibi_path(f'~/.local/share/lxc/{cls.name}/rootfs') return Chibi_path(f'/var/lib/lxc/{cls.name}/rootfs') @Class_property def provision_folder(cls): return Chibi_atlas( {k: cls.root + '..' + k for k, v in cls.provision_folders.items()}) @Class_property def script_folder(cls): return '/' + cls.provision_root + 'scripts/' @Class_property def is_running(cls): return cls.info.state == 'running' @classmethod def create(cls): template = cls.lxc.Create.name(cls.name).template('download') template = template.parameters('-d', cls.distribution, '-r', cls.version, '--arch', cls.arch) print(template.preview()) result = template.run() if not result: raise Creation_error("un error en la creacion del contenedor" f" '{result.return_code}' revise los output") return result @classmethod def start(cls, daemon=True): command = cls.lxc.Start.name(cls.name) if daemon: command.daemon() result = command.run() return result @classmethod def stop(cls): command = cls.lxc.Stop.name(cls.name) result = command.run() return result @classmethod def destroy(cls, stop=False): if cls.is_running and stop: cls.stop() template = cls.lxc.Destroy.name(cls.name) result = template.run() if not result: raise Destruction_error( "un error en la destruscion del contenedor" f" '{result.return_code}' revise los output") return result @classmethod def provision(cls): config = cls.config.open().read() hosts = configuration.chibi_lxc.hosts for k, v in cls.provision_folders.items(): real_folder = cls.provision_folder[k] mount = (f"{real_folder} {cls.provision_root}/{k} " "none bind,create=dir 0 0") if "mount" not in config.lxc: config.lxc.mount = Chibi_atlas(entry=[]) entries = config.lxc.mount.entry if not isinstance(entries, list): entries = [entries] for entry in entries: if entry == mount: break else: entries.append(mount) cls.config.open().write(config) config = cls.config.open().read() if not real_folder.exists: real_folder.mkdir() if v.is_a_folder and not v.endswith('/'): v = str(v) + '/' if not real_folder.exists: real_folder.mkdir() Rsync.clone_dir().human().verbose().run(v, real_folder) if hosts and hosts.exists: hosts.copy(real_folder + 'hosts') @Class_property def hosts(cls): if cls.extra_hosts: return [cls.name, *cls.extra_hosts] return [cls.name] @classmethod def attach(cls): attach = cls.lxc.Attach.name(cls.name) for k, v in cls.env_vars.items(): attach.set_var(k, v) return attach @classmethod def attach_script(cls, script, *args): attach = cls.attach() for k, v in cls.env_vars.items(): attach.set_var(k, v) command, script = cls._prepare_script(script) return attach.run(command, cls.script_folder + script, *args) @classmethod def run_scripts(cls): for script in cls.scripts: if isinstance(script, tuple): args = cls._prepare_script_arguments(*script[1:]) script = script[0] result = cls.attach_script(script, *args) else: result = cls.attach_script(script) if not result: logger.error( f"fallo el script '{script}' se regreso el codigo " f"{result.return_code}") return result @classmethod def run_status_scripts(cls): for script in cls.status_scripts: if isinstance(script, tuple): args = cls._prepare_script_arguments(*script[1:]) script = script[0] result = cls.attach_script(script, *args) else: result = cls.attach_script(script) if not result: logger.error( f"fallo el status script '{script}' se regreso el codigo " f"{result.return_code}") return result @classmethod def _prepare_script_arguments(cls, *args): result = [] for a in args: if isinstance(a, str): if a.startswith('cls.'): a = a[4:] result.append(getattr(cls, a)) continue result.append(a) return result @staticmethod def _prepare_script(script): if script.endswith('py'): return 'python3', script return 'bash', script
def metadata(self): try: raise NotImplementedError return self._metadata except AttributeError: self._metadata = Chibi_atlas()
boards = Chibi_atlas( { "a": "Anime and Manga", "c": "Anime/Cute", "w": "Anime/Wallpapers", "m": "Mecha", "cgl": "Cosplay and EGL", "cm": "Cute/Male", "f": "Flash", "n": "Transportation", "jp": "Otaku Culture", "vp": "Pokemon", "v": "Video Games", "vg": "Video Game Generals", "vr": "Retro Games", "co": "Comics & Cartoons", "g": "Technology", "tv": "Television & Film", "k": "Weapons", "o": "Auto", "an": "Animals & Nature", "tg": "Traditional Games", "qst": "Quests", "sp": "Sports", "asp": "Alternative Sports", "sci": "Science & Math", "int": "International", "out": "Outdoors", "toy": "Toys", "biz": "Business & Finance", "i": "Oekaki", "po": "Papercraft & Origami", "p": "Photography", "ck": "Food & Cooking", "ic": "Artwork/Critique", "wg": "Wallpapers/General", "mu": "Music", "fa": "Fashion", "3": "3DCG", "gd": "Graphic Design", "diy": "Do-It-Yourself", "wsg": "Worksafe GIF", "s": "Beautiful Women", "hc": "Hardcore", "hm": "Handsome Men", "h": "Hentai", "e": "Ecchi", "u": "Yuri", "d": "Hentai/Alternative", "y": "Yaoi", "t": "Torrents", "hr": "High Resolution", "gif": "Adult GIF", "trv": "Travel", "fit": "Fitness", "x": "Paranormal", "lit": "Literature", "adv": "Advice", "lgbt": "LGBT", "mlp": "Pony [see My Little Pony]", "b": "Random", "r": "Request", "r9k": "ROBOT9001", "pol": "Politically Incorrect", "soc": "Cams & Meetups", "s4s": "Shit 4chan Says", } )
def parse_info(self): image = Chibi_url( self.soup.find("section", id="image-container").img.get('src')) return Chibi_atlas(image=image, )