text_prompt
stringlengths
100
17.7k
code_prompt
stringlengths
7
9.86k
<SYSTEM_TASK:> method returns DB cursor based on precise boundaries <END_TASK> <USER_TASK:> Description: def cursor_fine(self, table_name, start_id_obj, end_id_obj, iteration, start_timeperiod, end_ti...
raise NotImplementedError('method cursor_fine must be implemented by {0}'.format(self.__class__.__name__))
<SYSTEM_TASK:> method returns batched DB cursor <END_TASK> <USER_TASK:> Description: def cursor_batch(self, table_name, start_timeperiod, end_timeperiod): """ method returns batched DB cursor """
raise NotImplementedError('method cursor_batch must be implemented by {0}'.format(self.__class__.__name__))
<SYSTEM_TASK:> replaces document identified by the primary_key or creates one if a matching document does not exist <END_TASK> <USER_TASK:> Description: def update(self, table_name, primary_key, instance): """ replaces document identified by the primary_key or creates one if a matching document does not exist""...
assert isinstance(primary_key, dict) assert isinstance(instance, BaseDocument) collection = self._db[table_name] # work with a copy of the document, as the direct type change of the _id field # is later negated by the `BaseDocument.to_json` method document = instance.do...
<SYSTEM_TASK:> Returns the first occurrence of the effect in your pedalboard <END_TASK> <USER_TASK:> Description: def index(self): """ Returns the first occurrence of the effect in your pedalboard """
if self.pedalboard is None: raise IndexError('Effect not contains a pedalboard') return self.pedalboard.effects.index(self)
<SYSTEM_TASK:> Force all models to call full_clean before save <END_TASK> <USER_TASK:> Description: def pre_save_full_clean_handler(sender, instance, *args, **kwargs): """ Force all models to call full_clean before save """
from django.contrib.sessions.models import Session if sender != Session: instance.full_clean()
<SYSTEM_TASK:> Load the settings module pointed to by the environment variable. This <END_TASK> <USER_TASK:> Description: def _setup(self): """ Load the settings module pointed to by the environment variable. This is used the first time we need any settings at all, if the user has not pr...
settings_module = os.environ.get(ENVIRONMENT_SETTINGS_VARIABLE, 'settings') if not settings_module: raise ImproperlyConfigured( 'Requested settings module points to an empty variable. ' 'You must either define the environment variable {0} ' 'o...
<SYSTEM_TASK:> Load the context module pointed to by the environment variable. This <END_TASK> <USER_TASK:> Description: def _setup(self): """ Load the context module pointed to by the environment variable. This is used the first time we need the context at all, if the user has not previ...
context_module = os.environ.get(ENVIRONMENT_CONTEXT_VARIABLE, 'context') if not context_module: raise ImproperlyConfigured( 'Requested context points to an empty variable. ' 'You must either define the environment variable {0} ' 'or call conte...
<SYSTEM_TASK:> Reads the json data in path <END_TASK> <USER_TASK:> Description: def read(path, create_file=False): """ Reads the json data in path :param Path path: Path that json data will be readed :param create_file: Creates the file if it isn't exists :return: json data ...
if create_file: with open(str(path), 'a+') as data_file: data_file.seek(0) return json.load(data_file) else: with open(str(path)) as data_file: return json.load(data_file)
<SYSTEM_TASK:> This method for run some function at subprocess. <END_TASK> <USER_TASK:> Description: def run_at_subprocess(self, use_subprocess, foo, *args, **kwrags): """ This method for run some function at subprocess. Very useful when you have a problem with memory leaks. """
if use_subprocess is False: return foo(*args, **kwrags) child_pid = os.fork() if child_pid == 0: foo(*args, **kwrags) sys.exit(0) return os.waitpid(child_pid, 0)[1] == 0
<SYSTEM_TASK:> removes all documents in this collection <END_TASK> <USER_TASK:> Description: def clear(self): """ removes all documents in this collection """
collection = self.ds.connection(COLLECTION_MANAGED_PROCESS) return collection.delete_many(filter={})
<SYSTEM_TASK:> method traverses compressed file and calculates its MD5 checksum <END_TASK> <USER_TASK:> Description: def compute_gzip_md5(file_name): """ method traverses compressed file and calculates its MD5 checksum """
md5 = hashlib.md5() file_obj = gzip.open(file_name, 'rb') for chunk in iter(lambda: file_obj.read(8192), ''): md5.update(chunk) file_obj.close() return md5.hexdigest()
<SYSTEM_TASK:> methods iterates thru source family and copies its entries to target family <END_TASK> <USER_TASK:> Description: def copy_and_sum_families(family_source, family_target): """ methods iterates thru source family and copies its entries to target family in case key already exists in both families - t...
for every in family_source: if every not in family_target: family_target[every] = family_source[every] else: family_target[every] += family_source[every]
<SYSTEM_TASK:> Validates the format of a host entry <END_TASK> <USER_TASK:> Description: def host_errors(self, hostname, details): """ Validates the format of a host entry Returns an error string, or None if it is valid. """
if not hostname or not isinstance(hostname, basestring): return "hostname_invalid" if not isinstance(details, list): return "host_details_not_list" if len(details) != 3: return "host_details_wrong_length" if details[0] not in self.balancer.action_mapp...
<SYSTEM_TASK:> Callback to validate a response code. <END_TASK> <USER_TASK:> Description: def boolean(cls, true_code, false_code=None): """Callback to validate a response code. The returned callback checks whether a given response has a ``status_code`` that is considered good (``true_code``) an...
def func(response): if response is not None: status_code = response.status if status_code == true_code: return True if false_code is not None and status_code == false_code: return False raise err...
<SYSTEM_TASK:> Callback to validate and extract a JSON object. <END_TASK> <USER_TASK:> Description: def json(cls, status_code, process): """Callback to validate and extract a JSON object. The returned callback checks a given response for the given status_code using :function:`response_boolean`....
def func(response): ret = None if cls.boolean(status_code)(response): ret = response.json() or {} return process(ret) return func
<SYSTEM_TASK:> Get a URL. <END_TASK> <USER_TASK:> Description: def get(self, url, callback, params=None, json=None, headers=None): """Get a URL. Args: callback(func): The response callback function Keyword Args: params(dict): Parameters for the request ...
return self.adapter.get(url, callback, params=params, json=json, headers=headers)
<SYSTEM_TASK:> Put to a URL. <END_TASK> <USER_TASK:> Description: def put(self, url, callback, params=None, json=None, headers=None): """Put to a URL. Args: url(string): URL for the request callback(func): The response callback function Keyword Args: ...
return self.adapter.put(url, callback, params=params, json=json)
<SYSTEM_TASK:> Patch a URL. <END_TASK> <USER_TASK:> Description: def patch(self, url, callback, params=None, json=None, headers=None): """Patch a URL. Args: url(string): URL for the request callback(func): The response callback function headers(dict)...
return self.adapter.patch(url, callback, params=params, json=json, headers=headers)
<SYSTEM_TASK:> Delete a URL. <END_TASK> <USER_TASK:> Description: def delete(self, url, callback, json=None): """Delete a URL. Args: url(string): URL for the request callback(func): The response callback function Keyword Args: json(dict): JSON body for th...
return self.adapter.delete(url, callback, json=json)
<SYSTEM_TASK:> Get a live endpoint. <END_TASK> <USER_TASK:> Description: def live(self, url, resource_class, resource_args, params=None): """Get a live endpoint. Args: url(string): URL for the request resource_class(class): The class to use for entries coming f...
return self.adapter.live(self, url, resource_class, resource_args, params=params)
<SYSTEM_TASK:> Return a list if banks presents in data_path <END_TASK> <USER_TASK:> Description: def load(self, system_effect): """ Return a list if banks presents in data_path :param SystemEffect system_effect: SystemEffect used in pedalboards :return list[Bank]: List with Banks persis...
persistence = PersistenceDecoder(system_effect) banks = [] for file in glob(str(self.data_path) + "/*.json"): bank = persistence.read(Persistence.read(file)) bank._uuid = file.split('/')[-1].split('.json')[0] banks.append(bank) return banks
<SYSTEM_TASK:> Save the bank in your file <END_TASK> <USER_TASK:> Description: def save_bank(self, bank): """ Save the bank in your file :param Bank bank: Bank that will be persisted """
path = self._bank_path(bank) Persistence.save(path, bank.json)
<SYSTEM_TASK:> Delete the bank's file <END_TASK> <USER_TASK:> Description: def delete_bank(self, bank): """ Delete the bank's file :param Bank bank: Bank that will be removed """
path = self._bank_path(bank) Persistence.delete(path)
<SYSTEM_TASK:> Delete all banks files. <END_TASK> <USER_TASK:> Description: def delete_all_banks(self): """ Delete all banks files. Util for manual save, because isn't possible know which banks were removed """
for file in glob(str(self.data_path) + "/*.json"): Persistence.delete(file)
<SYSTEM_TASK:> Extracts audio interfaces data <END_TASK> <USER_TASK:> Description: def audio_interfaces(): """ Extracts audio interfaces data :return list[AudioInterface]: Audio interfaces data """
p = pyaudio.PyAudio() interfaces = [] for i in range(p.get_device_count()): data = p.get_device_info_by_index(i) if 'hw' not in data['name']: interfaces.append(AudioInterface(data)) p.terminate() return interfaces
<SYSTEM_TASK:> method finds unit_of_work record and change its status <END_TASK> <USER_TASK:> Description: def update(self, instance): """ method finds unit_of_work record and change its status"""
assert isinstance(instance, UnitOfWork) if instance.db_id: query = {'_id': ObjectId(instance.db_id)} else: query = {unit_of_work.PROCESS_NAME: instance.process_name, unit_of_work.TIMEPERIOD: instance.timeperiod, unit_of_work.STAR...
<SYSTEM_TASK:> method runs the query and returns a list of filtered UnitOfWork records <END_TASK> <USER_TASK:> Description: def run_query(self, query): """ method runs the query and returns a list of filtered UnitOfWork records """
cursor = self.ds.filter(COLLECTION_UNIT_OF_WORK, query) return [UnitOfWork.from_json(document) for document in cursor]
<SYSTEM_TASK:> method tries to recover from DuplicateKeyError <END_TASK> <USER_TASK:> Description: def recover_from_duplicatekeyerror(self, e): """ method tries to recover from DuplicateKeyError """
if isinstance(e, DuplicateKeyError): try: return self.get_by_params(e.process_name, e.timeperiod, e.start_id, e.end_id) except LookupError as e: self.logger.error('Unable to recover from DuplicateKeyError error due to {0}'.format(e), exc_info=True) ...
<SYSTEM_TASK:> Handle when AutoReconnect is raised from pymongo. This is the standard error <END_TASK> <USER_TASK:> Description: def with_reconnect(func): """ Handle when AutoReconnect is raised from pymongo. This is the standard error raised for everything from "host disconnected" to "couldn't connect to h...
from pymongo.errors import AutoReconnect @functools.wraps(func) def _reconnector(*args, **kwargs): for _ in range(20): try: return func(*args, **kwargs) except AutoReconnect: time.sleep(0.250) raise return _reconnector
<SYSTEM_TASK:> method clears existing log_recorder entries for given parent_object_id, <END_TASK> <USER_TASK:> Description: def attach(self): """ method clears existing log_recorder entries for given parent_object_id, creates a new one and attaches this handler to the logger from this mo...
log_recording = LogRecording(parent_object_id=self.parent_object_id, created_at=datetime.utcnow()) self.log_recording_dao.remove(self.parent_object_id) self.log_recording_dao.update(log_recording) formatter = logging.Formatter(fmt='%(asctime)s %(levelname)-8s %(message)s', ...
<SYSTEM_TASK:> Handle payment received and respond with a dictionary <END_TASK> <USER_TASK:> Description: def process_lipisha_payment(request): """Handle payment received and respond with a dictionary"""
log.debug(request.POST) schema = LipishaInitiateSchema api_type = request.POST.get('api_type') if api_type == TYPE_ACKNOWLEDGE: schema = LipishaAcknowledgeSchema form = Form(request, schema()) transaction_status_code = STATUS_SUCCESS transaction_status = 'Processed' transaction_...
<SYSTEM_TASK:> Create a new database and collection by inserting one document. <END_TASK> <USER_TASK:> Description: def create_mongo_db(database_name, collection_name, initial_document): """Create a new database and collection by inserting one document."""
response_dict = {} try: mongodb_client_url = getattr(settings, 'MONGODB_CLIENT', 'mongodb://localhost:27017/') mc = MongoClient(mongodb_client_url,document_class=OrderedDict) db = mc[str(database_name)] collection = db[str(collection_name)] ...
<SYSTEM_TASK:> return a list of all dbs and related collections. <END_TASK> <USER_TASK:> Description: def show_dbs(): """return a list of all dbs and related collections. Return an empty list on error. """
l = [] mc = client_connector() if not mc: # The client couldn't connect return () dbs = mc.database_names() for d in dbs: dbc = mc[d] collections = dbc.collection_names() collections = remove_values_from_list(collections, "system.indexes") l.append(...
<SYSTEM_TASK:> releases the Publisher instance for reuse <END_TASK> <USER_TASK:> Description: def put(self, publisher): """ releases the Publisher instance for reuse"""
if publisher.name not in self.pools: self.pools[publisher.name] = _Pool(logger=self.logger, name=publisher.name) self.pools[publisher.name].put(publisher)
<SYSTEM_TASK:> iterates thru the list of established connections and resets them by disconnecting and reconnecting <END_TASK> <USER_TASK:> Description: def reset_all(self, suppress_logging=False): """ iterates thru the list of established connections and resets them by disconnecting and reconnecting """
pool_names = list(self.pools) for name in pool_names: self.reset(name, suppress_logging)
<SYSTEM_TASK:> resets established connection by disconnecting and reconnecting <END_TASK> <USER_TASK:> Description: def reset(self, name, suppress_logging=False): """ resets established connection by disconnecting and reconnecting """
self._close(name, suppress_logging) self.get(name) self.logger.info('Reset Flopsy Pool for {0}'.format(name))
<SYSTEM_TASK:> closes one particular pool and all its amqp amqp connections <END_TASK> <USER_TASK:> Description: def _close(self, name, suppress_logging): """ closes one particular pool and all its amqp amqp connections """
try: pool_names = list(self.pools) if name in pool_names: self.pools[name].close() del self.pools[name] except Exception as e: self.logger.error('Exception on closing Flopsy Pool for {0}: {1}'.format(name, e), ...
<SYSTEM_TASK:> iterates thru all publisher pools and closes them <END_TASK> <USER_TASK:> Description: def close(self, suppress_logging=False): """ iterates thru all publisher pools and closes them """
pool_names = list(self.pools) for name in pool_names: self._close(name, suppress_logging)
<SYSTEM_TASK:> reading box configuration entries for all boxes managed by Synergy Supervisor <END_TASK> <USER_TASK:> Description: def entries(self): """ reading box configuration entries for all boxes managed by Synergy Supervisor """
list_of_rows = [] try: list_of_rows = self.bc_dao.get_all() except LookupError as e: self.logger.error('MX Exception {0}'.format(e), exc_info=True) return list_of_rows
<SYSTEM_TASK:> method finds Site Statistics record and update it DB representation <END_TASK> <USER_TASK:> Description: def update(self, collection_name, instance): """ method finds Site Statistics record and update it DB representation """
assert isinstance(instance, SiteStatistics) if instance.db_id: query = {'_id': ObjectId(instance.db_id)} else: query = {DOMAIN_NAME: instance.domain_name, TIMEPERIOD: instance.timeperiod} self.ds.update(collection_name, query, instance) ...
<SYSTEM_TASK:> inserts a unit of work into MongoDB. <END_TASK> <USER_TASK:> Description: def insert(self, collection_name, instance): """ inserts a unit of work into MongoDB. """
assert isinstance(instance, SiteStatistics) collection = self.ds.connection(collection_name) return collection.insert_one(instance.document).inserted_id
<SYSTEM_TASK:> method runs query on a specified collection and return a list of filtered Job records <END_TASK> <USER_TASK:> Description: def run_query(self, collection_name, query): """ method runs query on a specified collection and return a list of filtered Job records """
cursor = self.ds.filter(collection_name, query) return [Job.from_json(document) for document in cursor]
<SYSTEM_TASK:> method looks for suitable job records in all Job collections and returns them as a dict <END_TASK> <USER_TASK:> Description: def retrieve_records(self, timeperiod, include_running, include_processed, include_noop, include_failed, include_disabled): """ method looks for su...
resp = dict() resp.update(self._search_by_level(COLLECTION_JOB_HOURLY, timeperiod, include_running, include_processed, include_noop, include_failed, include_disabled)) resp.update(self._search_by_level(COLLECTION_JOB_DAILY, timeperiod, include_running, ...
<SYSTEM_TASK:> method looks for suitable UOW records and returns them as a dict <END_TASK> <USER_TASK:> Description: def retrieve_records(self, timeperiod, include_running, include_processed, include_noop, include_failed, include_disabled): """ method looks for suitable UOW records and ...
resp = dict() try: query = unit_of_work_dao.QUERY_GET_FREERUN_SINCE(timeperiod, include_running, include_processed, include_noop, include_failed) records_list = self.uow_dao.run_query(query) if len(records_...
<SYSTEM_TASK:> Invokes the mod-host process. <END_TASK> <USER_TASK:> Description: def start(self): """ Invokes the mod-host process. mod-host requires JACK to be running. mod-host does not startup JACK automatically, so you need to start it before running mod-host. .. note:: ...
if self.address != 'localhost': raise ModHostError('The host configured in the constructor isn''t "localhost". ' 'It is not possible to start a process on another device.') try: subprocess.call([self.process, '-p', str(self.port)]) except...
<SYSTEM_TASK:> Remove the audio plugins loaded and closes connection with mod-host. <END_TASK> <USER_TASK:> Description: def close(self): """ Remove the audio plugins loaded and closes connection with mod-host. .. note:: If the mod-host process has been created with :meth:`~plugins...
if self.host is None: raise ModHostError('There is no established connection with mod-host. ' 'Did you call the `connect()` method?') super(ModHost, self).close() if self._started_with_this_api: self.host.quit() else: ...
<SYSTEM_TASK:> function reads managed_process and updates context entries appropriately <END_TASK> <USER_TASK:> Description: def synch_db(): """ function reads managed_process and updates context entries appropriately """
logger = get_logger(PROCESS_SCHEDULER) managed_process_dao = ManagedProcessDao(logger) try: process_entries = managed_process_dao.get_all() except LookupError: logger.error('Synergy DB is not initialized. Aborting.') exit(1) for process_entry in process_entries: pr...
<SYSTEM_TASK:> writes to managed_process table records from the context.process_context <END_TASK> <USER_TASK:> Description: def update_db(): """ writes to managed_process table records from the context.process_context """
logger = get_logger(PROCESS_SCHEDULER) managed_process_dao = ManagedProcessDao(logger) managed_process_dao.clear() for process_name, process_entry in context.process_context.items(): if not isinstance(process_entry, ManagedProcessEntry): continue managed_process_dao.update...
<SYSTEM_TASK:> Moves a item list to new position <END_TASK> <USER_TASK:> Description: def move(self, item, new_position): """ Moves a item list to new position Calls observer ``self.observer(UpdateType.DELETED, item, index)`` and observer ``self.observer(UpdateType.CREATED, item, index)...
if item == self[new_position]: return self.remove(item) self.insert(new_position, item)
<SYSTEM_TASK:> method performs logging into log file and Timetable's tree node <END_TASK> <USER_TASK:> Description: def _log_message(self, level, process_name, timeperiod, msg): """ method performs logging into log file and Timetable's tree node"""
self.timetable.add_log_entry(process_name, timeperiod, msg) self.logger.log(level, msg)
<SYSTEM_TASK:> method is valid for processes having time_grouping != 1. <END_TASK> <USER_TASK:> Description: def _process_noop_timeperiod(self, job_record): """ method is valid for processes having time_grouping != 1. should a job record fall in-between grouped time milestones, its state...
job_record.state = job.STATE_NOOP self.job_dao.update(job_record) time_grouping = context.process_context[job_record.process_name].time_grouping msg = 'Job {0}@{1} with time_grouping {2} was transferred to STATE_NOOP' \ .format(job_record.process_name, job_record.timeperi...
<SYSTEM_TASK:> method logs a warning message notifying that the job is no longer govern by this state machine <END_TASK> <USER_TASK:> Description: def _process_terminal_state(self, job_record): """ method logs a warning message notifying that the job is no longer govern by this state machine """
msg = 'Job {0} for {1}@{2} is in the terminal state {3}, ' \ 'and is no further govern by the State Machine {4}' \ .format(job_record.db_id, job_record.process_name, job_record.timeperiod, job_record.state, self.name) self._log_message(WARNING, job_record.process_name, job_r...
<SYSTEM_TASK:> method updates job record with a new unit_of_work and new state <END_TASK> <USER_TASK:> Description: def update_job(self, job_record, uow, new_state): """ method updates job record with a new unit_of_work and new state"""
original_job_state = job_record.state job_record.state = new_state job_record.related_unit_of_work = uow.db_id self.job_dao.update(job_record) msg = 'Updated Job {0} for {1}@{2}: state transfer {3} -> {4};' \ .format(job_record.db_id, job_record.process_name, job_...
<SYSTEM_TASK:> reads JSON request from the mq message and delivers it for processing <END_TASK> <USER_TASK:> Description: def _mq_callback(self, message): """ reads JSON request from the mq message and delivers it for processing """
while threading.active_count() > settings.settings['bash_runnable_count'] + self.initial_thread_count: time.sleep(0.1) t = BashRunnable(self.logger, message, self.consumer, self.performance_tracker) t.daemon = True t.start()
<SYSTEM_TASK:> Saves the state if it has changed. <END_TASK> <USER_TASK:> Description: def save_loop(self): """ Saves the state if it has changed. """
last_hash = hash(repr(self.hosts)) while self.running: eventlet.sleep(self.save_interval) next_hash = hash(repr(self.hosts)) if next_hash != last_hash: self.save() last_hash = next_hash
<SYSTEM_TASK:> Accepts management requests. <END_TASK> <USER_TASK:> Description: def management_loop(self, address, family): """ Accepts management requests. """
try: sock = eventlet.listen(address, family) except socket.error, e: logging.critical("Cannot listen on (%s, %s): %s" % (address, family, e)) return # Sleep to ensure we've dropped privileges by the time we start serving eventlet.sleep(0.5) # ...
<SYSTEM_TASK:> Accepts incoming connections. <END_TASK> <USER_TASK:> Description: def listen_loop(self, address, family, internal=False): """ Accepts incoming connections. """
try: sock = eventlet.listen(address, family) except socket.error, e: if e.errno == errno.EADDRINUSE: logging.critical("Cannot listen on (%s, %s): already in use" % (address, family)) raise elif e.errno == errno.EACCES and address[1] <=...
<SYSTEM_TASK:> Handles an incoming HTTP connection. <END_TASK> <USER_TASK:> Description: def handle(self, sock, address, internal=False): """ Handles an incoming HTTP connection. """
try: sock = StatsSocket(sock) rfile = sock.makefile('rb', 4096) # Read the first line first = rfile.readline().strip("\r\n") words = first.split() # Ensure it looks kind of like HTTP if not (2 <= len(words) <= 3): ...
<SYSTEM_TASK:> loads scheduler managed entries. no start-up procedures are performed <END_TASK> <USER_TASK:> Description: def _load_managed_entries(self): """ loads scheduler managed entries. no start-up procedures are performed """
for process_name, process_entry in context.process_context.items(): if isinstance(process_entry, ManagedProcessEntry): function = self.fire_managed_worker else: self.logger.warning('Skipping non-managed context entry {0} of type {1}.' ...
<SYSTEM_TASK:> reads scheduler managed entries and starts their timers to trigger events <END_TASK> <USER_TASK:> Description: def _load_freerun_entries(self): """ reads scheduler managed entries and starts their timers to trigger events """
freerun_entries = self.freerun_process_dao.get_all() for freerun_entry in freerun_entries: try: self._register_process_entry(freerun_entry, self.fire_freerun_worker) except Exception: self.logger.error('Freerun Thread Handler {0} failed to start. ...
<SYSTEM_TASK:> reads managed process entries and starts timer instances; starts dependant threads <END_TASK> <USER_TASK:> Description: def start(self, *_): """ reads managed process entries and starts timer instances; starts dependant threads """
self.logger.info('Starting Scheduler...') db_manager.synch_db() self._load_managed_entries() try: self._load_freerun_entries() except LookupError as e: self.logger.warning('DB Lookup: {0}'.format(e)) # Scheduler is initialized and running. Garba...
<SYSTEM_TASK:> requests next valid job for given process and manages its state <END_TASK> <USER_TASK:> Description: def fire_managed_worker(self, thread_handler_header): """ requests next valid job for given process and manages its state """
def _fire_worker(process_entry, prev_job_record): assert isinstance(process_entry, ManagedProcessEntry) job_record = self.timetable.get_next_job_record(process_entry.process_name) state_machine = self.timetable.state_machines[process_entry.state_machine_name] if...
<SYSTEM_TASK:> fires free-run worker with no dependencies to track <END_TASK> <USER_TASK:> Description: def fire_freerun_worker(self, thread_handler_header): """ fires free-run worker with no dependencies to track """
try: assert isinstance(thread_handler_header, ThreadHandlerHeader) self.logger.info('{0} {{'.format(thread_handler_header.key)) state_machine = self.timetable.state_machines[STATE_MACHINE_FREERUN] state_machine.manage_schedulable(thread_handler_header.process_en...
<SYSTEM_TASK:> The id of the sensor of this data point. <END_TASK> <USER_TASK:> Description: def sensor_id(self): """The id of the sensor of this data point. Returns: The id of the sensor that generated this datapoint. Will throw an AttributeError if no sensor id was found in t...
if hasattr(self, '_sensor_id'): return self._sensor_id relationships = self._json_data.get('relationships') sensor_id = relationships.get('sensor').get('data').get('id') self._sensor_id = sensor_id return sensor_id
<SYSTEM_TASK:> Post a new reading to a timeseries. <END_TASK> <USER_TASK:> Description: def create(self, port, value, timestamp=None): """Post a new reading to a timeseries. A reading is comprised of a `port`, a `value` and a timestamp. A port is like a tag for the given reading and gives an ...
session = self._session datapoint_class = self._datapoint_class attributes = { 'port': port, 'value': value, } if timestamp is not None: attributes['timestamp'] = to_iso_date(timestamp) attributes = build_request_body('data-point', Non...
<SYSTEM_TASK:> Get a live stream of timeseries readings. <END_TASK> <USER_TASK:> Description: def live(self): """Get a live stream of timeseries readings. This returns an Iterable over a live stream of readings. Note that the result will need to be closed since the system can not tell w...
session = self._session url = "{}/live".format(self._base_url) supported_params = frozenset(['filter[port]']) params = {k: v for k, v in iteritems(self._params) if k in supported_params} return session.live(url, self._datapoint_class, { 'is_aggregat...
<SYSTEM_TASK:> register dependencies between trees <END_TASK> <USER_TASK:> Description: def _register_dependencies(self): """ register dependencies between trees"""
for tree_name, context_entry in context.timetable_context.items(): tree = self.trees[tree_name] assert isinstance(tree, MultiLevelTree) for dependent_on in context_entry.dependent_on: dependent_on_tree = self.trees[dependent_on] assert isinsta...
<SYSTEM_TASK:> returns list of trees that are dependent_on given tree_obj <END_TASK> <USER_TASK:> Description: def _find_dependant_trees(self, tree_obj): """ returns list of trees that are dependent_on given tree_obj """
dependant_trees = [] for tree_name, tree in self.trees.items(): if tree_obj in tree.dependent_on: dependant_trees.append(tree) return dependant_trees
<SYSTEM_TASK:> method reprocesses the node and all its dependants and parent nodes <END_TASK> <USER_TASK:> Description: def reprocess_tree_node(self, tree_node, tx_context=None): """ method reprocesses the node and all its dependants and parent nodes """
if not tx_context: # create transaction context if one was not provided # format: {process_name: {timeperiod: AbstractTreeNode} } tx_context = collections.defaultdict(dict) if tree_node.parent is None: # do not process 'root' - the only node that has Non...
<SYSTEM_TASK:> method skips the node and all its dependants and child nodes <END_TASK> <USER_TASK:> Description: def skip_tree_node(self, tree_node, tx_context=None): """ method skips the node and all its dependants and child nodes """
if not tx_context: # create transaction context if one was not provided # format: {process_name: {timeperiod: AbstractTreeNode} } tx_context = collections.defaultdict(dict) if tree_node.timeperiod in tx_context[tree_node.process_name]: # the node has alr...
<SYSTEM_TASK:> - looks for an existing job record in the DB, and if not found <END_TASK> <USER_TASK:> Description: def assign_job_record(self, tree_node): """ - looks for an existing job record in the DB, and if not found - creates a job record in STATE_EMBRYO and bind it to the given tree node """
try: job_record = self.job_dao.get_one(tree_node.process_name, tree_node.timeperiod) except LookupError: state_machine_name = context.process_context[tree_node.process_name].state_machine_name state_machine = self.state_machines[state_machine_name] job_re...
<SYSTEM_TASK:> return tree that is managing time-periods for given process <END_TASK> <USER_TASK:> Description: def get_tree(self, process_name): """ return tree that is managing time-periods for given process"""
for tree_name, tree in self.trees.items(): if process_name in tree: return tree
<SYSTEM_TASK:> method iterated thru all documents in all job collections and builds a tree of known system state <END_TASK> <USER_TASK:> Description: def _build_tree_by_level(self, time_qualifier, collection_name, since): """ method iterated thru all documents in all job collections and builds a tree of known s...
invalid_tree_records = dict() invalid_tq_records = dict() try: job_records = self.job_dao.get_all(collection_name, since) for job_record in job_records: tree = self.get_tree(job_record.process_name) if tree is None: ut...
<SYSTEM_TASK:> method iterates thru all objects older than synergy_start_timeperiod parameter in job collections <END_TASK> <USER_TASK:> Description: def load_tree(self): """ method iterates thru all objects older than synergy_start_timeperiod parameter in job collections and loads them into this timeta...
timeperiod = settings.settings['synergy_start_timeperiod'] yearly_timeperiod = time_helper.cast_to_time_qualifier(QUALIFIER_YEARLY, timeperiod) monthly_timeperiod = time_helper.cast_to_time_qualifier(QUALIFIER_MONTHLY, timeperiod) daily_timeperiod = time_helper.cast_to_time_qualifier(QU...
<SYSTEM_TASK:> method is called from abstract_state_machine.manage_job to notify about job's failed processing <END_TASK> <USER_TASK:> Description: def skip_if_needed(self, job_record): """ method is called from abstract_state_machine.manage_job to notify about job's failed processing if should_skip...
tree = self.get_tree(job_record.process_name) node = tree.get_node(job_record.process_name, job_record.timeperiod) if tree.should_skip_tree_node(node): self.skip_tree_node(node)
<SYSTEM_TASK:> adds a non-persistent log entry to the tree node <END_TASK> <USER_TASK:> Description: def add_log_entry(self, process_name, timeperiod, msg): """ adds a non-persistent log entry to the tree node """
tree = self.get_tree(process_name) node = tree.get_node(process_name, timeperiod) node.add_log_entry([datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S'), msg])
<SYSTEM_TASK:> Save all data from a banks_manager <END_TASK> <USER_TASK:> Description: def save(self, banks_manager): """ Save all data from a banks_manager :param BanksManager banks_manager: BanksManager that your banks data will be persisted """
self.banks_files.delete_all_banks() self.banks_files.save(banks_manager) self.index_file.save(banks_manager)
<SYSTEM_TASK:> Applies kwargs arguments to the instance passed as the first <END_TASK> <USER_TASK:> Description: def apply(cls, self, *args, **kwargs): """ Applies kwargs arguments to the instance passed as the first argument to the call. For defined INPUTS, OUTPUTS and PARAMETERS the m...
for key in kwargs: if key in [ x.name for x in cls.INPUTS ]: setattr(self, key, kwargs[key]) if key in [ x.name for x in cls.OUTPUTS ]: setattr(self, key, kwargs[key]) if key in [ x.name for x in cls.PARAMETERS ]: setattr(self, key, kwargs[key])
<SYSTEM_TASK:> Generate spec for the processor as a Python dictionary. <END_TASK> <USER_TASK:> Description: def spec(self): """ Generate spec for the processor as a Python dictionary. A spec is a standard way to describe a MountainLab processor in a way that is easy to process, yet stil...
pspec = {} pspec['name'] = self.NAME pspec['version'] = self.VERSION pspec['description'] = self.DESCRIPTION #if hasattr(self, 'run') and callable(self.run): components = [sys.argv[0], self.NAME] if self.USE_ARGUMENTS: components.append('$(arguments)') ps...
<SYSTEM_TASK:> Executes the processor passing given arguments. <END_TASK> <USER_TASK:> Description: def invoke(proc, args=None, *, _instance = None, **kwargs): """ Executes the processor passing given arguments. :param args: a list of parameters in --key=value format. """
if args is None: args=[] for kwargname in kwargs: args.append('--'+kwargname) args.append('{}'.format(kwargs[kwargname])) parser = proc.invoke_parser(noexit=(_instance is not None)) opts = parser.parse_args(args) kwargs0 = {} def han...
<SYSTEM_TASK:> Returns the first occurrence of the pedalboard in your bank <END_TASK> <USER_TASK:> Description: def index(self): """ Returns the first occurrence of the pedalboard in your bank """
if self.bank is None: raise IndexError('Pedalboard not contains a bank') return self.bank.pedalboards.index(self)
<SYSTEM_TASK:> check for process' pid file and returns pid from there <END_TASK> <USER_TASK:> Description: def get_process_pid(process_name): """ check for process' pid file and returns pid from there """
try: pid_filename = get_pid_filename(process_name) with open(pid_filename, mode='r') as pid_file: pid = int(pid_file.read().strip()) except IOError: pid = None return pid
<SYSTEM_TASK:> stops the timer. call_back function is not called <END_TASK> <USER_TASK:> Description: def cancel(self): """ stops the timer. call_back function is not called """
self.event.clear() if self.__timer is not None: self.__timer.cancel()
<SYSTEM_TASK:> calls the call_back function. interrupts the timer to start a new countdown <END_TASK> <USER_TASK:> Description: def trigger(self): """ calls the call_back function. interrupts the timer to start a new countdown """
self.call_back(*self.args, **self.kwargs) if self.__timer is not None: self.__timer.cancel()
<SYSTEM_TASK:> method casts given timeperiod accordingly to time qualifier. <END_TASK> <USER_TASK:> Description: def cast_to_time_qualifier(time_qualifier, timeperiod): """ method casts given timeperiod accordingly to time qualifier. For example, will cast session time format of 20100101193412 to 2010010119 wit...
if time_qualifier == QUALIFIER_HOURLY: date_format = SYNERGY_HOURLY_PATTERN elif time_qualifier == QUALIFIER_DAILY: date_format = SYNERGY_DAILY_PATTERN elif time_qualifier == QUALIFIER_MONTHLY: date_format = SYNERGY_MONTHLY_PATTERN elif time_qualifier == QUALIFIER_YEARLY: ...
<SYSTEM_TASK:> method parses datetime and returns Synergy Date <END_TASK> <USER_TASK:> Description: def datetime_to_synergy(time_qualifier, dt): """ method parses datetime and returns Synergy Date"""
if time_qualifier == QUALIFIER_HOURLY: date_format = SYNERGY_HOURLY_PATTERN elif time_qualifier == QUALIFIER_DAILY: date_format = SYNERGY_DAILY_PATTERN elif time_qualifier == QUALIFIER_MONTHLY: date_format = SYNERGY_MONTHLY_PATTERN elif time_qualifier == QUALIFIER_YEARLY: ...
<SYSTEM_TASK:> method receives timeperiod in Synergy format YYYYMMDDHH and convert it to UTC _naive_ datetime <END_TASK> <USER_TASK:> Description: def synergy_to_datetime(time_qualifier, timeperiod): """ method receives timeperiod in Synergy format YYYYMMDDHH and convert it to UTC _naive_ datetime"""
if time_qualifier == QUALIFIER_HOURLY: date_format = SYNERGY_HOURLY_PATTERN elif time_qualifier == QUALIFIER_DAILY: date_format = SYNERGY_DAILY_PATTERN elif time_qualifier == QUALIFIER_MONTHLY: date_format = SYNERGY_MONTHLY_PATTERN elif time_qualifier == QUALIFIER_YEARLY: ...
<SYSTEM_TASK:> converts Synergy Timestamp for session to UTC zone seconds since epoch <END_TASK> <USER_TASK:> Description: def session_to_epoch(timestamp): """ converts Synergy Timestamp for session to UTC zone seconds since epoch """
utc_timetuple = datetime.strptime(timestamp, SYNERGY_SESSION_PATTERN).replace(tzinfo=None).utctimetuple() return calendar.timegm(utc_timetuple)
<SYSTEM_TASK:> Add an LV2 plugin encapsulated as a jack client <END_TASK> <USER_TASK:> Description: def add(self, effect): """ Add an LV2 plugin encapsulated as a jack client :param Lv2Effect effect: Effect that will be loaded as LV2 plugin encapsulated """
effect.instance = self.instance_index self.instance_index += 1 self.connection.send(ProtocolParser.add(effect))
<SYSTEM_TASK:> Quit the connection with mod-host <END_TASK> <USER_TASK:> Description: def close(self): """ Quit the connection with mod-host """
if self.connection is not None: self.connection.close() if self.connection_fd is not None: self.connection_fd.close()
<SYSTEM_TASK:> method reads collection and refine slice upper bound for processing <END_TASK> <USER_TASK:> Description: def update_scope_of_processing(self, process_name, uow, start_timeperiod, end_timeperiod): """method reads collection and refine slice upper bound for processing"""
source_collection_name = uow.source last_object_id = self.ds.lowest_primary_key(source_collection_name, start_timeperiod, end_timeperiod) uow.end_id = str(last_object_id) self.uow_dao.update(uow) msg = 'Updated processing range for {0}@{1} for collection {2}: [{3} : {4}]' \ ...
<SYSTEM_TASK:> method computes new unit_of_work and transfers the job to STATE_FINAL_RUN <END_TASK> <USER_TASK:> Description: def _compute_and_transfer_to_final_run(self, process_name, start_timeperiod, end_timeperiod, job_record): """ method computes new unit_of_work and transfers the job to STATE_FINAL_RUN ...
source_collection_name = context.process_context[process_name].source start_id = self.ds.highest_primary_key(source_collection_name, start_timeperiod, end_timeperiod) end_id = self.ds.lowest_primary_key(source_collection_name, start_timeperiod, end_timeperiod) uow, transfer_to_final = s...
<SYSTEM_TASK:> method translates given timeperiod to the grouped timeperiod <END_TASK> <USER_TASK:> Description: def _translate_timeperiod(self, timeperiod): """ method translates given timeperiod to the grouped timeperiod """
if self.time_grouping == 1: # no translation is performed for identity grouping return timeperiod # step 1: tokenize timeperiod into: (year, month, day, hour) # for instance: daily 2015031400 -> ('2015', '03', '14', '00') year, month, day, hour = time_helper.tok...
<SYSTEM_TASK:> return a response_dict with a list of search results in decending <END_TASK> <USER_TASK:> Description: def query_mongo_sort_decend( database_name, collection_name, query={}, skip=0, limit=getattr( settings, 'MONGO_LIMIT', 200), ...
l = [] response_dict = {} try: mongodb_client_url = getattr(settings, 'MONGODB_CLIENT', 'mongodb://localhost:27017/') mc = MongoClient(mongodb_client_url,document_class=OrderedDict) db = mc[str(database_name)] collection = db[str(colle...
<SYSTEM_TASK:> delete from mongo helper <END_TASK> <USER_TASK:> Description: def delete_mongo(database_name, collection_name, query={}, just_one=False): """delete from mongo helper"""
l = [] response_dict = {} try: mongodb_client_url = getattr(settings, 'MONGODB_CLIENT', 'mongodb://localhost:27017/') mc = MongoClient(mongodb_client_url, document_class=OrderedDict) db = mc[str(database_name)] collection = db[str(colle...
<SYSTEM_TASK:> Write a document to the collection. Return a response_dict containing <END_TASK> <USER_TASK:> Description: def write_mongo(document, database_name, collection_name, update=False): """Write a document to the collection. Return a response_dict containing the written record. Method f...
l = [] response_dict = {} try: mongodb_client_url = getattr(settings, 'MONGODB_CLIENT', 'mongodb://localhost:27017/') mc = MongoClient(mongodb_client_url,document_class=OrderedDict) db = mc[str(database_name)] collection = db[str(collection_...
<SYSTEM_TASK:> return a result list or an empty list <END_TASK> <USER_TASK:> Description: def raw_query_mongo_db(kwargs, database_name, collection_name): # for key in kwargs: # print "arg: %s: %s" % (key, kwargs[key]) """return a result list or an empty list"""
l = [] response_dict = {} try: mongodb_client_url = getattr(settings, 'MONGODB_CLIENT', 'mongodb://localhost:27017/') mc = MongoClient(mongodb_client_url,document_class=OrderedDict) db = mc[database_name] transactions = db[collection_name] ...
<SYSTEM_TASK:> d is a dict <END_TASK> <USER_TASK:> Description: def cast_number_strings_to_integers(d): """d is a dict"""
for k, v in d.items(): # print type(v) if determine_if_str_or_unicode(v): if v.isdigit(): d[k] = int(v) return d
<SYSTEM_TASK:> method returns either RestJob instance or corresponding document, depending on the as_model argument <END_TASK> <USER_TASK:> Description: def get_details(cls, node, as_model=False): """method returns either RestJob instance or corresponding document, depending on the as_model argument """
rest_job = RestJob( process_name=node.process_name, timeperiod=node.timeperiod, time_qualifier=node.time_qualifier, number_of_children=len(node.children), number_of_failures='NA' if not node.job_record else node.job_record.number_of_failures, ...
<SYSTEM_TASK:> Generate the system effect based in pedalboard_info <END_TASK> <USER_TASK:> Description: def discover_system_effect(self, pedalboard_info): """ Generate the system effect based in pedalboard_info :param dict pedalboard_info: For obtain this, see :meth:`~pluginsmanager...
# MOD swap ins and outs!!! hardware = pedalboard_info['hardware'] total_audio_outs = hardware['audio_ins'] total_audio_ins = hardware['audio_outs'] outputs = ['capture_{}'.format(i) for i in range(1, total_audio_outs+1)] inputs = ['playback_{}'.format(i) for i in range...