text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_tolerance_params(self, for_heartbeat=None, for_cursed_vassals=None): """Various tolerance options. :param int for_heartbeat: Set the Emperor tolerance ab...
self._set('emperor-required-heartbeat', for_heartbeat) self._set('emperor-curse-tolerance', for_cursed_vassals) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_mode_broodlord_params( self, zerg_count=None, vassal_overload_sos_interval=None, vassal_queue_items_sos=None): """This mode is a way for a vassal to ask ...
self._set('emperor-broodlord', zerg_count) self._set('vassal-sos', vassal_overload_sos_interval) self._set('vassal-sos-backlog', vassal_queue_items_sos) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run_command_as_worker(self, command, after_post_fork_hook=False): """Run the specified command as worker. :param str|unicode command: :param bool after_post_...
self._set('worker-exec2' if after_post_fork_hook else 'worker-exec', command, multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_count_auto(self, count=None): """Sets workers count. By default sets it to detected number of available cores :param int count: """
count = count or self._section.vars.CPU_CORES self._set('workers', count) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_thread_params( self, enable=None, count=None, count_offload=None, stack_size=None, no_wait=None): """Sets threads related params. :param bool enable: Ena...
self._set('enable-threads', enable, cast=bool) self._set('no-threads-wait', no_wait, cast=bool) self._set('threads', count) self._set('offload-threads', count_offload) if count: self._section.print_out('Threads per worker: %s' % count) self._set('threads-st...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_mules_params( self, mules=None, touch_reload=None, harakiri_timeout=None, farms=None, reload_mercy=None, msg_buffer=None, msg_buffer_recv=None): """Sets ...
farms = farms or [] next_mule_number = 1 farm_mules_count = 0 for farm in farms: if isinstance(farm.mule_numbers, int): farm.mule_numbers = list(range(next_mule_number, next_mule_number + farm.mule_numbers)) next_mule_number = farm.mule_num...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_reload_params( self, min_lifetime=None, max_lifetime=None, max_requests=None, max_requests_delta=None, max_addr_space=None, max_rss=None, max_uss=None, ma...
self._set('max-requests', max_requests) self._set('max-requests-delta', max_requests_delta) self._set('min-worker-lifetime', min_lifetime) self._set('max-worker-lifetime', max_lifetime) self._set('reload-on-as', max_addr_space) self._set('reload-on-rss', max_rss) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_reload_on_exception_params(self, do_reload=None, etype=None, evalue=None, erepr=None): """Sets workers reload on exceptions parameters. :param bool do_re...
self._set('reload-on-exception', do_reload, cast=bool) self._set('reload-on-exception-type', etype) self._set('reload-on-exception-value', evalue) self._set('reload-on-exception-repr', erepr) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_harakiri_params(self, timeout=None, verbose=None, disable_for_arh=None): """Sets workers harakiri parameters. :param int timeout: Harakiri timeout in sec...
self._set('harakiri', timeout) self._set('harakiri-verbose', verbose, cast=bool) self._set('harakiri-no-arh', disable_for_arh, cast=bool) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_zerg_server_params(self, socket, clients_socket_pool=None): """Zerg mode. Zerg server params. When your site load is variable, it would be nice to be abl...
if clients_socket_pool: self._set('zergpool', '%s:%s' % (socket, ','.join(listify(clients_socket_pool))), multi=True) else: self._set('zerg-server', socket) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_zerg_client_params(self, server_sockets, use_fallback_socket=None): """Zerg mode. Zergs params. :param str|unicode|list[str|unicode] server_sockets: Atta...
self._set('zerg', server_sockets, multi=True) if use_fallback_socket is not None: self._set('zerg-fallback', use_fallback_socket, cast=bool) for socket in listify(server_sockets): self._section.networking.register_socket(self._section.networking.sockets.default...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def format_print_text(text, color_fg=None, color_bg=None): """Format given text using ANSI formatting escape sequences. Could be useful gfor print command. :para...
from .config import Section color_fg = { 'black': '30', 'red': '31', 'reder': '91', 'green': '32', 'greener': '92', 'yellow': '33', 'yellower': '93', 'blue': '34', 'bluer': '94', 'magenta': '35', 'magenter': '95', ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def iter_options(self): """Iterates configuration sections groups options."""
for section in self.sections: name = str(section) for key, value in section._get_options(): yield name, key, value
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_memory_params(self, ksm_interval=None, no_swap=None): """Set memory related parameters. :param int ksm_interval: Kernel Samepage Merging frequency option...
self._set('ksm', ksm_interval) self._set('never_swap', no_swap, cast=bool) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def daemonize(self, log_into, after_app_loading=False): """Daemonize uWSGI. :param str|unicode log_into: Logging destination: * File: /tmp/mylog.log * UPD: 192.1...
self._set('daemonize2' if after_app_loading else 'daemonize', log_into) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def change_dir(self, to, after_app_loading=False): """Chdir to specified directory before or after apps loading. :param str|unicode to: Target directory. :param ...
self._set('chdir2' if after_app_loading else 'chdir', to) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_owner_params(self, uid=None, gid=None, add_gids=None, set_asap=False): """Set process owner params - user, group. :param str|unicode|int uid: Set uid to ...
prefix = 'immediate-' if set_asap else '' self._set(prefix + 'uid', uid) self._set(prefix + 'gid', gid) self._set('add-gid', add_gids, multi=True) # This may be wrong for subsequent method calls. self.owner = [uid, gid] return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_hook_touch(self, fpath, action): """Allows running certain action when the specified file is touched. :param str|unicode fpath: File path. :param str|uni...
self._set('hook-touch', '%s %s' % (fpath, action), multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_on_exit_params(self, skip_hooks=None, skip_teardown=None): """Set params related to process exit procedure. :param bool skip_hooks: Skip ``EXIT`` phase h...
self._set('skip-atexit', skip_hooks, cast=bool) self._set('skip-atexit-teardown', skip_teardown, cast=bool) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run_command_on_event(self, command, phase=phases.ASAP): """Run the given command on a given phase. :param str|unicode command: :param str|unicode phase: See ...
self._set('exec-%s' % phase, command, multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_pid_file(self, fpath, before_priv_drop=True, safe=False): """Creates pidfile before or after privileges drop. :param str|unicode fpath: File path. :param...
command = 'pidfile' if not before_priv_drop: command += '2' if safe: command = 'safe-' + command self._set(command, fpath) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_naming_params(self, autonaming=None, prefix=None, suffix=None, name=None): """Setups processes naming parameters. :param bool autonaming: Automatically s...
self._set('auto-procname', autonaming, cast=bool) self._set('procname-prefix%s' % ('-spaced' if prefix and prefix.endswith(' ') else ''), prefix) self._set('procname-append', suffix) self._set('procname', name) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def errorprint(): """Print out descriptions from ConfigurationError."""
try: yield except ConfigurationError as e: click.secho('%s' % e, err=True, fg='red') sys.exit(1)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run(conf, only): """Runs uWSGI passing to it using the default or another `uwsgiconf` configuration module. """
with errorprint(): config = ConfModule(conf) spawned = config.spawn_uwsgi(only) for alias, pid in spawned: click.secho("Spawned uWSGI for configuration aliased '%s'. PID %s" % (alias, pid), fg='green')
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def compile(conf): """Compiles classic uWSGI configuration file using the default or given `uwsgiconf` configuration module. """
with errorprint(): config = ConfModule(conf) for conf in config.configurations: conf.format(do_print=True)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def sysinit(systype, conf, project): """Outputs configuration for system initialization subsystem."""
click.secho(get_config( systype, conf=ConfModule(conf).configurations[0], conf_path=conf, project_name=project, ))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def probe_plugins(): """Runs uWSGI to determine what plugins are available and prints them out. Generic plugins come first then after blank line follow request p...
plugins = UwsgiRunner().get_plugins() for plugin in sorted(plugins.generic): click.secho(plugin) click.secho('') for plugin in sorted(plugins.request): click.secho(plugin)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def register_handler(self, target=None): """Decorator for a function to be used as a signal handler. :param str|unicode target: Where this signal will be deliver...
target = target or 'worker' sign_num = self.num def wrapper(func): _LOG.debug("Registering '%s' as signal '%s' handler ...", func.__name__, sign_num) uwsgi.register_signal(sign_num, target, func) return func return wrapper
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add(self, work_dir, external=False): """Run a spooler on the specified directory. :param str|unicode work_dir: .. note:: Placeholders can be used to build pa...
command = 'spooler' if external: command += '-external' self._set(command, self._section.replace_placeholders(work_dir), multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def configure(self): """Configures broodlord mode and returns emperor and zerg sections. :rtype: tuple """
section_emperor = self.section_emperor section_zerg = self.section_zerg socket = self.socket section_emperor.workers.set_zerg_server_params(socket=socket) section_emperor.empire.set_emperor_params(vassals_home=self.vassals_home) section_emperor.empire.set_mode_broodlor...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_log_format_default(self): """Returns default log message format. .. note:: Some params may be missing. """
vars = self.logging.vars format_default = ( '[pid: %s|app: %s|req: %s/%s] %s (%s) {%s vars in %s bytes} [%s] %s %s => ' 'generated %s bytes in %s %s%s(%s %s) %s headers in %s bytes (%s switches on core %s)' % ( vars.WORKER_PID, '-', # app id ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def configure_owner(self, owner='www-data'): """Shortcut to set process owner data. :param str|unicode owner: Sets user and group. Default: ``www-data``. """
if owner is not None: self.main_process.set_owner_params(uid=owner, gid=owner) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def alarm_on_fd_ready(self, alarm, fd, message, byte_count=None): """Triggers the alarm when the specified file descriptor is ready for read. This is really usef...
self.register_alarm(alarm) value = fd if byte_count: value += ':%s' % byte_count value += ' %s' % message for alarm in listify(alarm): self._set('alarm-fd', '%s %s' % (alarm.alias, value), multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def alarm_on_segfault(self, alarm): """Raise the specified alarm when the segmentation fault handler is executed. Sends a backtrace. :param AlarmType|list[AlarmT...
self.register_alarm(alarm) for alarm in listify(alarm): self._set('alarm-segfault', alarm.alias, multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_config(systype, conf, conf_path, runner=None, project_name=None): """Returns init system configuration file contents. :param str|unicode systype: System ...
runner = runner or ('%s run' % Finder.uwsgiconf()) conf_path = abspath(conf_path) if isinstance(conf, Configuration): conf = conf.sections[0] # todo Maybe something more intelligent. tpl = dedent(TEMPLATES.get(systype)(conf=conf)) formatted = tpl.strip().format( project=project_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def app_1(env, start_response): """This is simple WSGI application that will be served by uWSGI."""
from uwsgiconf.runtime.environ import uwsgi_env start_response('200 OK', [('Content-Type','text/html')]) data = [ '<h1>uwsgiconf demo: one file</h1>', '<div>uWSGI version: %s</div>' % uwsgi_env.get_version(), '<div>uWSGI request ID: %s</div>' % uwsgi_env.request.id, ] r...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def app_2(env, start_response): """This is another simple WSGI application that will be served by uWSGI."""
import random start_response('200 OK', [('Content-Type','text/html')]) data = [ '<h1>uwsgiconf demo: one file second app</h1>', '<div>Some random number for you: %s</div>' % random.randint(1, 99999), ] return encode(data)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def configure(): """Configure uWSGI. This returns several configuration objects, which will be used to spawn several uWSGI processes. Applications are on 127.0.0...
import os from uwsgiconf.presets.nice import PythonSection FILE = os.path.abspath(__file__) port = 8000 configurations = [] for idx in range(2): alias = 'app_%s' % (idx + 1) section = PythonSection( # Automatically reload uWSGI if this file is changed. ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def log_into(self, target, before_priv_drop=True): """Simple file or UDP logging. .. note:: This doesn't require any Logger plugin and can be used if no log rout...
command = 'logto' if not before_priv_drop: command += '2' self._set(command, target) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_file_params( self, reopen_on_reload=None, trucate_on_statup=None, max_size=None, rotation_fname=None, touch_reopen=None, touch_rotate=None, owner=None, mo...
self._set('log-reopen', reopen_on_reload, cast=bool) self._set('log-truncate', trucate_on_statup, cast=bool) self._set('log-maxsize', max_size) self._set('log-backupname', rotation_fname) self._set('touch-logreopen', touch_reopen, multi=True) self._set('touch-logrotate'...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_master_logging_params( self, enable=None, dedicate_thread=None, buffer=None, sock_stream=None, sock_stream_requests_only=None): """Sets logging params fo...
self._set('log-master', enable, cast=bool) self._set('threaded-logger', dedicate_thread, cast=bool) self._set('log-master-bufsize', buffer) self._set('log-master-stream', sock_stream, cast=bool) if sock_stream_requests_only: self._set('log-master-req-stream', sock_...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_logger_route(self, logger, matcher, requests_only=False): """Log to the specified named logger if regexp applied on log item matches. :param str|unicode|...
command = 'log-req-route' if requests_only else 'log-route' for logger in listify(logger): self._set(command, '%s %s' % (logger, matcher), multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_logger_encoder(self, encoder, logger=None, requests_only=False, for_single_worker=False): """Add an item in the log encoder or request encoder chain. * h...
if for_single_worker: command = 'worker-log-req-encoder' if requests_only else 'worker-log-encoder' else: command = 'log-req-encoder' if requests_only else 'log-encoder' for encoder in listify(encoder): value = '%s' % encoder if logger: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_metrics_params(self, enable=None, store_dir=None, restore=None, no_cores=None): """Sets basic Metrics subsystem params. uWSGI metrics subsystem allows yo...
self._set('enable-metrics', enable, cast=bool) self._set('metrics-dir', self._section.replace_placeholders(store_dir)) self._set('metrics-dir-restore', restore, cast=bool) self._set('metrics-no-cores', no_cores, cast=bool) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_metrics_threshold(self, name, value, check_interval=None, reset_to=None, alarm=None, alarm_message=None): """Sets metric threshold parameters. :param str...
if alarm is not None and isinstance(alarm, AlarmType): self._section.alarms.register_alarm(alarm) alarm = alarm.alias value = KeyValue( locals(), aliases={ 'name': 'key', 'reset_to': 'reset', 'check_interva...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_stats_params( self, address=None, enable_http=None, minify=None, no_cores=None, no_metrics=None, push_interval=None): """Enables stats server on the spec...
self._set('stats-server', address) self._set('stats-http', enable_http, cast=bool) self._set('stats-minified', minify, cast=bool) self._set('stats-no-cores', no_cores, cast=bool) self._set('stats-no-metrics', no_metrics, cast=bool) self._set('stats-pusher-default-freq', ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def enable_snmp(self, address, community_string): """Enables SNMP. uWSGI server embeds a tiny SNMP server that you can use to integrate your web apps with your m...
self._set('snmp', address) self._set('snmp-community', community_string) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def mount(self, mountpoint, app, into_worker=False): """Load application under mountpoint. Example: * .mount('', 'app0.py') -- Root URL part * .mount('/app1', 'a...
# todo check worker mount -- uwsgi_init_worker_mount_app() expects worker:// self._set('worker-mount' if into_worker else 'mount', '%s=%s' % (mountpoint, app), multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def switch_into_lazy_mode(self, affect_master=None): """Load apps in workers instead of master. This option may have memory usage implications as Copy-on-Write s...
self._set('lazy' if affect_master else 'lazy-apps', True, cast=bool) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_manage_params( self, chunked_input=None, chunked_output=None, gzip=None, websockets=None, source_method=None, rtsp=None, proxy_protocol=None): """Allows ...
self._set_aliased('chunked-input', chunked_input, cast=bool) self._set_aliased('auto-chunked', chunked_output, cast=bool) self._set_aliased('auto-gzip', gzip, cast=bool) self._set_aliased('websockets', websockets, cast=bool) self._set_aliased('manage-source', source_method, cast...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_owner_params(self, uid=None, gid=None): """Drop http router privileges to specified user and group. :param str|unicode|int uid: Set uid to the specified ...
self._set_aliased('uid', uid) self._set_aliased('gid', gid) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_postbuffering_params(self, size=None, store_dir=None): """Sets buffering params. Web-proxies like nginx are "buffered", so they wait til the whole reques...
self._set_aliased('post-buffering', size) self._set_aliased('post-buffering-dir', store_dir) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_window_params(self, cols=None, rows=None): """Sets pty window params. :param int cols: :param int rows: """
self._set_aliased('cols', cols) self._set_aliased('rows', rows) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def register_route(self, src, dst, gateway): """Adds a routing rule to the tuntap router. :param str|unicode src: Source/mask. :param str|unicode dst: Destinatio...
self._set_aliased('router-route', ' '.join((src, dst, gateway)), multi=True) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def device_add_rule(self, direction, action, src, dst, target=None): """Adds a tuntap device rule. To be used in a vassal. :param str|unicode direction: Directio...
value = [direction, src, dst, action] if target: value.append(target) self._set_aliased('device-rule', ' '.join(value), multi=True) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def add_firewall_rule(self, direction, action, src=None, dst=None): """Adds a firewall rule to the router. The TunTap router includes a very simple firewall for ...
value = [action] if src: value.extend((src, dst)) self._set_aliased('router-firewall-%s' % direction.lower(), ' '.join(value), multi=True) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def configure_uwsgi(configurator_func): """Allows configuring uWSGI using Configuration objects returned by the given configuration function. .. code-block: pyth...
from .settings import ENV_CONF_READY, ENV_CONF_ALIAS, CONFIGS_MODULE_ATTR if os.environ.get(ENV_CONF_READY): # This call is from uWSGI trying to load an application. # We prevent unnecessary configuration # for setups where application is located in the same # file as configur...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def print_stamp(self): """Prints out a stamp containing useful information, such as what and when has generated this configuration. """
from . import VERSION print_out = partial(self.print_out, format_options='red') print_out('This configuration was automatically generated using') print_out('uwsgiconf v%s on %s' % ('.'.join(map(str, VERSION)), datetime.now().isoformat(' '))) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def print_out(self, value, indent=None, format_options=None, asap=False): """Prints out the given value. :param value: :param str|unicode indent: :param dict|str...
if indent is None: indent = '> ' text = indent + str(value) if format_options is None: format_options = 'gray' if self._style_prints and format_options: if not isinstance(format_options, dict): format_options = {'color_fg': forma...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def print_variables(self): """Prints out magic variables available in config files alongside with their values and descriptions. May be useful for debugging. htt...
print_out = partial(self.print_out, format_options='green') print_out('===== variables =====') for var, hint in self.vars.get_descriptions().items(): print_out(' %' + var + ' = ' + var + ' = ' + hint.replace('%', '%%')) print_out('=====================') retur...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_plugins_params(self, plugins=None, search_dirs=None, autoload=None, required=False): """Sets plugin-related parameters. :param list|str|unicode|OptionsGr...
plugins = plugins or [] command = 'need-plugin' if required else 'plugin' for plugin in listify(plugins): if plugin not in self._plugins: self._set(command, plugin, multi=True) self._plugins.append(plugin) self._set('plugins-dir', search_d...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_fallback(self, target): """Sets a fallback configuration for section. Re-exec uWSGI with the specified config when exit code is 1. :param str|unicode|Sec...
if isinstance(target, Section): target = ':' + target.name self._set('fallback-config', target) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_placeholder(self, key, value): """Placeholders are custom magic variables defined during configuration time. .. note:: These are accessible, like any uWS...
self._set('set-placeholder', '%s=%s' % (key, value), multi=True) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def include(self, target): """Includes target contents into config. :param str|unicode|Section|list target: File path or Section to include. """
for target_ in listify(target): if isinstance(target_, Section): target_ = ':' + target_.name self._set('ini', target_, multi=True) return self
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def derive_from(cls, section, name=None): """Creates a new section based on the given. :param Section section: Section to derive from, :param str|unicode name: N...
new_section = deepcopy(section) if name: new_section.name = name return new_section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _validate_sections(cls, sections): """Validates sections types and uniqueness."""
names = [] for section in sections: if not hasattr(section, 'name'): raise ConfigurationError('`sections` attribute requires a list of Section') name = section.name if name in names: raise ConfigurationError('`%s` section name must b...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def format(self, do_print=False, stamp=True): """Applies formatting to configuration. *Currently formats to .ini* :param bool do_print: Whether to print out form...
if stamp and self.sections: self.sections[0].print_stamp() formatted = IniFormatter(self.sections).format() if do_print: print(formatted) return formatted
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def tofile(self, filepath=None): """Saves configuration into a file and returns its path. Convenience method. :param str|unicode filepath: Filepath to save confi...
if filepath is None: with NamedTemporaryFile(prefix='%s_' % self.alias, suffix='.ini', delete=False) as f: filepath = f.name else: filepath = os.path.abspath(filepath) if os.path.isdir(filepath): filepath = os.path.join(filepath, '%s...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _set_name(self, version=AUTO): """Returns plugin name."""
name = 'python' if version: if version is AUTO: version = sys.version_info[0] if version == 2: version = '' name = '%s%s' % (name, version) self.name = name
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_app_args(self, *args): """Sets ``sys.argv`` for python apps. Examples: * pyargv="one two three" will set ``sys.argv`` to ``('one', 'two', 'three')``. :pa...
if args: self._set('pyargv', ' '.join(args)) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_wsgi_params(self, module=None, callable_name=None, env_strategy=None): """Set wsgi related parameters. :param str|unicode module: * load .wsgi file as th...
module = module or '' if '/' in module: self._set('wsgi-file', module, condition=module) else: self._set('wsgi', module, condition=module) self._set('callable', callable_name) self._set('wsgi-env-behaviour', env_strategy) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_autoreload_params(self, scan_interval=None, ignore_modules=None): """Sets autoreload related parameters. :param int scan_interval: Seconds. Monitor Pytho...
self._set('py-auto-reload', scan_interval) self._set('py-auto-reload-ignore', ignore_modules, multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def register_module_alias(self, alias, module_path, after_init=False): """Adds an alias for a module. http://uwsgi-docs.readthedocs.io/en/latest/PythonModuleAlia...
command = 'post-pymodule-alias' if after_init else 'pymodule-alias' self._set(command, '%s=%s' % (alias, module_path), multi=True) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def import_module(self, modules, shared=False, into_spooler=False): """Imports a python module. :param list|str|unicode modules: :param bool shared: Import a pyt...
if all((shared, into_spooler)): raise ConfigurationError('Unable to set both `shared` and `into_spooler` flags') if into_spooler: command = 'spooler-python-import' else: command = 'shared-python-import' if shared else 'python-import' self._set(comma...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_server_params( self, client_notify_address=None, mountpoints_depth=None, require_vassal=None, tolerance=None, tolerance_inactive=None, key_dot_split=None)...
# todo notify-socket (fallback) relation self._set('subscription-notify-socket', client_notify_address) self._set('subscription-mountpoint', mountpoints_depth) self._set('subscription-vassal-required', require_vassal, cast=bool) self._set('subscription-tolerance', tolerance) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_server_verification_params( self, digest_algo=None, dir_cert=None, tolerance=None, no_check_uid=None, dir_credentials=None, pass_unix_credentials=None): ...
if digest_algo and dir_cert: self._set('subscriptions-sign-check', '%s:%s' % (digest_algo, dir_cert)) self._set('subscriptions-sign-check-tolerance', tolerance) self._set('subscriptions-sign-skip-uid', no_check_uid, multi=True) self._set('subscriptions-credentials-check', d...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_client_params( self, start_unsubscribed=None, clear_on_exit=None, unsubscribe_on_reload=None, announce_interval=None): """Sets subscribers related params...
self._set('start-unsubscribed', start_unsubscribed, cast=bool) self._set('subscription-clear-on-shutdown', clear_on_exit, cast=bool) self._set('unsubscribe-on-graceful-reload', unsubscribe_on_reload, cast=bool) self._set('subscribe-freq', announce_interval) return self._section
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def subscribe( self, server=None, key=None, address=None, address_vassal=None, balancing_weight=None, balancing_algo=None, modifier=None, signing=None, check_file...
# todo params: inactive (inactive slot activation) if not any((server, key)): raise ConfigurationError('Subscription requires `server` or `key` to be set.') address_key = 'addr' if isinstance(address, int): address_key = 'socket' if balancing_algo: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def find_project_dir(): """Runs up the stack to find the location of manage.py which will be considered a project base path. :rtype: str|unicode """
frame = inspect.currentframe() while True: frame = frame.f_back fname = frame.f_globals['__file__'] if os.path.basename(fname) == 'manage.py': break return os.path.dirname(fname)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def run_uwsgi(config_section, compile_only=False): """Runs uWSGI using the given section configuration. :param Section config_section: :param bool compile_only: ...
config = config_section.as_configuration() if compile_only: config.print_ini() return config_path = config.tofile() os.execvp('uwsgi', ['uwsgi', '--ini=%s' % config_path])
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def spawn(cls, options=None, dir_base=None): """Alternative constructor. Creates a mutator and returns section object. :param dict options: :param str|unicode di...
from uwsgiconf.utils import ConfModule options = options or { 'compile': True, } dir_base = os.path.abspath(dir_base or find_project_dir()) name_module = ConfModule.default_name name_project = get_project_name(dir_base) path_conf = os.path.join(dir...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _get_section_new(cls, dir_base): """Creates a new section with default settings. :param str|unicode dir_base: :rtype: Section """
from uwsgiconf.presets.nice import PythonSection from django.conf import settings wsgi_app = settings.WSGI_APPLICATION path_wsgi, filename, _, = wsgi_app.split('.') path_wsgi = os.path.join(dir_base, path_wsgi, '%s.py' %filename) section = PythonSection( w...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def contribute_static(self): """Contributes static and media file serving settings to an existing section."""
options = self.options if options['compile'] or not options['use_static_handler']: return from django.core.management import call_command settings = self.settings statics = self.section.statics statics.register_static_map(settings.STATIC_URL, settings.STAT...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def contribute_error_pages(self): """Contributes generic static error massage pages to an existing section."""
static_dir = self.settings.STATIC_ROOT if not static_dir: # Source static directory is not configured. Use temporary. import tempfile static_dir = os.path.join(tempfile.gettempdir(), self.project_name) self.settings.STATIC_ROOT = static_dir sel...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def mutate(self): """Mutates current section."""
section = self.section project_name = self.project_name section.project_name = project_name self.contribute_runtime_dir() main = section.main_process main.set_naming_params(prefix='[%s] ' % project_name) main.set_pid_file( self.get_pid_filepath(),...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set(self, value, mode=None): """Sets metric value. :param int|long value: New value. :param str|unicode mode: Update mode. * None - Unconditional update. * m...
if mode == 'max': func = uwsgi.metric_set_max elif mode == 'min': func = uwsgi.metric_set_min else: func = uwsgi.metric_set return func(self.name, value)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_message(cls, signals=True, farms=False, buffer_size=65536, timeout=-1): """Block until a mule message is received and return it. This can be called from ...
return decode(uwsgi.mule_get_msg(signals, farms, buffer_size, timeout))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parse_command_plugins_output(out): """Parses ``plugin-list`` command output from uWSGI and returns object containing lists of embedded plugin names. :param s...
out = out.split('--- end of plugins list ---')[0] out = out.partition('plugins ***')[2] out = out.splitlines() current_slot = 0 plugins = EmbeddedPlugins([], []) for line in out: line = line.strip() if not line: continue if line.startswith('***'): ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_uwsgi_stub_attrs_diff(): """Returns attributes difference two elements tuple between real uwsgi module and its stub. Might be of use while describing in ...
try: import uwsgi except ImportError: from uwsgiconf.exceptions import UwsgiconfException raise UwsgiconfException( '`uwsgi` module is unavailable. Calling `get_attrs_diff` in such environment makes no sense.') from . import uwsgi_stub def get_attrs(src): ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def configurations(self): """Configurations from uwsgiconf module."""
if self._confs is not None: return self._confs with output_capturing(): module = self.load(self.fpath) confs = getattr(module, CONFIGS_MODULE_ATTR) confs = listify(confs) self._confs = confs return confs
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def load(cls, fpath): """Loads a module and returns its object. :param str|unicode fpath: :rtype: module """
module_name = os.path.splitext(os.path.basename(fpath))[0] sys.path.insert(0, os.path.dirname(fpath)) try: module = import_module(module_name) finally: sys.path = sys.path[1:] return module
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cmd_log(self, reopen=False, rotate=False): """Allows managing of uWSGI log related stuff :param bool reopen: Reopen log file. Could be required after third p...
cmd = b'' if reopen: cmd += b'l' if rotate: cmd += b'L' return self.send_command(cmd)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def cmd_reload(self, force=False, workers_only=False, workers_chain=False): """Reloads uWSGI master process, workers. :param bool force: Use forced (brutal) relo...
if workers_chain: return self.send_command(b'c') if workers_only: return self.send_command(b'R' if force else b'r') return self.send_command(b'R' if force else b'r')
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def send_command(self, cmd): """Sends a generic command into FIFO. :param bytes cmd: Command chars to send into FIFO. """
if not cmd: return with open(self.fifo, 'wb') as f: f.write(cmd)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def prepare_env(cls): """Prepares current environment and returns Python binary name. This adds some virtualenv friendliness so that we try use uwsgi from it. :r...
os.environ['PATH'] = cls.get_env_path() return os.path.basename(Finder.python())
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def spawn(self, filepath, configuration_alias, replace=False): """Spawns uWSGI using the given configuration module. :param str|unicode filepath: :param str|unic...
# Pass --conf as an argument to have a chance to use # touch reloading form .py configuration file change. args = ['uwsgi', '--ini', 'exec://%s %s --conf %s' % (self.binary_python, filepath, configuration_alias)] if replace: return os.execvp('uwsgi', args) return o...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get(self, key, default=None, as_int=False, setter=None): """Gets a value from the cache. :param str|unicode key: The cache key to get value for. :param defau...
if as_int: val = uwsgi.cache_num(key, self.name) else: val = decode(uwsgi.cache_get(key, self.name)) if val is None: if setter is None: return default val = setter(key) if val is None: return default...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set(self, key, value): """Sets the specified key value. :param str|unicode key: :param int|str|unicode value: :rtype: bool """
return uwsgi.cache_set(key, value, self.timeout, self.name)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def decr(self, key, delta=1): """Decrements the specified key value by the specified value. :param str|unicode key: :param int delta: :rtype: bool """
return uwsgi.cache_dec(key, delta, self.timeout, self.name)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def mul(self, key, value=2): """Multiplies the specified key value by the specified value. :param str|unicode key: :param int value: :rtype: bool """
return uwsgi.cache_mul(key, value, self.timeout, self.name)