_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q254700 | IntermediateCatchEventParser.get_event_definition | validation | def get_event_definition(self):
"""
Parse the event definition node, and return an instance of Event
"""
messageEventDefinition = first(
self.xpath('.//bpmn:messageEventDefinition'))
if messageEventDefinition is not None:
return self.get_message_event_defi... | python | {
"resource": ""
} |
q254701 | IntermediateCatchEventParser.get_message_event_definition | validation | def get_message_event_definition(self, messageEventDefinition):
"""
Parse the messageEventDefinition node and return an instance of
MessageEventDefinition
"""
messageRef = first(self.xpath('.//bpmn:messageRef'))
message = messageRef.get(
'name') if messageRef ... | python | {
"resource": ""
} |
q254702 | IntermediateCatchEventParser.get_timer_event_definition | validation | def get_timer_event_definition(self, timerEventDefinition):
"""
Parse the timerEventDefinition node and return an instance of
TimerEventDefinition
This currently only supports the timeDate node for specifying an expiry
time for the timer.
"""
timeDate = first(sel... | python | {
"resource": ""
} |
q254703 | BpmnProcessSpec.to_html_string | validation | def to_html_string(self):
"""
Returns an etree HTML node with a document describing the process. This
is only supported if the editor provided an SVG representation.
"""
html = ET.Element('html')
head = ET.SubElement(html, 'head')
title = ET.SubElement(head, 'titl... | python | {
"resource": ""
} |
q254704 | Event.connect | validation | def connect(self, callback, *args, **kwargs):
"""
Connects the event with the given callback.
When the signal is emitted, the callback is invoked.
.. note::
The signal handler is stored with a hard reference, so you
need to make sure to call :class:`disconnect()... | python | {
"resource": ""
} |
q254705 | Event.n_subscribers | validation | def n_subscribers(self):
"""
Returns the number of connected subscribers.
:rtype: int
:returns: The number of subscribers.
"""
hard = self.hard_subscribers and len(self.hard_subscribers) or 0
weak = self.weak_subscribers and len(self.weak_subscribers) or 0
... | python | {
"resource": ""
} |
q254706 | Event.is_connected | validation | def is_connected(self, callback):
"""
Returns True if the event is connected to the given function.
:type callback: object
:param callback: The callback function.
:rtype: bool
:returns: Whether the signal is connected to the given function.
"""
index = ... | python | {
"resource": ""
} |
q254707 | Event._try_disconnect | validation | def _try_disconnect(self, ref):
"""
Called by the weak reference when its target dies.
In other words, we can assert that self.weak_subscribers is not
None at this time.
"""
with self.lock:
weak = [s[0] for s in self.weak_subscribers]
try:
... | python | {
"resource": ""
} |
q254708 | Event.disconnect | validation | def disconnect(self, callback):
"""
Disconnects the signal from the given function.
:type callback: object
:param callback: The callback function.
"""
if self.weak_subscribers is not None:
with self.lock:
index = self._weakly_connected_index(... | python | {
"resource": ""
} |
q254709 | TaskParser.parse_node | validation | def parse_node(self):
"""
Parse this node, and all children, returning the connected task spec.
"""
try:
self.task = self.create_task()
self.task.documentation = self.parser._parse_documentation(
self.node, xpath=self.xpath, task_parser=self)
... | python | {
"resource": ""
} |
q254710 | TaskParser.create_task | validation | def create_task(self):
"""
Create an instance of the task appropriately. A subclass can override
this method to get extra information from the node.
"""
return self.spec_class(self.spec, self.get_task_spec_name(),
lane=self.get_lane(),
... | python | {
"resource": ""
} |
q254711 | TaskParser.connect_outgoing | validation | def connect_outgoing(self, outgoing_task, outgoing_task_node,
sequence_flow_node, is_default):
"""
Connects this task to the indicating outgoing task, with the details in
the sequence flow. A subclass can override this method to get extra
information from the nod... | python | {
"resource": ""
} |
q254712 | BpmnSpecMixin.connect_outgoing | validation | def connect_outgoing(self, taskspec, sequence_flow_id, sequence_flow_name,
documentation):
"""
Connect this task spec to the indicated child.
:param sequence_flow_id: The ID of the connecting sequenceFlow node.
:param sequence_flow_name: The name of the connect... | python | {
"resource": ""
} |
q254713 | BpmnSpecMixin.get_outgoing_sequence_names | validation | def get_outgoing_sequence_names(self):
"""
Returns a list of the names of outgoing sequences. Some may be None.
"""
return sorted([s.name for s in
list(self.outgoing_sequence_flows_by_id.values())]) | python | {
"resource": ""
} |
q254714 | MultiChoice.connect_if | validation | def connect_if(self, condition, task_spec):
"""
Connects a taskspec that is executed if the condition DOES match.
condition -- a condition (Condition)
taskspec -- the conditional task spec
"""
assert task_spec is not None
self.outputs.append(task_spec)
se... | python | {
"resource": ""
} |
q254715 | MultiChoice._on_complete_hook | validation | def _on_complete_hook(self, my_task):
"""
Runs the task. Should not be called directly.
Returns True if completed, False otherwise.
"""
# Find all matching conditions.
outputs = []
for condition, output in self.cond_task_specs:
if self.choice is not No... | python | {
"resource": ""
} |
q254716 | Workflow.is_completed | validation | def is_completed(self):
"""
Returns True if the entire Workflow is completed, False otherwise.
:rtype: bool
:return: Whether the workflow is completed.
"""
mask = Task.NOT_FINISHED_MASK
iter = Task.Iterator(self.task_tree, mask)
try:
next(iter... | python | {
"resource": ""
} |
q254717 | Workflow.cancel | validation | def cancel(self, success=False):
"""
Cancels all open tasks in the workflow.
:type success: bool
:param success: Whether the Workflow should be marked as successfully
completed.
"""
self.success = success
cancel = []
mask = Task.N... | python | {
"resource": ""
} |
q254718 | Workflow.get_task | validation | def get_task(self, id):
"""
Returns the task with the given id.
:type id:integer
:param id: The id of a task.
:rtype: Task
:returns: The task with the given id.
"""
tasks = [task for task in self.get_tasks() if task.id == id]
return tasks[0] if le... | python | {
"resource": ""
} |
q254719 | Workflow.get_tasks_from_spec_name | validation | def get_tasks_from_spec_name(self, name):
"""
Returns all tasks whose spec has the given name.
:type name: str
:param name: The name of a task spec.
:rtype: Task
:return: The task that relates to the spec with the given name.
"""
return [task for task in ... | python | {
"resource": ""
} |
q254720 | Workflow.get_tasks | validation | def get_tasks(self, state=Task.ANY_MASK):
"""
Returns a list of Task objects with the given state.
:type state: integer
:param state: A bitmask of states.
:rtype: list[Task]
:returns: A list of tasks.
"""
return [t for t in Task.Iterator(self.task_tree,... | python | {
"resource": ""
} |
q254721 | Workflow.complete_task_from_id | validation | def complete_task_from_id(self, task_id):
"""
Runs the task with the given id.
:type task_id: integer
:param task_id: The id of the Task object.
"""
if task_id is None:
raise WorkflowException(self.spec, 'task_id is None')
for task in self.task_tree:... | python | {
"resource": ""
} |
q254722 | Workflow.complete_next | validation | def complete_next(self, pick_up=True, halt_on_manual=True):
"""
Runs the next task.
Returns True if completed, False otherwise.
:type pick_up: bool
:param pick_up: When True, this method attempts to choose the next
task not by searching beginning at the ... | python | {
"resource": ""
} |
q254723 | ref | validation | def ref(function, callback=None):
"""
Returns a weak reference to the given method or function.
If the callback argument is not None, it is called as soon
as the referenced function is garbage deleted.
:type function: callable
:param function: The function to reference.
:type callback: ca... | python | {
"resource": ""
} |
q254724 | CompactWorkflowSerializer.new_workflow | validation | def new_workflow(self, workflow_spec, read_only=False, **kwargs):
"""
Create a new workflow instance from the given spec and arguments.
:param workflow_spec: the workflow spec to use
:param read_only: this should be in read only mode
:param kwargs: Any extra kwargs passed to t... | python | {
"resource": ""
} |
q254725 | Task._add_child | validation | def _add_child(self, task_spec, state=MAYBE):
"""
Adds a new child and assigns the given TaskSpec to it.
:type task_spec: TaskSpec
:param task_spec: The task spec that is assigned to the new child.
:type state: integer
:param state: The bitmask of states for the new ch... | python | {
"resource": ""
} |
q254726 | Task._assign_new_thread_id | validation | def _assign_new_thread_id(self, recursive=True):
"""
Assigns a new thread id to the task.
:type recursive: bool
:param recursive: Whether to assign the id to children recursively.
:rtype: bool
:returns: The new thread id.
"""
self.__class__.thread_id_po... | python | {
"resource": ""
} |
q254727 | Task._is_descendant_of | validation | def _is_descendant_of(self, parent):
"""
Returns True if parent is in the list of ancestors, returns False
otherwise.
:type parent: Task
:param parent: The parent that is searched in the ancestors.
:rtype: bool
:returns: Whether the parent was found.
""... | python | {
"resource": ""
} |
q254728 | Task._find_child_of | validation | def _find_child_of(self, parent_task_spec):
"""
Returns the ancestor that has a task with the given task spec
as a parent.
If no such ancestor was found, the root task is returned.
:type parent_task_spec: TaskSpec
:param parent_task_spec: The wanted ancestor.
:r... | python | {
"resource": ""
} |
q254729 | Task._find_any | validation | def _find_any(self, task_spec):
"""
Returns any descendants that have the given task spec assigned.
:type task_spec: TaskSpec
:param task_spec: The wanted task spec.
:rtype: list(Task)
:returns: The tasks objects that are attached to the given task spec.
"""
... | python | {
"resource": ""
} |
q254730 | Task._find_ancestor | validation | def _find_ancestor(self, task_spec):
"""
Returns the ancestor that has the given task spec assigned.
If no such ancestor was found, the root task is returned.
:type task_spec: TaskSpec
:param task_spec: The wanted task spec.
:rtype: Task
:returns: The ancestor.... | python | {
"resource": ""
} |
q254731 | Task._find_ancestor_from_name | validation | def _find_ancestor_from_name(self, name):
"""
Returns the ancestor that has a task with the given name assigned.
Returns None if no such ancestor was found.
:type name: str
:param name: The name of the wanted task.
:rtype: Task
:returns: The ancestor.
"... | python | {
"resource": ""
} |
q254732 | Task._ready | validation | def _ready(self):
"""
Marks the task as ready for execution.
"""
if self._has_state(self.COMPLETED) or self._has_state(self.CANCELLED):
return
self._set_state(self.READY)
self.task_spec._on_ready(self) | python | {
"resource": ""
} |
q254733 | Task.get_state_name | validation | def get_state_name(self):
"""
Returns a textual representation of this Task's state.
"""
state_name = []
for state, name in list(self.state_names.items()):
if self._has_state(state):
state_name.append(name)
return '|'.join(state_name) | python | {
"resource": ""
} |
q254734 | Task._inherit_data | validation | def _inherit_data(self):
"""
Inherits the data from the parent.
"""
LOG.debug("'%s' inheriting data from '%s'" % (self.get_name(),
self.parent.get_name()),
extra=dict(data=self.parent.data))
self.set_data(**s... | python | {
"resource": ""
} |
q254735 | Task.cancel | validation | def cancel(self):
"""
Cancels the item if it was not yet completed, and removes
any children that are LIKELY.
"""
if self._is_finished():
for child in self.children:
child.cancel()
return
self._set_state(self.CANCELLED)
self... | python | {
"resource": ""
} |
q254736 | Task.get_dump | validation | def get_dump(self, indent=0, recursive=True):
"""
Returns the subtree as a string for debugging.
:rtype: str
:returns: The debug information.
"""
dbg = (' ' * indent * 2)
dbg += '%s/' % self.id
dbg += '%s:' % self.thread_id
dbg += ' Task of %s' %... | python | {
"resource": ""
} |
q254737 | _eval_args | validation | def _eval_args(args, my_task):
"""Parses args and evaluates any Attrib entries"""
results = []
for arg in args:
if isinstance(arg, Attrib) or isinstance(arg, PathAttrib):
results.append(valueof(my_task, arg))
else:
results.append(arg)
return results | python | {
"resource": ""
} |
q254738 | _eval_kwargs | validation | def _eval_kwargs(kwargs, my_task):
"""Parses kwargs and evaluates any Attrib entries"""
results = {}
for kwarg, value in list(kwargs.items()):
if isinstance(value, Attrib) or isinstance(value, PathAttrib):
results[kwarg] = valueof(my_task, value)
else:
results[kwarg] ... | python | {
"resource": ""
} |
q254739 | Serializable | validation | def Serializable(o):
"""Make sure an object is JSON-serializable
Use this to return errors and other info that does not need to be
deserialized or does not contain important app data. Best for returning
error info and such"""
if isinstance(o, (str, dict, int)):
return o
else:
try... | python | {
"resource": ""
} |
q254740 | Celery._send_call | validation | def _send_call(self, my_task):
"""Sends Celery asynchronous call and stores async call information for
retrieval laster"""
args, kwargs = None, None
if self.args:
args = _eval_args(self.args, my_task)
if self.kwargs:
kwargs = _eval_kwargs(self.kwargs, my_t... | python | {
"resource": ""
} |
q254741 | Celery._restart | validation | def _restart(self, my_task):
""" Abort celery task and retry it"""
if not my_task._has_state(Task.WAITING):
raise WorkflowException(my_task, "Cannot refire a task that is not"
"in WAITING state")
# Check state of existing call and abort it (save hi... | python | {
"resource": ""
} |
q254742 | Celery._clear_celery_task_data | validation | def _clear_celery_task_data(self, my_task):
""" Clear celery task data """
# Save history
if 'task_id' in my_task.internal_data:
# Save history for diagnostics/forensics
history = my_task._get_internal_data('task_history', [])
history.append(my_task._get_inter... | python | {
"resource": ""
} |
q254743 | TaskSpec.ancestors | validation | def ancestors(self):
"""Returns list of ancestor task specs based on inputs"""
results = []
def recursive_find_ancestors(task, stack):
for input in task.inputs:
if input not in stack:
stack.append(input)
recursive_find_ancestor... | python | {
"resource": ""
} |
q254744 | TaskSpec._predict | validation | def _predict(self, my_task, seen=None, looked_ahead=0):
"""
Updates the branch such that all possible future routes are added.
Should NOT be overwritten! Instead, overwrite _predict_hook().
:type my_task: Task
:param my_task: The associated task in the task tree.
:type... | python | {
"resource": ""
} |
q254745 | TaskSpec._on_ready | validation | def _on_ready(self, my_task):
"""
Return True on success, False otherwise.
:type my_task: Task
:param my_task: The associated task in the task tree.
"""
assert my_task is not None
self.test()
# Acquire locks, if any.
for lock in self.locks:
... | python | {
"resource": ""
} |
q254746 | Packager.create_package | validation | def create_package(self):
"""
Creates the package, writing the data out to the provided file-like
object.
"""
# Check that all files exist (and calculate the longest shared path
# prefix):
self.input_path_prefix = None
for filename in self.input_files:
... | python | {
"resource": ""
} |
q254747 | Packager.write_file_to_package_zip | validation | def write_file_to_package_zip(self, filename, src_filename):
"""
Writes a local file in to the zip file and adds it to the manifest
dictionary
:param filename: The zip file name
:param src_filename: the local file name
"""
f = open(src_filename)
with f:
... | python | {
"resource": ""
} |
q254748 | Packager.write_to_package_zip | validation | def write_to_package_zip(self, filename, data):
"""
Writes data to the zip file and adds it to the manifest dictionary
:param filename: The zip file name
:param data: the data
"""
self.manifest[filename] = md5hash(data)
self.package_zip.writestr(filename, data) | python | {
"resource": ""
} |
q254749 | Packager.write_manifest | validation | def write_manifest(self):
"""
Write the manifest content to the zip file. It must be a predictable
order.
"""
config = configparser.ConfigParser()
config.add_section('Manifest')
for f in sorted(self.manifest.keys()):
config.set('Manifest', f.replace(... | python | {
"resource": ""
} |
q254750 | Packager.pre_parse_and_validate | validation | def pre_parse_and_validate(self, bpmn, filename):
"""
A subclass can override this method to provide additional parseing or
validation. It should call the parent method first.
:param bpmn: an lxml tree of the bpmn content
:param filename: the source file name
This must... | python | {
"resource": ""
} |
q254751 | Packager.pre_parse_and_validate_signavio | validation | def pre_parse_and_validate_signavio(self, bpmn, filename):
"""
This is the Signavio specific editor hook for pre-parsing and
validation.
A subclass can override this method to provide additional parseing or
validation. It should call the parent method first.
:param bpmn... | python | {
"resource": ""
} |
q254752 | Packager.package_for_editor_signavio | validation | def package_for_editor_signavio(self, spec, filename):
"""
Adds the SVG files to the archive for this BPMN file.
"""
signavio_file = filename[:-len('.bpmn20.xml')] + '.signavio.xml'
if os.path.exists(signavio_file):
self.write_file_to_package_zip(
"src... | python | {
"resource": ""
} |
q254753 | Packager.write_meta_data | validation | def write_meta_data(self):
"""
Writes the metadata.ini file to the archive.
"""
config = configparser.ConfigParser()
config.add_section('MetaData')
config.set('MetaData', 'entry_point_process', self.wf_spec.name)
if self.editor:
config.set('MetaData',... | python | {
"resource": ""
} |
q254754 | Packager.merge_option_and_config_str | validation | def merge_option_and_config_str(cls, option_name, config, options):
"""
Utility method to merge an option and config, with the option taking "
precedence
"""
opt = getattr(options, option_name, None)
if opt:
config.set(CONFIG_SECTION_NAME, option_name, opt)
... | python | {
"resource": ""
} |
q254755 | ProcessParser.parse_node | validation | def parse_node(self, node):
"""
Parses the specified child task node, and returns the task spec. This
can be called by a TaskParser instance, that is owned by this
ProcessParser.
"""
if node.get('id') in self.parsed_nodes:
return self.parsed_nodes[node.get('i... | python | {
"resource": ""
} |
q254756 | XmlSerializer.deserialize_assign | validation | def deserialize_assign(self, workflow, start_node):
"""
Reads the "pre-assign" or "post-assign" tag from the given node.
start_node -- the xml node (xml.dom.minidom.Node)
"""
name = start_node.getAttribute('name')
attrib = start_node.getAttribute('field')
value =... | python | {
"resource": ""
} |
q254757 | XmlSerializer.deserialize_data | validation | def deserialize_data(self, workflow, start_node):
"""
Reads a "data" or "define" tag from the given node.
start_node -- the xml node (xml.dom.minidom.Node)
"""
name = start_node.getAttribute('name')
value = start_node.getAttribute('value')
return name, value | python | {
"resource": ""
} |
q254758 | XmlSerializer.deserialize_assign_list | validation | def deserialize_assign_list(self, workflow, start_node):
"""
Reads a list of assignments from the given node.
workflow -- the workflow
start_node -- the xml structure (xml.dom.minidom.Node)
"""
# Collect all information.
assignments = []
for node in start... | python | {
"resource": ""
} |
q254759 | XmlSerializer.deserialize_logical | validation | def deserialize_logical(self, node):
"""
Reads the logical tag from the given node, returns a Condition object.
node -- the xml node (xml.dom.minidom.Node)
"""
term1_attrib = node.getAttribute('left-field')
term1_value = node.getAttribute('left-value')
op = node.... | python | {
"resource": ""
} |
q254760 | XmlSerializer.deserialize_condition | validation | def deserialize_condition(self, workflow, start_node):
"""
Reads the conditional statement from the given node.
workflow -- the workflow with which the concurrence is associated
start_node -- the xml structure (xml.dom.minidom.Node)
"""
# Collect all information.
... | python | {
"resource": ""
} |
q254761 | XmlSerializer.deserialize_workflow_spec | validation | def deserialize_workflow_spec(self, s_state, filename=None):
"""
Reads the workflow from the given XML structure and returns a
WorkflowSpec instance.
"""
dom = minidom.parseString(s_state)
node = dom.getElementsByTagName('process-definition')[0]
name = node.getAtt... | python | {
"resource": ""
} |
q254762 | WorkflowSpec._add_notify | validation | def _add_notify(self, task_spec):
"""
Called by a task spec when it was added into the workflow.
"""
if task_spec.name in self.task_specs:
raise KeyError('Duplicate task spec name: ' + task_spec.name)
self.task_specs[task_spec.name] = task_spec
task_spec.id = ... | python | {
"resource": ""
} |
q254763 | WorkflowSpec.validate | validation | def validate(self):
"""Checks integrity of workflow and reports any problems with it.
Detects:
- loops (tasks that wait on each other in a loop)
:returns: empty list if valid, a list of errors if not
"""
results = []
from ..specs import Join
def recursiv... | python | {
"resource": ""
} |
q254764 | BpmnWorkflow.accept_message | validation | def accept_message(self, message):
"""
Indicate to the workflow that a message has been received. The message
will be processed by any waiting Intermediate or Boundary Message
Events, that are waiting for the message.
"""
assert not self.read_only
self.refresh_wai... | python | {
"resource": ""
} |
q254765 | BpmnWorkflow.refresh_waiting_tasks | validation | def refresh_waiting_tasks(self):
"""
Refresh the state of all WAITING tasks. This will, for example, update
Catching Timer Events whose waiting time has passed.
"""
assert not self.read_only
for my_task in self.get_tasks(Task.WAITING):
my_task.task_spec._updat... | python | {
"resource": ""
} |
q254766 | BpmnWorkflow.get_ready_user_tasks | validation | def get_ready_user_tasks(self):
"""
Returns a list of User Tasks that are READY for user action
"""
return [t for t in self.get_tasks(Task.READY)
if not self._is_engine_task(t.task_spec)] | python | {
"resource": ""
} |
q254767 | Trigger.deserialize | validation | def deserialize(cls, serializer, wf_spec, s_state, **kwargs):
"""
Deserializes the trigger using the provided serializer.
"""
return serializer.deserialize_trigger(wf_spec,
s_state,
**kwargs) | python | {
"resource": ""
} |
q254768 | BpmnScriptEngine.evaluate | validation | def evaluate(self, task, expression):
"""
Evaluate the given expression, within the context of the given task and
return the result.
"""
if isinstance(expression, Operator):
return expression._matches(task)
else:
return self._eval(task, expression,... | python | {
"resource": ""
} |
q254769 | BpmnScriptEngine.execute | validation | def execute(self, task, script, **kwargs):
"""
Execute the script, within the context of the specified task
"""
locals().update(kwargs)
exec(script) | python | {
"resource": ""
} |
q254770 | Join._start | validation | def _start(self, my_task, force=False):
"""
Checks whether the preconditions for going to READY state are met.
Returns True if the threshold was reached, False otherwise.
Also returns the list of tasks that yet need to be completed.
"""
# If the threshold was already reac... | python | {
"resource": ""
} |
q254771 | Join._on_trigger | validation | def _on_trigger(self, my_task):
"""
May be called to fire the Join before the incoming branches are
completed.
"""
for task in my_task.workflow.task_tree._find_any(self):
if task.thread_id != my_task.thread_id:
continue
self._do_join(task) | python | {
"resource": ""
} |
q254772 | ExclusiveChoice.connect | validation | def connect(self, task_spec):
"""
Connects the task spec that is executed if no other condition
matches.
:type task_spec: TaskSpec
:param task_spec: The following task spec.
"""
assert self.default_task_spec is None
self.outputs.append(task_spec)
... | python | {
"resource": ""
} |
q254773 | BlockadeState.container_id | validation | def container_id(self, name):
'''Try to find the container ID with the specified name'''
container = self._containers.get(name, None)
if not container is None:
return container.get('id', None)
return None | python | {
"resource": ""
} |
q254774 | BlockadeState.initialize | validation | def initialize(self, containers):
'''
Initialize a new state file with the given contents.
This function fails in case the state file already exists.
'''
self._containers = deepcopy(containers)
self.__write(containers, initialize=True) | python | {
"resource": ""
} |
q254775 | BlockadeState.update | validation | def update(self, containers):
'''Update the current state file with the specified contents'''
self._containers = deepcopy(containers)
self.__write(containers, initialize=False) | python | {
"resource": ""
} |
q254776 | BlockadeState.load | validation | def load(self):
'''Try to load a blockade state file in the current directory'''
try:
with open(self._state_file) as f:
state = yaml.safe_load(f)
self._containers = state['containers']
except (IOError, OSError) as err:
if err.errno == errno... | python | {
"resource": ""
} |
q254777 | BlockadeState._get_blockade_id_from_cwd | validation | def _get_blockade_id_from_cwd(self, cwd=None):
'''Generate a new blockade ID based on the CWD'''
if not cwd:
cwd = os.getcwd()
# this follows a similar pattern as docker-compose uses
parent_dir = os.path.abspath(cwd)
basename = os.path.basename(parent_dir).lower()
... | python | {
"resource": ""
} |
q254778 | BlockadeState._assure_dir | validation | def _assure_dir(self):
'''Make sure the state directory exists'''
try:
os.makedirs(self._state_dir)
except OSError as err:
if err.errno != errno.EEXIST:
raise | python | {
"resource": ""
} |
q254779 | BlockadeState._state_delete | validation | def _state_delete(self):
'''Try to delete the state.yml file and the folder .blockade'''
try:
os.remove(self._state_file)
except OSError as err:
if err.errno not in (errno.EPERM, errno.ENOENT):
raise
try:
os.rmdir(self._state_dir)
... | python | {
"resource": ""
} |
q254780 | BlockadeState.__base_state | validation | def __base_state(self, containers):
'''
Convert blockade ID and container information into
a state dictionary object.
'''
return dict(blockade_id=self._blockade_id,
containers=containers,
version=self._state_version) | python | {
"resource": ""
} |
q254781 | BlockadeState.__write | validation | def __write(self, containers, initialize=True):
'''Write the given state information into a file'''
path = self._state_file
self._assure_dir()
try:
flags = os.O_WRONLY | os.O_CREAT
if initialize:
flags |= os.O_EXCL
with os.fdopen(os.ope... | python | {
"resource": ""
} |
q254782 | expand_partitions | validation | def expand_partitions(containers, partitions):
'''
Validate the partitions of containers. If there are any containers
not in any partition, place them in an new partition.
'''
# filter out holy containers that don't belong
# to any partition at all
all_names = frozenset(c.name for c in cont... | python | {
"resource": ""
} |
q254783 | _IPTables.get_source_chains | validation | def get_source_chains(self, blockade_id):
"""Get a map of blockade chains IDs -> list of IPs targeted at them
For figuring out which container is in which partition
"""
result = {}
if not blockade_id:
raise ValueError("invalid blockade_id")
lines = self.get_c... | python | {
"resource": ""
} |
q254784 | _IPTables.insert_rule | validation | def insert_rule(self, chain, src=None, dest=None, target=None):
"""Insert a new rule in the chain
"""
if not chain:
raise ValueError("Invalid chain")
if not target:
raise ValueError("Invalid target")
if not (src or dest):
raise ValueError("Need... | python | {
"resource": ""
} |
q254785 | BlockadeChaos._sm_start | validation | def _sm_start(self, *args, **kwargs):
"""
Start the timer waiting for pain
"""
millisec = random.randint(self._start_min_delay, self._start_max_delay)
self._timer = threading.Timer(millisec / 1000.0, self.event_timeout)
self._timer.start() | python | {
"resource": ""
} |
q254786 | BlockadeChaos._sm_to_pain | validation | def _sm_to_pain(self, *args, **kwargs):
"""
Start the blockade event
"""
_logger.info("Starting chaos for blockade %s" % self._blockade_name)
self._do_blockade_event()
# start the timer to end the pain
millisec = random.randint(self._run_min_time, self._run_max_ti... | python | {
"resource": ""
} |
q254787 | BlockadeChaos._sm_stop_from_no_pain | validation | def _sm_stop_from_no_pain(self, *args, **kwargs):
"""
Stop chaos when there is no current blockade operation
"""
# Just stop the timer. It is possible that it was too late and the
# timer is about to run
_logger.info("Stopping chaos for blockade %s" % self._blockade_name... | python | {
"resource": ""
} |
q254788 | BlockadeChaos._sm_relieve_pain | validation | def _sm_relieve_pain(self, *args, **kwargs):
"""
End the blockade event and return to a steady state
"""
_logger.info(
"Ending the degradation for blockade %s" % self._blockade_name)
self._do_reset_all()
# set a timer for the next pain event
millis... | python | {
"resource": ""
} |
q254789 | BlockadeChaos._sm_stop_from_pain | validation | def _sm_stop_from_pain(self, *args, **kwargs):
"""
Stop chaos while there is a blockade event in progress
"""
_logger.info("Stopping chaos for blockade %s" % self._blockade_name)
self._do_reset_all() | python | {
"resource": ""
} |
q254790 | BlockadeChaos._sm_cleanup | validation | def _sm_cleanup(self, *args, **kwargs):
"""
Delete all state associated with the chaos session
"""
if self._done_notification_func is not None:
self._done_notification_func()
self._timer.cancel() | python | {
"resource": ""
} |
q254791 | dependency_sorted | validation | def dependency_sorted(containers):
"""Sort a dictionary or list of containers into dependency order
Returns a sequence
"""
if not isinstance(containers, collections.Mapping):
containers = dict((c.name, c) for c in containers)
container_links = dict((name, set(c.links.keys()))
... | python | {
"resource": ""
} |
q254792 | BlockadeContainerConfig.from_dict | validation | def from_dict(name, values):
'''
Convert a dictionary of configuration values
into a sequence of BlockadeContainerConfig instances
'''
# determine the number of instances of this container
count = 1
count_value = values.get('count', 1)
if isinstance(count... | python | {
"resource": ""
} |
q254793 | BlockadeConfig.from_dict | validation | def from_dict(values):
'''
Instantiate a BlockadeConfig instance based on
a given dictionary of configuration values
'''
try:
containers = values['containers']
parsed_containers = {}
for name, container_dict in containers.items():
... | python | {
"resource": ""
} |
q254794 | cmd_up | validation | def cmd_up(opts):
"""Start the containers and link them together
"""
config = load_config(opts.config)
b = get_blockade(config, opts)
containers = b.create(verbose=opts.verbose, force=opts.force)
print_containers(containers, opts.json) | python | {
"resource": ""
} |
q254795 | cmd_destroy | validation | def cmd_destroy(opts):
"""Destroy all containers and restore networks
"""
config = load_config(opts.config)
b = get_blockade(config, opts)
b.destroy() | python | {
"resource": ""
} |
q254796 | cmd_status | validation | def cmd_status(opts):
"""Print status of containers and networks
"""
config = load_config(opts.config)
b = get_blockade(config, opts)
containers = b.status()
print_containers(containers, opts.json) | python | {
"resource": ""
} |
q254797 | cmd_kill | validation | def cmd_kill(opts):
"""Kill some or all containers
"""
kill_signal = opts.signal if hasattr(opts, 'signal') else "SIGKILL"
__with_containers(opts, Blockade.kill, signal=kill_signal) | python | {
"resource": ""
} |
q254798 | cmd_partition | validation | def cmd_partition(opts):
"""Partition the network between containers
Replaces any existing partitions outright. Any containers NOT specified
in arguments will be globbed into a single implicit partition. For
example if you have three containers: c1, c2, and c3 and you run:
blockade partition c... | python | {
"resource": ""
} |
q254799 | cmd_join | validation | def cmd_join(opts):
"""Restore full networking between containers
"""
config = load_config(opts.config)
b = get_blockade(config, opts)
b.join() | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.