def check_opts(opts): # exists(opts.checkpoint_dir, 'Checkpoint not found!') print(opts.in_path) exists(opts.in_path, 'In path not found!') if os.path.isdir(opts.out_path): exists(opts.out_path, 'out dir not found!') assert opts.batch_size > 0
def check_opts(flags): utils.exists(flags.checkpoint_dir, 'checkpoint_dir not found!') utils.exists(flags.in_path, 'in_path not found!') style_name = FLAGS.checkpoint_dir.split('/')[-1] if not os.path.isdir(os.path.join(flags.out_path, style_name)): print("making_dir : false")
def create_train_data(): train_data_file_name = 'memory_dbow_train' label_data_file_name = 'memory_dbow_label' if utils.exists(train_data_file_name) and utils.exists( label_data_file_name): train_data = utils.load(train_data_file_name) label_data = utils.load(label_data_file_name) else: all_docs = utils.load('all_docs') pairs = [([doc.tag, sentence_num], word_num) for doc in all_docs for sentence_num in doc.detail_sentences_nums for word_num in doc.title_words_nums] detail_pairs = [([doc.tag, sentence_num], word_num) for doc in all_docs for sentence_num in doc.detail_sentences_nums for word_num in doc.detail_words_nums] pairs.extend(detail_pairs) print('Shuffling train data set, size:', len(pairs)) shuffle(pairs) train_data, label_data = [list(pair) for pair in zip(*pairs)] train_data = np.array(train_data) label_data = np.transpose(np.array([label_data])) utils.save(train_data, train_data_file_name) utils.save(label_data, label_data_file_name) return train_data, label_data
def create_train_data(window_size, is_cache=False): if len(proj_name) == 0: train_name = 'train_' + str(window_size) label_name = 'label_' + str(window_size) else: train_name = 'train_' + str(window_size) + '_' + proj_name label_name = 'label_' + str(window_size) + '_' + proj_name if is_cache and utils.exists(train_name) and utils.exists(label_name): train_data = utils.load(train_name) label_data = utils.load(label_name) else: all_docs = utils.load('all_docs') for doc in all_docs: if len(doc.numbers) <= window_size: nums_padded = [1] * (window_size + 1 - len(doc.numbers)) nums_padded.extend(doc.numbers) doc.numbers = nums_padded train_label_pairs = [(doc.numbers[i: i + window_size] + [doc.tag], doc.numbers[i + window_size]) for doc in all_docs for i in range(0, len(doc.numbers) - window_size)] shuffle(train_label_pairs) train_data, label_data = [list(pair) for pair in zip(*train_label_pairs)] train_data = np.array(train_data) label_data = np.transpose(np.array([label_data])) if is_cache: utils.save(train_data, train_name) utils.save(label_data, label_name) return train_data, label_data
def save(self): show_name = None if self.rageid is not None: show_name = self.rageid_show_name(self.rageid) if show_name is not None: show_name = unicode(show_name, 'utf-8') if show_name is None: manual_name = unikeyboard(self.nzbname, 'Enter show name') if manual_name is None: log("Tvshow: save: did not recieve a name for the TV-show") return #show_name = manual_name.decode("utf_8").encode("raw_unicode_escape") show_name = unicode(manual_name, 'utf-8').replace('\n','') strm_path_show = utils.join(self.strm_path, os.path.join(remove_disallowed_filename_chars(show_name),'')) # Check if showname folder exist in path, if not create it. if not utils.exists(strm_path_show): try: utils.mkdir(strm_path_show) except: log("Tvshow: save: failed to create TV-show folder %s" % strm_path_show) return # Check if tvshow.nfo is there, if not, create it. tv_nfo = self.info tv_nfo.path(strm_path_show) # The Episode name has to be picked up by XBMC # regexps episode_name = self.check_episode_name(self.nzbname) if not self.save_nfo_type == "disabled": if self.save_nfo_type == "minimal": tv_nfo.mini() if not utils.exists(os.path.join(strm_path_show, 'tvshow.nfo')): tv_nfo.save_tvshow(show_name) # now, save the episodename.nfo tv_nfo.save_episode(episode_name) strm.StrmFile(strm_path_show, episode_name, self.nzb).save()
def wait_for_nzf(folder, sab_nzo_id, nzf): log("wait_for_nzf: folder: %s sab_nzo_id: %s nzf.filename: %s" % (folder, sab_nzo_id, nzf.filename)) iscanceled = False is_rar_found = False # If rar exist we skip dialogs some_rar = os.path.join(folder, nzf.filename) if utils.exists(some_rar): is_rar_found = True if not is_rar_found: progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Request to SABnzbd succeeded, waiting for ', utils.short_string(nzf.filename)) time_now = time.time() while not is_rar_found: time.sleep(1) if utils.exists(some_rar): # TODO Look for optimization # Wait until the file is written to disk before proceeding size_now = float(nzf.bytes) size_later = 0 while (size_now != size_later) or (size_now == 0) or (size_later == 0): size_now = utils.size(some_rar) if size_now != size_later: time.sleep(0.5) size_later = utils.size(some_rar) is_rar_found = True break nzo = Nzo(sab_nzo_id) m_nzf = nzo.get_nzf_id(nzf.nzf_id) percent, label = utils.wait_for_rar_label(nzo, m_nzf, time_now) progressDialog.update(percent, 'Request to SABnzbd succeeded, waiting for', utils.short_string(nzf.filename), label) if progressDialog.iscanceled(): progressDialog.close() dialog = xbmcgui.Dialog() ret = dialog.select('What do you want to do?', ['Delete job', 'Just download']) # Fix for hang when playing .strm xbmc.Player().stop() xbmc.executebuiltin('Dialog.Close(all, true)') if ret == 0: sabnzbd.nzo_pause(sab_nzo_id) time.sleep(3) delete_ = sabnzbd.nzo_delete_files(sab_nzo_id) if not "ok" in delete_: xbmc.log(delete_) utils.notification("Deleting failed") else: utils.notification("Deleting succeeded") elif ret == 1: # allow the previous select dialog to close time.sleep(1) just_download({'nzoid': sab_nzo_id}) return True progressDialog.close() return iscanceled
def check_opts(opts): """ Check input params via ArgumentParser. Returns: No return value, assert if failed """ exists(opts.checkpoint, "Checkpoint not defined!") exists(opts.in_path, "Input video not defined!")
def wait_for_nzf(folder, sab_nzo_id, nzf): log("wait_for_nzf: folder: %s sab_nzo_id: %s nzf.filename: %s" % (folder, sab_nzo_id, nzf.filename)) iscanceled = False is_rar_found = False # If rar exist we skip dialogs some_rar = os.path.join(folder, nzf.filename) if utils.exists(some_rar): is_rar_found = True if not is_rar_found: progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Request to SABnzbd succeeded, waiting for ', utils.short_string(nzf.filename)) time_now = time.time() while not is_rar_found: time.sleep(1) if utils.exists(some_rar): # TODO Look for optimization # Wait until the file is written to disk before proceeding size_now = int(nzf.bytes) size_later = 0 while (size_now != size_later) or (size_now == 0) or (size_later == 0): size_now = utils.size(some_rar) if size_now != size_later: time.sleep(0.5) size_later = utils.size(some_rar) is_rar_found = True break nzo = sabnzbd.Nzo(SABNZBD, sab_nzo_id) m_nzf = nzo.get_nzf_id(nzf.nzf_id) percent, label = utils.wait_for_rar_label(nzo, m_nzf, time_now) progressDialog.update(percent, 'Request to SABnzbd succeeded, waiting for', utils.short_string(nzf.filename), label) if progressDialog.iscanceled(): progressDialog.close() dialog = xbmcgui.Dialog() ret = dialog.select('What do you want to do?', ['Delete job', 'Just download']) # Fix for hang when playing .strm xbmc.Player().stop() xbmc.executebuiltin('Dialog.Close(all, true)') if ret == 0: pause = SABNZBD.pause_queue(id=sab_nzo_id) time.sleep(3) delete_ = SABNZBD.delete_queue('',sab_nzo_id) if not "ok" in delete_: xbmc.log(delete_) utils.notification("Deleting failed") else: utils.notification("Deleting succeeded") elif ret == 1: # allow the previous select dialog to close time.sleep(1) just_download({'nzoid': sab_nzo_id}) return True progressDialog.close() return iscanceled
def check_opts(flags): utils.exists(flags.style_img, 'style path not found!') utils.exists(flags.train_path, 'train path not found!') utils.exists(flags.test_path, 'test image path not found!') utils.exists(flags.vgg_path, 'vgg network data not found!') assert flags.epochs > 0 assert flags.batch_size > 0 assert flags.print_freq > 0 assert flags.sample_freq > 0 assert flags.content_weight >= 0 assert flags.style_weight >= 0 assert flags.tv_weight >= 0 assert flags.learning_rate >= 0 print(flags.style_img) print(flags.style_img.split('/')[-1][:-4]) style_img_name = flags.style_img.split('/')[-1][:-4] # extract style image name fold_name = os.path.join(flags.checkpoint_dir, style_img_name) if not os.path.isdir(fold_name): os.makedirs(fold_name) fold_name = os.path.join(flags.test_dir, style_img_name) if not os.path.isdir(fold_name): os.makedirs(fold_name)
def check_opts(opts): if not os.path.exists(opts.checkpoint_dir): try: os.makedirs(opts.checkpoint_dir) except ValueError: print("Oops! Already exeists..") exists(opts.style, "style path not found!") exists(opts.train_path, "train path not found!") if opts.test or opts.test_dir: exists(opts.test, "test img not found!") if not os.path.exists(opts.test_dir): try: os.makedirs(opts.test_dir) except ValueError: print("Oops! Already exeists..") exists(opts.vgg_path, "vgg network data not found!") assert opts.epochs > 0 assert opts.batch_size > 0 assert opts.checkpoint_iterations > 0 assert os.path.exists(opts.vgg_path) assert opts.content_weight >= 0 assert opts.style_weight >= 0 assert opts.tv_weight >= 0 assert opts.learning_rate >= 0 assert opts.task_index >= 0
def nzb_cache(type, nzb, nzbname): nzb_path = os.path.join(NZB_CACHE, '%s%s' % (nzbname, '.nzb')) if utils.exists(nzb_path): nzb = nzb_path type = 'add_file' log("nzb_cache: nzb_path: %s" % nzb) return type, nzb
def add_party(request): name = get_val_from_request(request, 'name') if name and not exists('parties', name): add_doc("parties-all", name) add_doc("parties-filtered", name) return "success" return "failure"
def check_opts(opts): exists(opts.checkpoint_dir, "checkpoint dir not found!") exists(opts.summary_dir, "summary dir not found!") exists(opts.style, "style path not found!") exists(opts.train_path, "train path not found!") #if opts.test or opts.test_dir: # exists(opts.test, "test img not found!") # exists(opts.test_dir, "test directory not found!") exists(opts.vgg_path, "vgg network not found!") assert opts.epochs > 0 assert opts.batch_size > 0 assert opts.checkpoint_iterations > 0 assert opts.content_weight >= 0 assert opts.style_weight >= 0 assert opts.tv_weight >= 0 assert opts.learning_rate >= 0
def load_files(files, decoder): fileObjects = [] for f in files: if exists(f) and is_file(f): obj = json.loads(stringfile(f), object_hook=decoder) fileObjects.append(obj) return fileObjects
def run(self, inpath, outpath, n=sys.maxsize): if exists(outpath): exit("Warning: output already exists") elif isdir(inpath): self.classify_directory(inpath, outpath) elif isfile(inpath): self.classify_file(inpath, outpath)
def post(self): name = self.request.get('alias') acct = self.request.get('username') mail = self.request.get('mail') pw = self.request.get('password') icon = self.request.get('icon') status = SUCCESS json_query_data = '' if pw == '' or acct == '' or name == '': status = 502 json_query_data = 'Missing alias, username or password' else: if utils.exists(User, [['username', acct]]): status = 503 json_query_data = 'Already existing account' else: # Create the User object and return its key newuser = User() newuser.name = name newuser.username = acct newuser.mail = mail newuser.icon = icon c = Credentials() c.set_dk(pw) newuser.password = c pkey = newuser.put() json_query_data = str(pkey.id()) utils.write_output(self, json_query_data, status)
def load_playlist_from_elements(self, elements): self.global_options = elements.get('global_options', {}) self.marked_items = set() self.file_options = {} self.missing_files = set() self.global_options_frame.clear() self.file_options_frame.clear() for file in elements.get('files', []): if file.get('options', {}) != {}: self.file_options[file['filename']] = file['options'] full_path = os.path.join(self.get_sd_card_root(), file['filename']) if not utils.exists(full_path): self.missing_files.add(file['filename']) self.marked_items.add(file['filename']) self.found_files_frame.add_missing_file(file['filename']) self.found_files_frame.refresh_files_display() self.found_files_frame.select_none() if elements.get('global_options', {}) != {}: for k, v in elements['global_options'].items(): self.add_option(True, k, v) if len(self.missing_files) > 0: tkMessageBox.showwarning( 'Warning', '''Some files from the playlist couldn't be found. They were highlighted in red.\n You can put them back on the SD card and reload the playlist to clear the view.\n If you save a playlist while some items are missing, these items won't be saved as part of the playlist. ''')
def check_file_system_mounted(): """ Check if file server host is online, and project folder is mounted :rtype: bool """ from utils import exists return check_file_server() and exists(settings.MEDIA_ROOT)
def save_strm(nzbname, url): log("save_strm: nzbname: %s url: %s" % (nzbname, url)) strm2lib.save_strm(__settings__, nzbname, url) if SAVE_NZB and utils.exists(NZB_CACHE): nzb_path = utils.join(NZB_CACHE, '%s%s' % (nzbname, '.nzb')) log("save_strm: nzb_path: %s" % nzb_path) m_nzb.save(url, nzb_path)
def login(): body = request.get_json() user = User.query.filter_by(**body) if exists(user): data = {**to_dict(user.first(), ['password'])} return jsonify({"status": True, "data": data}) return jsonify({"status": False})
def save(self): strm_path = utils.join(self.folder, ('%s.strm' % self.nzbname)) nzb_path = utils.join(self.folder, ('%s.nzb' % self.nzbname)) nzb = urllib.quote_plus(self.nzb) nzbname = urllib.quote_plus(self.nzbname) if utils.exists(strm_path): log("StrmFile: save: replacing .strm file: %s" % strm_path.encode("utf_8")) line = "plugin://plugin.program.pneumatic/?mode=strm&nzb=" + nzb +\ "&nzbname=" + nzbname try: utils.write(strm_path, line, 'wb') except: log("StrmFile: save: failed to create .strm file: %s" % strm_path.encode("utf_8")) if utils.exists(nzb_path): log("StrmFile: save: replacing .nzb file: %s" % nzb_path.encode("utf_8")) m_nzb.save(self.nzb, nzb_path)
def check_opts(opts): # exists(opts.checkpoint_dir, "checkpoint dir not found!") os.makedirs(opts.checkpoint_dir, exist_ok=True) exists(opts.style, "style path not found!") exists(opts.train_path, "train path not found!") if opts.test or opts.test_dir: exists(opts.test, "test img not found!") exists(opts.test_dir, "test directory not found!") exists(opts.vgg_path, "vgg network data not found!") assert opts.epochs > 0 assert opts.batch_size > 0 assert opts.checkpoint_iterations > 0 assert os.path.exists(opts.vgg_path) assert opts.content_weight >= 0 assert opts.style_weight >= 0 assert opts.tv_weight >= 0 assert opts.learning_rate >= 0
def main(): parser = argparse.ArgumentParser(description='A Simple Plot Generator') parser.add_argument('-t', '--type', help='Type of plot. Valid types are: [line | bar]', required=True) parser.add_argument( '-o', '--objective', help='Tuning function objective.' 'Valid objectives are: [runtime | energy | edp | ed2p | mlups]', required=True) parser.add_argument('-d', '--directories', nargs='*', help='Result directories', required=True) args = vars(parser.parse_args()) objectives = {'runtime', 'energy', 'edp', 'ed2p', 'mlups'} plot_types = {'line': lineplot, 'bar': barplot} objective_exist = exists(args.values(), objectives) plot_type_exist = exists(args.values(), plot_types) if not objective_exist: print 'Valid objectives are: [runtime | energy | edp | ed2p | mlups]' sys.exit(2) if not plot_type_exist: print 'Valid plot types are: [line | bar]' sys.exit(2) # Get the sys cfg for the input directories sys_cfgs = [] for directory in args['directories']: delete_ds_store(directory) sys_cfgs.append(static_sys_cfgs(directory)) # Plot cfg pcfg = plot_cfg(args['objective'].lower(), objectives, args['type']) # Plot plot_types[args['type']](args['objective'].lower(), sys_cfgs, pcfg)
def download_forecast_data(target_date, force=False): """Download forecast data for the given target date. If force is False, data is only downloaded if it doesn't already exist. """ start_date = end_date = target_date target_date_formatted = start_date.strftime(DATE_FORMAT) folder = os.path.join(settings.DATA_FOLDER, 'MyOcean', 'Forecast') create_if_not_exists(folder) datasets = [ { # chlorophile, nitrate, phosphate, oxygen... 'service': 'http://purl.org/myocean/ontology/service/database#MEDSEA_ANALYSIS_FORECAST_BIO_006_006-TDS', 'product': 'myov04-med-ogs-bio-an-fc', 'time': '12:00:00', }, { # salinity 'service': 'http://purl.org/myocean/ontology/service/database#MEDSEA_ANALYSIS_FORECAST_PHYS_006_001_a-TDS', 'product': 'myov05-med-ingv-sal-an-fc-dm', 'time': '00:00:00' }, { # temperature 'service': 'http://purl.org/myocean/ontology/service/database#MEDSEA_ANALYSIS_FORECAST_PHYS_006_001_a-TDS', 'product': 'myov05-med-ingv-tem-an-fc-dm', 'time': '00:00:00' }, { # temperature 'service': 'http://purl.org/myocean/ontology/service/database#MEDSEA_ANALYSIS_FORECAST_PHYS_006_001_a-TDS', 'product': 'myov05-med-ingv-cur-an-fc-dm', 'time': '00:00:00', 'variables': ['vozocrtx', 'vomecrty'] } ] for dataset in datasets: filename = '%s-%s.nc' % (dataset['product'], target_date_formatted) if not exists(filename, folder) or force: try: download_myocean_data( service=dataset['service'], product=dataset['product'], variables=dataset.get('variables'), time_start='%s %s' % (start_date, dataset['time']), time_end='%s %s' % (end_date, dataset['time']), folder=folder, filename=filename) except MaxTriesExceededException: logger.error("Download of file {} from MyOcean failed.".format( filename)) else: print( 'File %s already exists, skipping download... (use force=True to override).' % filename)
def check_opts(opts): exists(opts.checkpoint_dir, "checkpoint dir not found!") exists(opts.style_image, "style image path not found!") exists(opts.train_path, "train path not found!") exists(opts.vgg_path, "vgg network data not found!") assert opts.epochs > 0 assert opts.batch_size > 0 assert opts.checkpoint_iterations > 0 assert os.path.exists(opts.vgg_path) assert opts.content_weight >= 0 assert opts.style_weight >= 0 assert opts.tv_weight > 0 assert opts.learning_rate >= 0
def get_moves(self): """ Get all possible moves from the current position on the board. """ combinations = self.get_combinations(self._x_pos, self._y_pos) possible = [] for combination in combinations: if exists(self.board, combination): possible.append(combination) return possible
def __init__(self, nfo_path): self.nfo_path = nfo_path filename_movie = utils.join(self.nfo_path, ("movie.nfo")) filename_tvshow = utils.join(self.nfo_path, ("episode.nfo")) self.is_episode = False if utils.exists(filename_movie): filename = filename_movie elif utils.exists(filename_tvshow): filename = filename_tvshow self.is_episode = True try: out = parseString(utils.read(filename, "r")) except: log(("ReadNfoLabels: could not open: %s.nfo") % (xbmc.translatePath(self.nfo_path))) out = None if out: self.info_labels = self._get_info_labels(out) else: self.info_labels = {"title": os.path.basename(self.nfo_path)} self.thumbnail = utils.join(self.nfo_path, "folder.jpg") self.fanart = utils.join(self.nfo_path, "fanart.jpg")
def download_forecast_data(target_date, force=False): """Download forecast data for the given target date. If force is False, data is only downloaded if it doesn't already exist. """ start_date = end_date = target_date target_date_formatted = start_date.strftime(DATE_FORMAT) folder = os.path.join(settings.DATA_FOLDER, 'MyOcean', 'Forecast') create_if_not_exists(folder) datasets = [ { # chlorophile, nitrate, phosphate, oxygen... 'service': 'http://purl.org/myocean/ontology/service/database#MEDSEA_ANALYSIS_FORECAST_BIO_006_006-TDS', 'product': 'myov04-med-ogs-bio-an-fc', 'time': '12:00:00', }, { # salinity 'service': 'http://purl.org/myocean/ontology/service/database#MEDSEA_ANALYSIS_FORECAST_PHYS_006_001_a-TDS', 'product': 'myov05-med-ingv-sal-an-fc-dm', 'time': '00:00:00' }, { # temperature 'service': 'http://purl.org/myocean/ontology/service/database#MEDSEA_ANALYSIS_FORECAST_PHYS_006_001_a-TDS', 'product': 'myov05-med-ingv-tem-an-fc-dm', 'time': '00:00:00' }, { # temperature 'service': 'http://purl.org/myocean/ontology/service/database#MEDSEA_ANALYSIS_FORECAST_PHYS_006_001_a-TDS', 'product': 'myov05-med-ingv-cur-an-fc-dm', 'time': '00:00:00', 'variables': ['vozocrtx', 'vomecrty'] } ] for dataset in datasets: filename = '%s-%s.nc' % (dataset['product'], target_date_formatted) if not exists(filename, folder) or force: try: download_myocean_data( service=dataset['service'], product=dataset['product'], variables=dataset.get('variables'), time_start='%s %s' % (start_date, dataset['time']), time_end='%s %s' % (end_date, dataset['time']), folder=folder, filename=filename) except MaxTriesExceededException: logger.error("Download of file {} from MyOcean failed.".format(filename)) else: print('File %s already exists, skipping download... (use force=True to override).' % filename)
def __init__(self, nfo_path): self.nfo_path = nfo_path filename_movie = utils.join(self.nfo_path, ('movie.nfo')) filename_tvshow = utils.join(self.nfo_path, ('episode.nfo')) self.is_episode = False if utils.exists(filename_movie): filename = filename_movie elif utils.exists(filename_tvshow): filename = filename_tvshow self.is_episode = True try: out = parseString(utils.read(filename, 'r')) except: log(("ReadNfoLabels: could not open: %s.nfo") % \ (xbmc.translatePath(self.nfo_path))) out = None if out: self.info_labels = self._get_info_labels(out) else: self.info_labels = {'title': os.path.basename(self.nfo_path)} self.thumbnail = utils.join(self.nfo_path, 'folder.jpg') self.fanart = utils.join(self.nfo_path, 'fanart.jpg')
def virtualenv(config): if not exists(config.func, config["env_path"]): raise DatabaseError(u"Virtualenv не создан.") system = platform.system() if "Windows" == system: path = "%s/Scripts/activate.bat" % config["env_path"] path = path.replace("./", "") path = path.replace("/", "\\") with prefix(path): yield elif "Linux" == system or "Darwin" == system: with prefix("source %s/bin/activate" % config["env_path"]): yield
def save(self): show_name = None if self.rageid is not None: show_name = self.rageid_show_name(self.rageid) if show_name is not None: show_name = unicode(show_name, 'utf-8') if show_name is None: manual_name = unikeyboard(self.nzbname, 'Enter show name') if manual_name is None: log("Tvshow: save: did not recieve a name for the TV-show") return #show_name = manual_name.decode("utf_8").encode("raw_unicode_escape") show_name = unicode(manual_name, 'utf-8').replace('\n', '') strm_path_show = utils.join( self.strm_path, os.path.join(remove_disallowed_filename_chars(show_name), '')) # Check if showname folder exist in path, if not create it. if not utils.exists(strm_path_show): try: utils.mkdir(strm_path_show) except: log("Tvshow: save: failed to create TV-show folder %s" % strm_path_show) return # Check if tvshow.nfo is there, if not, create it. tv_nfo = self.info tv_nfo.path(strm_path_show) # The Episode name has to be picked up by XBMC # regexps episode_name = self.check_episode_name(self.nzbname) if not self.save_nfo_type == "disabled": if self.save_nfo_type == "minimal": tv_nfo.mini() if not utils.exists(os.path.join(strm_path_show, 'tvshow.nfo')): tv_nfo.save_tvshow(show_name) # now, save the episodename.nfo tv_nfo.save_episode(episode_name) strm.StrmFile(strm_path_show, episode_name, self.nzb).save()
def strm_init(params): log("strm_init: params: %s" % params) strm_path = unicode(xbmc.getInfoLabel("ListItem.FileNameAndPath"), 'utf-8') log("strm_init: strm_path: %s" % strm_path) strm_base = os.path.dirname(strm_path) nzbname = params['nzbname'] extensions = ['nzb', 'nzb.zip', 'nzb.gz'] for ext in extensions: nzbname_ext = "%s.%s" % (utils.join(strm_base, nzbname), ext) if utils.exists(nzbname_ext): log("strm_init: exists: %s" % nzbname_ext) params['nzb'] = nzbname_ext params['type'] = 'add_file' return params
def getdata(): target = lambda vidname: f"static/temp/{Path(vidname).stem}-canvas.MP4" videos = None result = {'data': utils.getdatasource()} activefolder = [False] * len(result['data']) default = True vidname = None default = False videos, paths = utils.getvidlist(request.args.get('datafolder')) active = 0 if request.args.get('vidname'): vidname = f"{request.args.get('vidname').split('.')[1]}.MP4" active = int(request.args.get('vidname').split('.')[0]) - 1 utils.getvideo(vidname) result.update(utils.getstats(vidname, len(videos))) total = len(videos) selected = [False] * total selected[active] = True utils.getvideo(videos[active]) activefolder[result['data'].index(request.args.get('datafolder'))] = True status = [utils.exists(v) for v in videos] videos = [{ 'sno': str(i + 1).zfill(3), 'name': v, 'target': target(v), 'done': s, 'active': a, 'path': p } for v, i, s, a, p in zip(videos, range(total), status, selected, paths)] for v in videos: if v['active']: result.update(utils.getstats(v['name'], total)) if default and utils.getdatasource(): activefolder[0] = True if videos: result['videos'] = videos result['total'] = len(videos) if vidname: result['target'] = f"static/temp/{Path(vidname).stem}-canvas.MP4" result['vdata'] = [{ 'folder': f, 'active': a } for f, a in zip(result['data'], activefolder)] # print(result.keys()) return result
def strm_init(params): log("strm_init: params: %s" % params) strm_path = unicode(xbmc.getInfoLabel("ListItem.FileNameAndPath"), 'utf-8') log("strm_init: strm_path: %s" % strm_path) strm_base = os.path.dirname(strm_path) nzbname = params['nzbname'] extensions = ['nzb', 'zip', 'gz'] for ext in extensions: nzbname_ext = "%s.%s" % (utils.join(strm_base, nzbname), ext) if utils.exists(nzbname_ext): log("strm_init: exists: %s" % nzbname_ext) params['nzb'] = nzbname_ext params['type'] = 'add_file' return params
def check_and_add(subdomains): new_subdomains = {} for c,j in enumerate(subdomains): if not utils.exists(j): live = checks.check_if_live(j) if live: utils.add(j, live=True, cname="") new_subdomains[c] = {"subdomain":j,"title":live} else: utils.add(j, live=False, cname="") new_subdomains[c] = {"subdomain":j,"title":""} return new_subdomains
def write_to_file(self): ''' Save tag information to file. ''' if self.get_scheme() != "file": self.last_error = self.get_scheme() + " " + "Scheme not supported" return False if not utils.exists(self.get("uri")): self.last_error = self.get_filename() + " doesn't exist" return False if not os.access(self.get_path(), os.W_OK): self.last_error = self.get_filename( ) + " doesn't have enough permission" return False try: audio = common.MutagenFile(self.get_path(), common.FORMATS) tag_keys_override = None if audio is not None: if audio.tags is None: audio.add_tags() tag_keys_override = TAGS_KEYS_OVERRIDE.get( audio.__class__.__name__, None) for file_tag, tag in TAG_KEYS.iteritems(): if tag_keys_override and tag_keys_override.has_key( file_tag): file_tag = tag_keys_override[file_tag] if self.get(tag): value = unicode(self.get(tag)) audio[file_tag] = value else: try: del (audio[file_tag]) # TEST except KeyError: pass audio.save() else: raise "w:Song:MutagenTag:No audio found" except Exception, e: # print traceback.format_exc() print "W: Error while writting (" + self.get( "uri") + ")Tracback :", e self.last_error = "Error while writting" + ": " + self.get_filename( ) return False
def predict_forecast(target_date, force=False): """Predict the presence of medusae using a previously calibrated model. If force is False, it is only predicted the output file doesn't already exist. """ for a in settings.TUNEZ_DATA: filename = '{}EF-{}.csv'.format(a, target_date.strftime(DATE_FORMAT)) folder = os.path.join(settings.DATA_FOLDER, 'Projections') create_if_not_exists(folder) if not exists(filename, folder) or force: os.chdir(settings.DATA_FOLDER) with open(os.path.join(BASE_DIR, 'R', 'Tunisia_MedJellyRisk_{}.R'.format(a)), 'r') as inputfile: call(["R", "--no-save", "--args", target_date.strftime(DATE_FORMAT)], stdin=inputfile) else: print('\nFile %s already exists, skipping prediction... (use force=True to override).' % filename)
def preprocess_forecast_data(target_date, force=False): """Preprocess forecast environmental data from MyOcean using R. If force is False, it is only preprocessed if the output file doesn't already exist. """ filename = 'Forecast_Env-%s.csv' % target_date.strftime(DATE_FORMAT) folder = os.path.join(settings.DATA_FOLDER, 'MyOcean', 'Forecast') create_if_not_exists(folder) if not exists(filename, folder) or force: os.chdir(os.path.join(settings.DATA_FOLDER)) with open(os.path.join(BASE_DIR, 'R', 'ExtractData_MyOcean.R'), 'r') as inputfile: call(["R", "--no-save", "--args", target_date.strftime(DATE_FORMAT)], stdin=inputfile) else: print('\nFile %s already exists, skipping preprocessing... (use force=True to override).' % filename)
def write_to_file(self): ''' Save tag information to file. ''' if self.get_scheme() != "file": self.last_error = self.get_scheme() + " " + "Scheme not supported" return False if not utils.exists(self.get("uri")): self.last_error = self.get_filename() + " doesn't exist" return False if not os.access(self.get_path(), os.W_OK): self.last_error = self.get_filename() + " doesn't have enough permission" return False try: audio = common.MutagenFile(self.get_path(), common.FORMATS) tag_keys_override = None if audio is not None: if audio.tags is None: audio.add_tags() tag_keys_override = TAGS_KEYS_OVERRIDE.get(audio.__class__.__name__, None) for file_tag, tag in TAG_KEYS.iteritems(): if tag_keys_override and tag_keys_override.has_key(file_tag): file_tag = tag_keys_override[file_tag] if self.get(tag): value = unicode(self.get(tag)) audio[file_tag] = value else: try: del(audio[file_tag]) # TEST except KeyError: pass audio.save() else: raise "w:Song:MutagenTag:No audio found" except Exception, e: # print traceback.format_exc() print "W: Error while writting ("+self.get("uri")+")\nTracback :",e self.last_error = "Error while writting" + ": " + self.get_filename() return False
def save(self): if not utils.exists(self.strm_path): try: utils.mkdir(self.strm_path) except: log("Movie: save: failed to create folder %s" % self.strm_path) return movie_nfo = self.info movie_nfo.path(self.strm_path) if not self.save_nfo_type == "disabled": if self.save_nfo_type == "minimal": movie_nfo.mini() else: movie_nfo.save() if self.save_poster: movie_nfo.save_poster() if self.save_fanart: movie_nfo.save_fanart() strm.StrmFile(self.strm_path, self.nzbname, self.nzb).save()
def init(): global config global APACHE global WSGI if 'testing' == config.type: path = config['project'] name = config['name'] name_underline = name.replace('.', '_') name_short = name[:name.find('.')] APACHE = APACHE.format(global_param='%{GLOBAL}', name=name, name_short=name_short, name_underline=name_underline) WSGI = WSGI.format(name=name, name_short=name_short, name_underline=name_underline) if exists(config.func, path): error('Каталог проекта уже создан %s' % path) config.func('mkdir -p %s' % path) config.func('mkdir -p %s/app' % path) config.func('mkdir -p %s/env' % path) config.func('mkdir -p %s/configs' % path) config.func('mkdir -p %s/logs' % path) config.func('mkdir -p %s/var' % path) config.func('mkdir -p %s/static' % path) config.func('mkdir -p %s/media' % path) # config.func('echo "%s" > %s/configs/%s' % (APACHE, path, name)) config.func('echo "%s" > %s/configs/wsgi.py' % (WSGI, path)) # if exists(config.func, '/etc/apache2/sites-available/%s' % name): # sudo('rm /etc/apache2/sites-available/%s' % name) # sudo('cd /etc/apache2/sites-available && ln -s %s/configs/%s .' % (path, name)) # sudo('a2ensite %s' % name) config.func('cd %s && git clone [email protected]:sevenquark/%s.git app' % (path, name_short)) virtualenv_init() requirements() create_db() sync() static() # sudo('service apache2 reload') else: virtualenv_init() requirements() create_db() sync()
def add_local_nzb(): log("add_local_nzb:") if not utils.exists(NZB_FOLDER): __settings__.openSettings() return None dialog = xbmcgui.Dialog() nzb_file = dialog.browse(1, 'Pick a NZB', 'files', '.nzb', False, False, NZB_FOLDER) # XBMC outputs utf-8 path = unicode(nzb_file, 'utf-8') log("add_local_nzb: path: %s" % path) if not utils.isfile(path): return None else: params = dict() # Fixing the naming of nzb according to SAB rules params['nzbname'] = m_nzb.Nzbname(os.path.basename(path)).final_name params['nzb'] = path if IS_SAB_LOCAL: params['type'] = 'add_local' else: params['type'] = 'add_file' return params
def check_opts(opts): exists(opts.checkpoint) exists(opts.out)
def __init__(self, strm_path): self.cache_path = utils.join(strm_path, 'rageid.cache') if not utils.exists(self.cache_path): pickle.dump( dict(), open( self.cache_path, "wb" ) )
def exists(self): return utils.exists(self.get("uri"))
def requirements(self): with virtualenv(self.config): if exists(self.config.func, "config/requirements.txt"): self.config.func("pip install -r config/requirements.txt")
def play_video(params): log("play_video: params: %s" % params) get = params.get mode = get("mode") file_list = get("file_list") file_list = utils.unquote_plus(file_list).split(";") play_list = get("play_list") play_list = utils.unquote_plus(play_list).split(";") folder = get("folder") folder = utils.unquote_plus(folder) # We might have deleted the path if utils.exists(folder): if len(file_list) > 0 and not play_list[1].endswith(play_list[0]): # we trick xbmc to play avi by creating empty rars if the download is only partial utils.write_fake(file_list, folder) # Prepare potential file stacking if (len(play_list) > 2): rar = [] for arch_rar, movie_file in zip(play_list[0::2], play_list[1::2]): raruri = "rar://" + utils.rarpath_fixer(folder, arch_rar) + "/" + movie_file rar.append(raruri) raruri = 'stack://' + ' , '.join(rar) else: raruri = "rar://" + utils.rarpath_fixer(folder, play_list[0]) + "/" + play_list[1] uri = raruri else: # we have a plain file if (len(play_list) > 2): uri = "stack://%s" % ' , '.join(play_list[1::2]) else: uri = play_list[1] log("play_video: uri: %s" % uri) info = nfo.NfoLabels() item = xbmcgui.ListItem(info.info_labels['title'], iconImage='DefaultVideo.png', thumbnailImage=info.thumbnail) item.setInfo(type="Video", infoLabels=info.info_labels) item.setPath(uri) item.setProperty("IsPlayable", "true") xbmcplugin.setContent(HANDLE, 'movies') wait = 0 player = xbmcplayer.XBMCPlayer(xbmc.PLAYER_CORE_AUTO) player.sleep(1000) if mode == MODE_AUTO_PLAY or mode == MODE_LIST_PLAY: player.play( uri, item ) log("play_video: player.play uri: %s" % uri) else: xbmcplugin.setResolvedUrl(handle=HANDLE, succeeded=True, listitem=item) log("play_video: setResolvedUrl uri: %s" % uri) removed_fake = False while player.is_active: player.sleep(500) wait+= 1 if player.is_playing and not removed_fake: utils.remove_fake(file_list, folder) removed_fake = True if player.is_stopped: the_end(folder, player.is_stopped) player.is_active = False elif player.is_ended: the_end(folder) player.is_active = False elif wait >= 6000 and not player.isPlayingVideo(): utils.notification("Error playing file!") break if not removed_fake: utils.remove_fake(file_list, folder) else: utils.notification("File deleted") time.sleep(1) xbmc.executebuiltin("Action(ParentDir)") return
def pre_play(nzbname, **kwargs): log("pre_play: nzbname: %s kwargs: %s" % (nzbname, kwargs)) mode = kwargs.get('mode', None) sab_nzo_id = kwargs.get('nzo', None) iscanceled = False folder = utils.join(INCOMPLETE_FOLDER, nzbname) folder_one = folder + '.1' if utils.exists(folder_one): folder = folder_one sab_file_list = [] multi_arch_list = [] if sab_nzo_id is None: sab_nzo_id_history = SABNZBD.nzo_id_history(nzbname) nzf_list = utils.dir_to_nzf_list(folder, sabnzbd) else: nzo = sabnzbd.Nzo(SABNZBD, sab_nzo_id) nzf_list = nzo.nzf_list() sab_nzo_id_history = None sorted_rar_nzf_list = utils.sorted_rar_nzf_file_list(nzf_list) # TODO # If we cant find any rars in the queue, we have to wait for SAB # and then guess the names... # if len(nzf_list) == 0: # iscanceled = get_nzf(folder, sab_nzo_id, None) is_movie_in_rar = True if len(sorted_rar_nzf_list) == 0: # look for other playable files multi_nzf_list = sorted_nzf_list = utils.sorted_movie_nzf_file_list(nzf_list) if len(multi_nzf_list) > 0: is_movie_in_rar = False else: multi_nzf_list = utils.sorted_multi_arch_nzf_list(sorted_rar_nzf_list) sorted_nzf_list = sorted_rar_nzf_list clean_sorted_nzf_list = utils.nzf_diff_list(sorted_nzf_list, multi_nzf_list) if len(multi_nzf_list) > 0: # Loop though all multi archives and add file to the play_list = [] for nzf in multi_nzf_list: if sab_nzo_id is not None: response = set_streaming(sab_nzo_id) log("pre_play: set_streaming: %s" % response) t = Thread(target=nzf_to_bottom, args=(sab_nzo_id, nzf_list, sorted_nzf_list,)) t.start() iscanceled = get_nzf(folder, sab_nzo_id, nzf) if iscanceled: break else: if is_movie_in_rar: # RAR ANALYSYS # in_rar_file_list = utils.rar_filenames(folder, nzf.filename) movie_list = utils.sort_filename(in_rar_file_list) log("pre_play: folder: %s nzf.filename: %s in_rar_file_list: %s" % (folder, nzf.filename, in_rar_file_list)) else: movie_list = [os.path.join(folder, nzf.filename)] # Make sure we have a movie if not (len(movie_list) >= 1): utils.notification("Not a movie!") log("pre_play: no movie in movie_list") break # Who needs sample? movie_no_sample_list = utils.no_sample_list(movie_list) # If auto play is enabled we skip samples in the play_list if AUTO_PLAY and mode is not MODE_INCOMPLETE_LIST: for movie_file in movie_no_sample_list: play_list.append(nzf.filename) play_list.append(movie_file) else: for movie_file in movie_list: play_list.append(nzf.filename) play_list.append(movie_file) # If the movie is a .mkv or .mp4 we need the last rar if utils.is_movie_mkv(movie_list) and sab_nzo_id and is_movie_in_rar: # If we have a sample or other file, the second rar is also needed.. if len(in_rar_file_list) > 1: second_nzf = clean_sorted_nzf_list[1] iscanceled = get_nzf(folder, sab_nzo_id, second_nzf) last_nzf = clean_sorted_nzf_list[-1] iscanceled = get_nzf(folder, sab_nzo_id, last_nzf) if iscanceled: break if iscanceled: log("pre_play: get_nzf: canceled") return else: rar_file_list = [x.filename for x in sorted_nzf_list] if (len(rar_file_list) >= 1) or (not is_movie_in_rar and len(movie_list) >= 1): if AUTO_PLAY and ( mode is None or mode is MODE_STRM): video_params = dict() if not mode: video_params['mode'] = MODE_AUTO_PLAY else: video_params['mode'] = MODE_STRM video_params['play_list'] = utils.quote_plus(';'.join(play_list)) video_params['file_list'] = utils.quote_plus(';'.join(rar_file_list)) video_params['folder'] = utils.quote_plus(folder) return play_video(video_params) else: return playlist_item(play_list, rar_file_list, folder, sab_nzo_id, sab_nzo_id_history) else: utils.notification("No rar\'s in the NZB!") log("pre_play: no rar\'s in the NZB") return else: utils.notification("No playable files found!") log("pre_play: no playable files found") return
def is_nzb_home(params): log("is_nzb_home: params: %s" % params) get = params.get nzb = utils.unquote_plus(get("nzb")) nzbname = m_nzb.Nzbname(utils.unquote_plus(get("nzbname"))).final_name folder = utils.join(INCOMPLETE_FOLDER, nzbname) iscanceled = False type = get('type', 'addurl') sab_nzo_id = SABNZBD.nzo_id(nzbname, nzb) log("is_nzb_home: folder: %s sab_nzo_id: %s" %(folder, sab_nzo_id)) if not utils.dir_exists(folder, sab_nzo_id): progressDialog = xbmcgui.DialogProgress() progressDialog.create('Pneumatic', 'Sending request to SABnzbd') category = get_category() if type == 'addurl': type, nzb = nzb_cache(type, nzb, nzbname) # SABnzbd and URI should be latin-1 encoded if type == 'addurl': response = SABNZBD.addurl(nzb.encode('latin-1'), nzbname, category=category) elif type == 'add_local': response = SABNZBD.add_local(nzb.encode('latin-1'), category=category) elif type == 'add_file': response = SABNZBD.add_file(nzb.encode('latin-1'), category=category) log("is_nzb_home: type: %s response: %s" %(type, response)) if "ok" in response: progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download') seconds = 0 #SABnzbd uses nzb url as name until it has downloaded the nzb file sab_nzo_id_init = SABNZBD.nzo_id(nzbname, nzb) log("is_nzb_home: sab_nzo_id_init: %s" % sab_nzo_id_init) while not (sab_nzo_id and utils.exists(folder)): sab_nzo_id = SABNZBD.nzo_id(nzbname) label = str(seconds) + " seconds" log("is_nzb_home: waiting for nzb: sab_nzo_id: %s for: %s" % (sab_nzo_id, label)) progressDialog.update(0, 'Request to SABnzbd succeeded', 'waiting for nzb download', label) if progressDialog.iscanceled(): progressDialog.close() log("is_nzb_home: waiting for nzb: canceled") # Fix for hang when playing .strm time.sleep(1) xbmc.Player().stop() if sab_nzo_id is None and sab_nzo_id_init is not None: sab_nzo_id = sab_nzo_id_init #Trying to delete both the queue and history if sab_nzo_id is not None: pause = SABNZBD.pause_queue(id=sab_nzo_id) log("is_nzb_home: pause: sab_nzo_id: %s msg: %s" % (sab_nzo_id, pause)) time.sleep(3) delete_msg = SABNZBD.delete_queue('',sab_nzo_id) log("is_nzb_home: delete_queue: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg)) if not "ok" in delete_msg: delete_msg = SABNZBD.delete_history('',sab_nzo_id) log("is_nzb_home: delete_history: sab_nzo_id: %s nzbname: %s msg: %s" % (sab_nzo_id, nzbname, delete_msg)) else: log("is_nzb_home: failed removing %s from the queue" % nzbname) iscanceled = True break time.sleep(1) seconds += 1 if not iscanceled: switch = SABNZBD.switch(0, '', sab_nzo_id) log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch)) if not "ok" in switch: progressDialog.update(0, 'Failed to prioritize the nzb!') time.sleep(1) # Dont add meta data for local nzb's if type == 'addurl': t = Thread(target=save_nfo, args=(folder,)) t.start() progressDialog.close() return True, sab_nzo_id else: progressDialog.close() return False, sab_nzo_id else: progressDialog.close() log("is_nzb_home: failed adding nzb to SAB") # Fix for hang when playing .strm xbmc.Player().stop() utils.notification("Request to SABnzbd failed!") return False, sab_nzo_id else: switch = SABNZBD.switch(0,'' , sab_nzo_id) log("is_nzb_home: switch: sab_nzo_id: %s msg: %s" % (sab_nzo_id, switch)) if not "ok" in switch: utils.notification("Failed to prioritize the nzb!") # TODO make sure there is also a NZB in the queue return True, sab_nzo_id
def is_cached(self, key, cls): if (cls in self.__registry): path = self.__build_path(key, cls) return exists(path) else: return False
def req_up(): with virtualenv(config): if exists(config.func, 'config/requirements.txt'): config.func('pip install --upgrade -r config/requirements.txt')
def check_opts(opts): exists(opts.checkpoint_dir, 'Checkpoint not found!') exists(opts.in_path, 'In path not found!') if os.path.isdir(opts.out_path): exists(opts.out_path, 'out dir not found!') assert opts.batch_size > 0
def check_opts(opts): exists(opts.checkpoint_dir, "checkpoint dir not found!") exists(opts.style, "style path not found!") exists(opts.train_path, "train path not found!") if opts.test or opts.test_dir: exists(opts.test, "test img not found!") exists(opts.test_dir, "test directory not found!") exists(opts.vgg_path, "vgg network data not found!") assert opts.epochs > 0 assert opts.batch_size > 0 assert opts.checkpoint_iterations > 0 assert os.path.exists(opts.vgg_path) assert opts.content_weight >= 0 assert opts.style_weight >= 0 assert opts.tv_weight >= 0 assert opts.learning_rate >= 0
def exists(self): if self.get_type() == "cue": return utils.exists(self.get("real_uri")) elif self.get_type() == "audiocd": return os.path.exists(self.get("uri").split("#")[1]) return utils.exists(self.get("uri"))