def initialize(bb, augment, cache, dataset_name, capital_word_shape=False): """Initialize LNEx using the elastic index""" geo_locations = None geo_info = None extended_words3 = None while geo_info is None: try: # retrieve the records from OSM based on the passed bb geo_locations, geo_info, extended_words3 = osm_gazetteer.build_bb_gazetteer(bb, augment) except elasticsearch.exceptions.ConnectionTimeout: pass # initialize LNEx using the retrieved (possible augmented) location names core.initialize(geo_locations, extended_words3, capital_word_shape) if cache: folder_abs_path = os.path.abspath(os.path.join(os.path.dirname( __file__), '..', "_Data", "Cached_Gazetteers")) if not os.path.exists(folder_abs_path): os.makedirs(folder_abs_path) with open(folder_abs_path+"/"+dataset_name+"_geo_locations.json", "w") as f: json.dump(geo_locations, f) with open(folder_abs_path+"/"+dataset_name+"_geo_info.json", "w") as f: json.dump(geo_info, f) with open(folder_abs_path+"/"+dataset_name+"_extended_words3.json", "w") as f: json.dump(extended_words3, f) return geo_info
def start(): log.info(":SYS:Starting W.I.L.L") log.info(":SYS:Loaded configuration file and started logging") log.info(":SYS:Connecting to database") log.info(":SYS:Starting W.I.L.L core") core.initialize(db) log.info(":SYS:Starting sessions parsing thread") core.sessions_monitor(db) log.info(":SYS:Connected to database, running server")
def initialize(stations_filename, devinfo_filename): dev.initialize() dev.cprintln("\nHardware component:") dev.cprint(" loading", devinfo_filename, "...") d, msg = dev.load_json(devinfo_filename) dev.cprintln(msg) devid = d.get("devID", "unknown") dev.cprintln(" ID:", devid) devmodel = d.get("model", "unknown") dev.cprintln(" model:", devmodel) dev.cprintln("\nData component:") # dev.cprintln(" loading", stations_filename, "...") return devid
def cli(ctx, webserver, profile, debug, config, report, dry_run, enabled_sites, watched_paths, comment): from core import initialize, CONFIG CONFIG = initialize(config, lvl=debug) import core.autoup if isinstance(enabled_sites, str): enabled_sites = enabled_sites.split() if isinstance(watched_paths, str): watched_paths = watched_paths.split() lvl = 'debug' if debug else 'info' if profile: pass ctx.obj = core.autoup.Autoup(config_file=CONFIG, enabled_sites=enabled_sites, watched_paths=watched_paths, loglevel=lvl, dry_run=dry_run, report=report, comment=comment)
def run(self): signal.signal(signal.SIGINT, self.exit) signal.signal(signal.SIGTERM, lambda signum, stack_frame: sys.exit(1)) try: core.initialize() core.run() except KeyboardInterrupt: pass except Exception: self.log.error(traceback.format_exc()) if self.do_restart: self.log.info("Going to sleep 2 seconds and restart") time.sleep(2) self.restart()
def post_save (self, instance=None, sender=None, created=False, **kwargs) : import core core.initialize() index_models = sys.MODELS_REGISTERED.get(utils.get_model_name(instance), None) for index_model in index_models : if created : sys.INDEX_MANAGER.index( instance, analyzer=index_model._meta.analyzer, field_analyzers=index_model._meta.field_analyzers, ) else : sys.INDEX_MANAGER.index_update( instance, analyzer=index_model._meta.analyzer, field_analyzers=index_model._meta.field_analyzers, )
def start(self): """ Initialize db and session monitor thread """ global db log.info(":SYS:Starting W.I.L.L") db_url = self.configuration_data["db_url"] log.info(":SYS:Connecting to database") db = dataset.connect(db_url, engine_kwargs={"pool_recycle": 1}) core.db = db API.db = db web.db = db start_time = self.now.strftime("%I:%M %p %A %m/%d/%Y") web.start_time = start_time log.info(":SYS:Starting W.I.L.L core") core.initialize(db) log.info(":SYS:Starting sessions parsing thread") core.sessions_monitor(db) log.info(":SYS:W.I.L.L started")
def application(): # pre-conditions config.init() # initialize internal config for the app time = 0 # define stopwatch for the process # process for t times print('=> START: Running simulation for waterbirds ABM') habitats, agents = initialize() observe(habitats, agents, time) for time in range(1, constants.PROCESSING_TIME): agents = update(habitats, agents, time) observe(habitats, agents, time) print('=> END: Running simulation for waterbirds ABM')
def start(): """ Initialize db and session monitor thread """ global db global start_time db_url = configuration_data["db_url"] db = dataset.connect(db_url) core.db = db API.db = db web.db = db start_time = now.strftime("%I:%M %p %A %m/%d/%Y") web.start_time = start_time log.info(":SYS:Running app") log.info(":SYS:Starting W.I.L.L") log.info(":SYS:Loaded configuration file and started logging") log.info(":SYS:Connecting to database") log.info(":SYS:Starting W.I.L.L core") core.initialize(db) log.info(":SYS:Starting sessions parsing thread") core.sessions_monitor(db) log.info(":SYS:Connected to database, running server")
def __init__(self, config=None, watched_paths=None, enabled_sites=None, enabled_clients=None, dry_run=False, report=False, comment=False, *args, **kwargs): # add kwargs if isinstance(config, str): core.CONFIG = config = initialize(config) self._config_file = core.CONFIG._config_file self.config = core.CONFIG self.comment = comment self._enabled_sites = self.load_sites(enabled_sites) self._enabled_clients = self.load_clients(enabled_clients) self.__watch_paths = watched_paths or self.config.WATCHED_PATHS self.__watcher = Observer(timeout=10) self.dry_run = dry_run self._resport = report
def main(): #START # Initialize the config section = None args = sys.argv core.initialize(section) logger.info("#########################################################") logger.info("## ..::[{0}]::.. ##".format(os.path.basename(__file__))) logger.info("#########################################################") # debug command line options logger.debug("Options passed into nzbToMedia: {0}".format(args)) # Post-Processing Result result = [0, ""] status = 0 #set arguments to variable args, because this is used as a default variable later #Argumente von Sabnzbd aufteilen # SABnzbd Pre 0.7.17 if len(args) == core.SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file # 3 Clean version of the job name (no path info and ".nzb" removed) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 clientAgent = 'sabnzbd' logger.info("Script triggered from SABnzbd") result = startproc(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent=clientAgent, download_id='') # SABnzbd 0.7.17+ elif len(args) >= core.SABNZB_0717_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file # 3 Clean version of the job name (no path info and ".nzb" removed) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 # 8 Failure URL clientAgent = 'sabnzbd' logger.info("Script triggered from SABnzbd 0.7.17+") result = startproc(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent=clientAgent, download_id='', failureLink=''.join(args[8:])) ##########here sys.exit(result)
raise ImportError("Could not find core.so in basepath: %s" % base_path) print("Found core.so at %s\n" % matches[0]) sys.path.insert(1, matches[0]) try: import core except ImportError as err: if 'CXXABI' in str(err): raise ImportError( "{0}\nLikely cause: GCC >= 4.9 not in [DY]LD_LIBRARY_PATH". format(err)) else: raise ImportError("{0}".format(err)) # Init core core.initialize() core.efp_init() # Cleanup core at exit import atexit atexit.register(core.set_legacy_molecule, None) atexit.register(core.clean) atexit.register(core.finalize) # Numpy place holder for files and cleanup numpy_files = [] def register_numpy_file(filename): if filename not in numpy_files: numpy_files.append(filename)
from core import start_app_Threads, initialize, trigger_Shutdown import signal import sys ''' This Main.py class is the entry point to run the core.py application standalone. Main.py will not be part of the Front end. Currently this is just used to test/debug and develop this core.py logic. ''' def signal_handler(sig, frame): print('You pressed Ctrl+C!') trigger_Shutdown() sys.exit(0) signal.signal(signal.SIGINT, signal_handler) start_app_Threads() initialize() print('Press Ctrl+C') signal.pause() #Wait for termination #shutdown()
def bot(): global log, log_long, stream, chrome, token chrome = initialize(load(os.path.abspath(os.getcwd()) + '\\config.txt'), stream, token, log, log_long) loadTwitch(chrome) collectAndBet(chrome, 'https://www.twitch.tv/' + stream)
def main(args): # Initialize the config core.initialize() # clientAgent for Torrents clientAgent = core.TORRENT_CLIENTAGENT logger.info("#########################################################") logger.info("## ..::[%s]::.. ##" % os.path.basename(__file__)) logger.info("#########################################################") # debug command line options logger.debug("Options passed into TorrentToMedia: %s" % (args)) # Post-Processing Result result = [ 0, "" ] try: inputDirectory, inputName, inputCategory, inputHash, inputID = core.parse_args(clientAgent, args) except: logger.error("There was a problem loading variables") return -1 if inputDirectory and inputName and inputHash and inputID: result = processTorrent(inputDirectory, inputName, inputCategory, inputHash, inputID, clientAgent) else: # Perform Manual Post-Processing logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...") for section, subsections in core.SECTIONS.items(): for subsection in subsections: if not core.CFG[section][subsection].isenabled(): continue for dirName in core.getDirs(section, subsection, link='hard'): logger.info("Starting manual run for %s:%s - Folder:%s" % (section, subsection, dirName)) logger.info("Checking database for download info for %s ..." % (os.path.basename(dirName))) core.DOWNLOADINFO = core.get_downloadInfo(os.path.basename(dirName), 0) if core.DOWNLOADINFO: logger.info( "Found download info for %s, setting variables now ..." % (os.path.basename(dirName))) else: logger.info( 'Unable to locate download info for %s, continuing to try and process this release ...' % ( os.path.basename(dirName)) ) try: clientAgent = str(core.DOWNLOADINFO[0]['client_agent']) except: clientAgent = 'manual' try: inputHash = str(core.DOWNLOADINFO[0]['input_hash']) except: inputHash = None try: inputID = str(core.DOWNLOADINFO[0]['input_id']) except: inputID = None if clientAgent.lower() not in core.TORRENT_CLIENTS and clientAgent != 'manual': continue try: dirName = dirName.encode(core.SYS_ENCODING) except: pass inputName = os.path.basename(dirName) try: inputName = inputName.encode(core.SYS_ENCODING) except: pass results = processTorrent(dirName, inputName, subsection, inputHash, inputID, clientAgent) if results[0] != 0: logger.error("A problem was reported when trying to perform a manual run for %s:%s." % ( section, subsection)) result = results if result[0] == 0: logger.info("The %s script completed successfully." % (args[0])) else: logger.error("A problem was reported in the %s script." % (args[0])) del core.MYAPP return result[0]
def initialize_using_files(geo_locations, extended_words3, capital_word_shape=False): """Initialize LNEx using files in _Data without using the elastic index""" core.initialize(geo_locations, extended_words3, capital_word_shape)
def main(args): # Initialize the config core.initialize() # clientAgent for Torrents client_agent = core.TORRENT_CLIENTAGENT logger.info('#########################################################') logger.info('## ..::[{0}]::.. ##'.format(os.path.basename(__file__))) logger.info('#########################################################') # debug command line options logger.debug('Options passed into TorrentToMedia: {0}'.format(args)) # Post-Processing Result result = ProcessResult( message='', status_code=0, ) try: input_directory, input_name, input_category, input_hash, input_id = core.parse_args(client_agent, args) except Exception: logger.error('There was a problem loading variables') return -1 if input_directory and input_name and input_hash and input_id: result = process_torrent(input_directory, input_name, input_category, input_hash, input_id, client_agent) else: # Perform Manual Post-Processing logger.warning('Invalid number of arguments received from client, Switching to manual run mode ...') for section, subsections in core.SECTIONS.items(): for subsection in subsections: if not core.CFG[section][subsection].isenabled(): continue for dir_name in core.get_dirs(section, subsection, link='hard'): logger.info('Starting manual run for {0}:{1} - Folder:{2}'.format (section, subsection, dir_name)) logger.info('Checking database for download info for {0} ...'.format (os.path.basename(dir_name))) core.DOWNLOADINFO = core.get_download_info(os.path.basename(dir_name), 0) if core.DOWNLOADINFO: client_agent = text_type(core.DOWNLOADINFO[0].get('client_agent', 'manual')) input_hash = text_type(core.DOWNLOADINFO[0].get('input_hash', '')) input_id = text_type(core.DOWNLOADINFO[0].get('input_id', '')) logger.info('Found download info for {0}, ' 'setting variables now ...'.format(os.path.basename(dir_name))) else: logger.info('Unable to locate download info for {0}, ' 'continuing to try and process this release ...'.format (os.path.basename(dir_name))) client_agent = 'manual' input_hash = '' input_id = '' if client_agent.lower() not in core.TORRENT_CLIENTS: continue try: dir_name = dir_name.encode(core.SYS_ENCODING) except UnicodeError: pass input_name = os.path.basename(dir_name) try: input_name = input_name.encode(core.SYS_ENCODING) except UnicodeError: pass results = process_torrent(dir_name, input_name, subsection, input_hash or None, input_id or None, client_agent) if results.status_code != 0: logger.error('A problem was reported when trying to perform a manual run for {0}:{1}.'.format (section, subsection)) result = results if result.status_code == 0: logger.info('The {0} script completed successfully.'.format(args[0])) else: logger.error('A problem was reported in the {0} script.'.format(args[0])) del core.MYAPP return result.status_code
#! /usr/bin/env python2 import os import sys import datetime import re import core from core.nzbToMediaAutoFork import autoFork from core import nzbToMediaDB from core.transcoder import transcoder from core.nzbToMediaUtil import get_downloadInfo, server_responding # Initialize the config core.initialize() #label = core.TORRENT_CLASS.core.get_torrent_status("f33a9c4b15cbd9170722d700069af86746817ade", ["label"]).get()['label'] #print label if transcoder.isVideoGood(core.TEST_FILE, 0): print "FFPROBE Works" else: print "FFPROBE FAILED" test = core.CFG['SickBeard','NzbDrone']['tv'].isenabled() print test section = core.CFG.findsection('tv').isenabled() print section print len(section) fork, fork_params = autoFork('SickBeard', 'tv') if server_responding("http://127.0.0.1:5050"): print "CouchPotato Running"
print(Parameters.realConcCC) #%% # Define seed and ranges np.random.seed(Parameters.r_seed) best_dist = [] avg_dist = [] med_dist = [] top5_dist = [] #%% t1 = time.time() # Initialize ens_dist, ens_model, ens_rl, rl_track = core.initialize(Parameters) dist_top_ind = np.argsort(ens_dist) dist_top = ens_dist[dist_top_ind] model_top = ens_model[dist_top_ind] # rl_top = ens_rl[dist_top_ind] best_dist.append(dist_top[0]) avg_dist.append(np.average(dist_top)) med_dist.append(np.median(dist_top)) top5_dist.append(np.average(np.unique(dist_top)[:int(0.05*Parameters.ens_size)])) print("Minimum distance: " + str(best_dist[-1])) print("Top 5 distance: " + str(top5_dist[-1])) print("Average distance: " + str(avg_dist[-1])) breakFlag = False
def test_initial(): core.initialize() del core.MYAPP
def main(args): # Initialize the config core.initialize() # clientAgent for Torrents client_agent = core.TORRENT_CLIENTAGENT logger.info('#########################################################') logger.info('## ..::[{0}]::.. ##'.format(os.path.basename(__file__))) logger.info('#########################################################') # debug command line options logger.debug('Options passed into TorrentToMedia: {0}'.format(args)) # Post-Processing Result result = ProcessResult( message='', status_code=0, ) try: input_directory, input_name, input_category, input_hash, input_id = core.parse_args(client_agent, args) except Exception: logger.error('There was a problem loading variables') return -1 if input_directory and input_name and input_hash and input_id: result = process_torrent(input_directory, input_name, input_category, input_hash, input_id, client_agent) else: # Perform Manual Post-Processing logger.warning('Invalid number of arguments received from client, Switching to manual run mode ...') for section, subsections in core.SECTIONS.items(): for subsection in subsections: if not core.CFG[section][subsection].isenabled(): continue for dir_name in core.get_dirs(section, subsection, link='hard'): logger.info('Starting manual run for {0}:{1} - Folder:{2}'.format (section, subsection, dir_name)) logger.info('Checking database for download info for {0} ...'.format (os.path.basename(dir_name))) core.DOWNLOADINFO = core.get_download_info(os.path.basename(dir_name), 0) if core.DOWNLOADINFO: client_agent = text_type(core.DOWNLOADINFO[0].get('client_agent', 'manual')) input_hash = text_type(core.DOWNLOADINFO[0].get('input_hash', '')) input_id = text_type(core.DOWNLOADINFO[0].get('input_id', '')) logger.info('Found download info for {0}, ' 'setting variables now ...'.format(os.path.basename(dir_name))) else: logger.info('Unable to locate download info for {0}, ' 'continuing to try and process this release ...'.format (os.path.basename(dir_name))) client_agent = 'manual' input_hash = '' input_id = '' if client_agent.lower() not in core.TORRENT_CLIENTS: continue try: dir_name = dir_name.encode(core.SYS_ENCODING) except UnicodeError: pass input_name = os.path.basename(dir_name) try: input_name = input_name.encode(core.SYS_ENCODING) except UnicodeError: pass results = process_torrent(dir_name, input_name, subsection, input_hash or None, input_id or None, client_agent) if results[0] != 0: logger.error('A problem was reported when trying to perform a manual run for {0}:{1}.'.format (section, subsection)) result = results if result.status_code == 0: logger.info('The {0} script completed successfully.'.format(args[0])) else: logger.error('A problem was reported in the {0} script.'.format(args[0])) del core.MYAPP return result.status_code
def initialize_agent(self): core.initialize(self)
def get_query_set (self): import core core.initialize() return queryset.QuerySet(self.index_model)
def main(args, section=None): # Initialize the config core.initialize(section) logger.info('#########################################################') logger.info('## ..::[{0}]::.. ##'.format(os.path.basename(__file__))) logger.info('#########################################################') # debug command line options logger.debug('Options passed into nzbToMedia: {0}'.format(args)) # Post-Processing Result result = ProcessResult( message='', status_code=0, ) status = 0 # NZBGet if 'NZBOP_SCRIPTDIR' in os.environ: # Check if the script is called from nzbget 11.0 or later if os.environ['NZBOP_VERSION'][0:5] < '11.0': logger.error('NZBGet Version {0} is not supported. Please update NZBGet.'.format(os.environ['NZBOP_VERSION'])) sys.exit(core.NZBGET_POSTPROCESS_ERROR) logger.info('Script triggered from NZBGet Version {0}.'.format(os.environ['NZBOP_VERSION'])) # Check if the script is called from nzbget 13.0 or later if 'NZBPP_TOTALSTATUS' in os.environ: if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': logger.info('Download failed with status {0}.'.format(os.environ['NZBPP_STATUS'])) status = 1 else: # Check par status if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': logger.warning('Par-repair failed, setting status \'failed\'') status = 1 # Check unpack status if os.environ['NZBPP_UNPACKSTATUS'] == '1': logger.warning('Unpack failed, setting status \'failed\'') status = 1 if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] == '0': # Unpack was skipped due to nzb-file properties or due to errors during par-check if os.environ['NZBPP_HEALTH'] < 1000: logger.warning( 'Download health is compromised and Par-check/repair disabled or no .par2 files found. Setting status \'failed\'') logger.info('Please check your Par-check/repair settings for future downloads.') status = 1 else: logger.info( 'Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful') logger.info('Please check your Par-check/repair settings for future downloads.') # Check for download_id to pass to CouchPotato download_id = '' failure_link = None if 'NZBPR_COUCHPOTATO' in os.environ: download_id = os.environ['NZBPR_COUCHPOTATO'] elif 'NZBPR_DRONE' in os.environ: download_id = os.environ['NZBPR_DRONE'] elif 'NZBPR_SONARR' in os.environ: download_id = os.environ['NZBPR_SONARR'] elif 'NZBPR_RADARR' in os.environ: download_id = os.environ['NZBPR_RADARR'] elif 'NZBPR_LIDARR' in os.environ: download_id = os.environ['NZBPR_LIDARR'] if 'NZBPR__DNZB_FAILURE' in os.environ: failure_link = os.environ['NZBPR__DNZB_FAILURE'] # All checks done, now launching the script. client_agent = 'nzbget' result = process(os.environ['NZBPP_DIRECTORY'], input_name=os.environ['NZBPP_NZBNAME'], status=status, client_agent=client_agent, download_id=download_id, input_category=os.environ['NZBPP_CATEGORY'], failure_link=failure_link) # SABnzbd Pre 0.7.17 elif len(args) == core.SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file # 3 Clean version of the job name (no path info and '.nzb' removed) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 client_agent = 'sabnzbd' logger.info('Script triggered from SABnzbd') result = process(args[1], input_name=args[2], status=int(args[7]), input_category=args[5], client_agent=client_agent, download_id='') # SABnzbd 0.7.17+ elif len(args) >= core.SABNZB_0717_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file # 3 Clean version of the job name (no path info and '.nzb' removed) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 # 8 Failure URL client_agent = 'sabnzbd' logger.info('Script triggered from SABnzbd 0.7.17+') result = process(args[1], input_name=args[2], status=int(args[7]), input_category=args[5], client_agent=client_agent, download_id='', failure_link=''.join(args[8:])) # Generic program elif len(args) > 5 and args[5] == 'generic': logger.info('Script triggered from generic program') result = process(args[1], input_name=args[2], input_category=args[3], download_id=args[4]) else: # Perform Manual Post-Processing logger.warning('Invalid number of arguments received from client, Switching to manual run mode ...') for section, subsections in core.SECTIONS.items(): for subsection in subsections: if not core.CFG[section][subsection].isenabled(): continue for dir_name in get_dirs(section, subsection, link='move'): logger.info('Starting manual run for {0}:{1} - Folder: {2}'.format(section, subsection, dir_name)) logger.info('Checking database for download info for {0} ...'.format(os.path.basename(dir_name))) core.DOWNLOAD_INFO = get_download_info(os.path.basename(dir_name), 0) if core.DOWNLOAD_INFO: logger.info('Found download info for {0}, ' 'setting variables now ...'.format (os.path.basename(dir_name))) client_agent = text_type(core.DOWNLOAD_INFO[0].get('client_agent', 'manual')) download_id = text_type(core.DOWNLOAD_INFO[0].get('input_id', '')) else: logger.info('Unable to locate download info for {0}, ' 'continuing to try and process this release ...'.format (os.path.basename(dir_name))) client_agent = 'manual' download_id = '' if client_agent and client_agent.lower() not in core.NZB_CLIENTS: continue input_name = os.path.basename(dir_name) results = process(dir_name, input_name, 0, client_agent=client_agent, download_id=download_id or None, input_category=subsection) if results.status_code != 0: logger.error('A problem was reported when trying to perform a manual run for {0}:{1}.'.format (section, subsection)) result = results if result.status_code == 0: logger.info('The {0} script completed successfully.'.format(args[0])) if result.message: print(result.message + '!') if 'NZBOP_SCRIPTDIR' in os.environ: # return code for nzbget v11 del core.MYAPP return core.NZBGET_POSTPROCESS_SUCCESS else: logger.error('A problem was reported in the {0} script.'.format(args[0])) if result.message: print(result.message + '!') if 'NZBOP_SCRIPTDIR' in os.environ: # return code for nzbget v11 del core.MYAPP return core.NZBGET_POSTPROCESS_ERROR del core.MYAPP return result.status_code
def main(args, section=None): # Initialize the config core.initialize(section) logger.info('#########################################################') logger.info('## ..::[{0}]::.. ##'.format(os.path.basename(__file__))) logger.info('#########################################################') # debug command line options logger.debug('Options passed into nzbToMedia: {0}'.format(args)) # Post-Processing Result result = ProcessResult( message='', status_code=0, ) status = 0 # NZBGet if 'NZBOP_SCRIPTDIR' in os.environ: # Check if the script is called from nzbget 11.0 or later if os.environ['NZBOP_VERSION'][0:5] < '11.0': logger.error('NZBGet Version {0} is not supported. Please update NZBGet.'.format(os.environ['NZBOP_VERSION'])) sys.exit(core.NZBGET_POSTPROCESS_ERROR) logger.info('Script triggered from NZBGet Version {0}.'.format(os.environ['NZBOP_VERSION'])) # Check if the script is called from nzbget 13.0 or later if 'NZBPP_TOTALSTATUS' in os.environ: if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': logger.info('Download failed with status {0}.'.format(os.environ['NZBPP_STATUS'])) status = 1 else: # Check par status if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': logger.warning('Par-repair failed, setting status \'failed\'') status = 1 # Check unpack status if os.environ['NZBPP_UNPACKSTATUS'] == '1': logger.warning('Unpack failed, setting status \'failed\'') status = 1 if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] == '0': # Unpack was skipped due to nzb-file properties or due to errors during par-check if os.environ['NZBPP_HEALTH'] < 1000: logger.warning( 'Download health is compromised and Par-check/repair disabled or no .par2 files found. Setting status \'failed\'') logger.info('Please check your Par-check/repair settings for future downloads.') status = 1 else: logger.info( 'Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful') logger.info('Please check your Par-check/repair settings for future downloads.') # Check for download_id to pass to CouchPotato download_id = '' failure_link = None if 'NZBPR_COUCHPOTATO' in os.environ: download_id = os.environ['NZBPR_COUCHPOTATO'] elif 'NZBPR_DRONE' in os.environ: download_id = os.environ['NZBPR_DRONE'] elif 'NZBPR_SONARR' in os.environ: download_id = os.environ['NZBPR_SONARR'] elif 'NZBPR_RADARR' in os.environ: download_id = os.environ['NZBPR_RADARR'] elif 'NZBPR_LIDARR' in os.environ: download_id = os.environ['NZBPR_LIDARR'] if 'NZBPR__DNZB_FAILURE' in os.environ: failure_link = os.environ['NZBPR__DNZB_FAILURE'] # All checks done, now launching the script. client_agent = 'nzbget' result = process(os.environ['NZBPP_DIRECTORY'], input_name=os.environ['NZBPP_NZBNAME'], status=status, client_agent=client_agent, download_id=download_id, input_category=os.environ['NZBPP_CATEGORY'], failure_link=failure_link) # SABnzbd Pre 0.7.17 elif len(args) == core.SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file # 3 Clean version of the job name (no path info and '.nzb' removed) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 client_agent = 'sabnzbd' logger.info('Script triggered from SABnzbd') result = process(args[1], input_name=args[2], status=args[7], input_category=args[5], client_agent=client_agent, download_id='') # SABnzbd 0.7.17+ elif len(args) >= core.SABNZB_0717_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file # 3 Clean version of the job name (no path info and '.nzb' removed) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 # 8 Failure URL client_agent = 'sabnzbd' logger.info('Script triggered from SABnzbd 0.7.17+') result = process(args[1], input_name=args[2], status=args[7], input_category=args[5], client_agent=client_agent, download_id='', failure_link=''.join(args[8:])) # Generic program elif len(args) > 5 and args[5] == 'generic': logger.info('Script triggered from generic program') result = process(args[1], input_name=args[2], input_category=args[3], download_id=args[4]) else: # Perform Manual Post-Processing logger.warning('Invalid number of arguments received from client, Switching to manual run mode ...') for section, subsections in core.SECTIONS.items(): for subsection in subsections: if not core.CFG[section][subsection].isenabled(): continue for dir_name in get_dirs(section, subsection, link='move'): logger.info('Starting manual run for {0}:{1} - Folder: {2}'.format(section, subsection, dir_name)) logger.info('Checking database for download info for {0} ...'.format(os.path.basename(dir_name))) core.DOWNLOADINFO = get_download_info(os.path.basename(dir_name), 0) if core.DOWNLOADINFO: logger.info('Found download info for {0}, ' 'setting variables now ...'.format (os.path.basename(dir_name))) client_agent = text_type(core.DOWNLOADINFO[0].get('client_agent', 'manual')) download_id = text_type(core.DOWNLOADINFO[0].get('input_id', '')) else: logger.info('Unable to locate download info for {0}, ' 'continuing to try and process this release ...'.format (os.path.basename(dir_name))) client_agent = 'manual' download_id = '' if client_agent and client_agent.lower() not in core.NZB_CLIENTS: continue try: dir_name = dir_name.encode(core.SYS_ENCODING) except UnicodeError: pass input_name = os.path.basename(dir_name) try: input_name = input_name.encode(core.SYS_ENCODING) except UnicodeError: pass results = process(dir_name, input_name, 0, client_agent=client_agent, download_id=download_id or None, input_category=subsection) if results.status_code != 0: logger.error('A problem was reported when trying to perform a manual run for {0}:{1}.'.format (section, subsection)) result = results if result.status_code == 0: logger.info('The {0} script completed successfully.'.format(args[0])) if result.message: print(result.message + '!') if 'NZBOP_SCRIPTDIR' in os.environ: # return code for nzbget v11 del core.MYAPP return core.NZBGET_POSTPROCESS_SUCCESS else: logger.error('A problem was reported in the {0} script.'.format(args[0])) if result.message: print(result.message + '!') if 'NZBOP_SCRIPTDIR' in os.environ: # return code for nzbget v11 del core.MYAPP return core.NZBGET_POSTPROCESS_ERROR del core.MYAPP return result.status_code
def main(args, section=None): # Initialize the config core.initialize(section) # clientAgent for NZBs clientAgent = core.NZB_CLIENTAGENT logger.info("#########################################################") logger.info("## ..::[%s]::.. ##" % os.path.basename(__file__)) logger.info("#########################################################") # debug command line options logger.debug("Options passed into nzbToMedia: %s" % args) # Post-Processing Result result = [0, ""] status = 0 # NZBGet if os.environ.has_key('NZBOP_SCRIPTDIR'): # Check if the script is called from nzbget 11.0 or later if os.environ['NZBOP_VERSION'][0:5] < '11.0': logger.error("NZBGet Version %s is not supported. Please update NZBGet." %(str(os.environ['NZBOP_VERSION']))) sys.exit(core.NZBGET_POSTPROCESS_ERROR) logger.info("Script triggered from NZBGet Version %s." %(str(os.environ['NZBOP_VERSION']))) # Check if the script is called from nzbget 13.0 or later if os.environ.has_key('NZBPP_TOTALSTATUS'): if not os.environ['NZBPP_TOTALSTATUS'] == 'SUCCESS': logger.info("Download failed with status %s." %(os.environ['NZBPP_STATUS'])) status = 1 else: # Check par status if os.environ['NZBPP_PARSTATUS'] == '1' or os.environ['NZBPP_PARSTATUS'] == '4': logger.warning("Par-repair failed, setting status \"failed\"") status = 1 # Check unpack status if os.environ['NZBPP_UNPACKSTATUS'] == '1': logger.warning("Unpack failed, setting status \"failed\"") status = 1 if os.environ['NZBPP_UNPACKSTATUS'] == '0' and os.environ['NZBPP_PARSTATUS'] == '0': # Unpack was skipped due to nzb-file properties or due to errors during par-check if os.environ['NZBPP_HEALTH'] < 1000: logger.warning( "Download health is compromised and Par-check/repair disabled or no .par2 files found. Setting status \"failed\"") logger.info("Please check your Par-check/repair settings for future downloads.") status = 1 else: logger.info( "Par-check/repair disabled or no .par2 files found, and Unpack not required. Health is ok so handle as though download successful") logger.info("Please check your Par-check/repair settings for future downloads.") # Check for download_id to pass to CouchPotato download_id = "" failureLink = None if os.environ.has_key('NZBPR_COUCHPOTATO'): download_id = os.environ['NZBPR_COUCHPOTATO'] elif os.environ.has_key('NZBPR_DRONE'): download_id = os.environ['NZBPR_DRONE'] elif os.environ.has_key('NZBPR_SONARR'): download_id = os.environ['NZBPR_SONARR'] if os.environ.has_key('NZBPR__DNZB_FAILURE'): failureLink = os.environ['NZBPR__DNZB_FAILURE'] # All checks done, now launching the script. clientAgent = 'nzbget' result = process(os.environ['NZBPP_DIRECTORY'], inputName=os.environ['NZBPP_NZBNAME'], status=status, clientAgent=clientAgent, download_id=download_id, inputCategory=os.environ['NZBPP_CATEGORY'], failureLink=failureLink) # SABnzbd Pre 0.7.17 elif len(args) == core.SABNZB_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file # 3 Clean version of the job name (no path info and ".nzb" removed) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 clientAgent = 'sabnzbd' logger.info("Script triggered from SABnzbd") result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent=clientAgent, download_id='') # SABnzbd 0.7.17+ elif len(args) >= core.SABNZB_0717_NO_OF_ARGUMENTS: # SABnzbd argv: # 1 The final directory of the job (full path) # 2 The original name of the NZB file # 3 Clean version of the job name (no path info and ".nzb" removed) # 4 Indexer's report number (if supported) # 5 User-defined category # 6 Group that the NZB was posted in e.g. alt.binaries.x # 7 Status of post processing. 0 = OK, 1=failed verification, 2=failed unpack, 3=1+2 # 8 Failure URL clientAgent = 'sabnzbd' logger.info("Script triggered from SABnzbd 0.7.17+") result = process(args[1], inputName=args[2], status=args[7], inputCategory=args[5], clientAgent=clientAgent, download_id='', failureLink=''.join(args[8:])) else: # Perform Manual Post-Processing logger.warning("Invalid number of arguments received from client, Switching to manual run mode ...") for section, subsections in core.SECTIONS.items(): for subsection in subsections: if not core.CFG[section][subsection].isenabled(): continue for dirName in getDirs(section, subsection, link = 'move'): logger.info("Starting manual run for %s:%s - Folder:%s" % (section, subsection, dirName)) logger.info("Checking database for download info for %s ..." % (os.path.basename(dirName))) core.DOWNLOADINFO = get_downloadInfo(os.path.basename(dirName), 0) if core.DOWNLOADINFO: logger.info( "Found download info for %s, setting variables now ..." % (os.path.basename(dirName))) else: logger.info( 'Unable to locate download info for %s, continuing to try and process this release ...' % ( os.path.basename(dirName)) ) try: clientAgent = str(core.DOWNLOADINFO[0]['client_agent']) except: clientAgent = 'manual' try: download_id = str(core.DOWNLOADINFO[0]['input_id']) except: download_id = None if clientAgent.lower() not in core.NZB_CLIENTS and clientAgent != 'manual': continue try: dirName = dirName.encode(core.SYS_ENCODING) except: pass inputName = os.path.basename(dirName) try: inputName = inputName.encode(core.SYS_ENCODING) except: pass results = process(dirName, inputName, 0, clientAgent=clientAgent, download_id=download_id, inputCategory=subsection) if results[0] != 0: logger.error("A problem was reported when trying to perform a manual run for %s:%s." % ( section, subsection)) result = results if result[0] == 0: logger.info("The %s script completed successfully." % args[0]) if result[1]: print result[1] + "!" # For SABnzbd Status display. if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 del core.MYAPP return (core.NZBGET_POSTPROCESS_SUCCESS) else: logger.error("A problem was reported in the %s script." % args[0]) if result[1]: print result[1] + "!" # For SABnzbd Status display. if os.environ.has_key('NZBOP_SCRIPTDIR'): # return code for nzbget v11 del core.MYAPP return (core.NZBGET_POSTPROCESS_ERROR) del core.MYAPP return (result[0])
def run_forever(self): print "Server started" server_sock = self.server_sock while True: print "Listening for connection" client_sock, address = server_sock.accept() print "Accepted connection from ", address client_sock.settimeout(10) print client_sock.gettimeout() try: self.serve_connection(client_sock) except Exception as e: print e core.locked_closer() try: client_sock.close() except Exception as e: print e print "Bluetooth Connection closed!!" server_sock.close() print "starting bluetooth server" server = My_Bluetooth_Server() core.initialize(server.setFalgFalse) server.create_server() server.run_forever()