Compose a dictionary with information for writing the submit script.
178067
def get_configs(self, command):
        """"""

        logger.debug("Requesting one block with {} nodes per block and {} tasks per node".format(
            self.nodes_per_block, self.tasks_per_node))

        job_config = {}
        job_config["submit_script_dir"] = self.channel.script_dir
        job_config["nodes"] = self.nodes_per_block
        job_config["walltime"] = wtime_to_minutes(self.walltime)
        job_config["overrides"] = self.overrides
        job_config["user_script"] = command

        job_config["user_script"] = self.launcher(command,
                                                  self.tasks_per_node,
                                                  self.nodes_per_block)
        return job_config
1352482
def dict_factory(cursor, row):
    """"""
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d
117868
def _build_dictionary(self, results):
        
        foreign = self._foreign_key

        dictionary = {}

        for result in results:
            key = getattr(result.pivot, foreign)
            if key not in dictionary:
                dictionary[key] = []

            dictionary[key].append(result)

        return dictionary
806531
def create_form_data(self, **kwargs):
        """"""
        # Get the specified keyword arguments.
        children = kwargs.get('children', [])
        sort_order = kwargs.get('sort_order', None)
        solr_response = kwargs.get('solr_response', None)
        superuser = kwargs.get('superuser', False)
        # Get the vocabularies to pull the qualifiers from.
        vocabularies = self.get_vocabularies()
        # Loop through all UNTL elements in the Python object.
        for element in children:
            # Add children that are missing from the form.
            element.children = add_missing_children(
                element.contained_children,
                element.children,
            )
            # Add the form attribute to the element.
            element.add_form(
                vocabularies=vocabularies,
                qualifier=element.qualifier,
                content=element.content,
                superuser=superuser,
            )
            # Element can contain children.
            if element.form.has_children:
                # If the parent has a qualifier,
                # create a representative form element for the parent.
                if getattr(element.form, 'qualifier_name', False):
                    add_parent = PARENT_FORM[element.form.qualifier_name](
                        content=element.qualifier,
                    )
                    # Add the parent to the list of child elements.
                    element.children.append(add_parent)
                # Sort the elements by the index of child sort.
                element.children.sort(
                    key=lambda obj: element.form.child_sort.index(obj.tag)
                )
                # Loop through the element's children (if it has any).
                for child in element.children:
                    # Add the form attribute to the element.
                    child.add_form(
                        vocabularies=vocabularies,
                        qualifier=child.qualifier,
                        content=child.content,
                        parent_tag=element.tag,
                        superuser=superuser,
                    )
        element_group_dict = {}
        # Group related objects together.
        for element in children:
            # Make meta-hidden its own group.
            if element.form.name == 'meta' and element.qualifier == 'hidden':
                element_group_dict['hidden'] = [element]
            # Element is not meta-hidden.
            else:
                # Make sure the dictionary key exists.
                if element.form.name not in element_group_dict:
                    element_group_dict[element.form.name] = []
                element_group_dict[element.form.name].append(element)
        # If the hidden meta element doesn't exist, add it to its own group.
        if 'hidden' not in element_group_dict:
            hidden_element = PYUNTL_DISPATCH['meta'](
                qualifier='hidden',
                content='False')
            hidden_element.add_form(
                vocabularies=vocabularies,
                qualifier=hidden_element.qualifier,
                content=hidden_element.content,
                superuser=superuser,
            )
            element_group_dict['hidden'] = [hidden_element]
        # Create a list of group object elements.
        element_list = self.create_form_groupings(
            vocabularies,
            solr_response,
            element_group_dict,
            sort_order,
        )
        # Return the list of UNTL elements with form data added.
        return element_list
931938
def compile_dictionary(self, lang, wordlists, encoding, output):
        """"""
        wordlist = ''

        try:
            output_location = os.path.dirname(output)
            if not os.path.exists(output_location):
                os.makedirs(output_location)
            if os.path.exists(output):
                os.remove(output)

            self.log("Compiling Dictionary...", 1)
            # Read word lists and create a unique set of words
            words = set()
            for wordlist in wordlists:
                with open(wordlist, 'rb') as src:
                    for word in src.read().split(b'\n'):
                        words.add(word.replace(b'\r', b''))

            # Sort and create wordlist
            with open(output, 'wb') as dest:
                dest.write(b'\n'.join(sorted(words)) + b'\n')
        except Exception:
            self.log('Problem compiling dictionary.', 0)
            self.log("Current wordlist '%s'" % wordlist)
            raise
541948
def fill_form(form, data):
    
    for (key, value) in data.items():
        if hasattr(form, key):
            if isinstance(value, dict):
                fill_form(getattr(form, key), value)
            else:
                getattr(form, key).data = value
    return form
596
def post(self):
        """"""
        self.set_header("Content-Type", "application/json")
        key = uuid.uuid4().hex
        metadata = json.loads(self.request.body.decode())
        metadata["uuid"] = key
        self.database[key] = metadata
        result = json.dumps({"uuid": key})
        self.write(result)
1042480
def _writeDict(self, o):
        
        for key, val in o.iteritems():
            if type(key) in python.int_types:
                key = str(key)

            self.serialiseString(key)
            self.writeElement(val)
986581
def _format_notes(self, record):
        
        notes = []

        if "notes" in record:
            for note in record["notes"]:
                self._append_note_dict_to_list(notes, "general", note)

        if "language_and_script_notes" in record:
            self._append_note_dict_to_list(
                notes, "language_and_script", record["language_and_script_notes"]
            )

        if "publication_notes" in record:
            self._append_note_dict_to_list(
                notes, "publication_notes", record["publication_notes"]
            )

        if "physical_characteristics_and_technical_requirements" in record:
            self._append_note_dict_to_list(
                notes,
                "physical_condition",
                record["physical_characteristics_and_technical_requirements"],
            )

        return notes
1210794
def write_script(self, script_name, contents, mode="t", blockers=()):
        """"""
        self.delete_blockers(  # clean up old .py/.pyw w/o a script
            [os.path.join(self.script_dir, x) for x in blockers]
        )
        log.info("Installing %s script to %s", script_name, self.script_dir)
        target = os.path.join(self.script_dir, script_name)
        self.add_output(target)

        if self.dry_run:
            return

        mask = current_umask()
        ensure_directory(target)
        if os.path.exists(target):
            os.unlink(target)
        with open(target, "w" + mode) as f:
            f.write(contents)
        chmod(target, 0o777 - mask)
331116
def pretty_dict_str(d, indent=2):
    """"""
    b = StringIO()
    write_pretty_dict_str(b, d, indent=indent)
    return b.getvalue()
746227
def add_field(self, name, script, lang=None, params=None, ignore_failure=False):
        
        data = {}
        if lang:
            data["lang"] = lang

        if script:
            data['script'] = script
        else:
            raise ScriptFieldsError("Script is required for script_fields definition")
        if params:
            if isinstance(params, dict):
                if len(params):
                    data['params'] = params
            else:
                raise ScriptFieldsError("Parameters should be a valid dictionary")
        if ignore_failure:
            data['ignore_failure'] = ignore_failure
        self.fields[name] = data
258265
def write_dict_to_json(dictionary, path, **kwargs):
    
    result_string = json.dumps(dictionary, cls=JSONObjectEncoder,
                               indent=4, check_circular=False, sort_keys=True, **kwargs)
    with open(path, 'w') as f:
        # We cannot write directly to the file, as otherwise the 'encode' method wouldn't be called
        f.write(result_string)
243641
def write(self):
        """"""
        with open(storage.config_file, 'w') as cfg:
            yaml.dump(self.as_dict(), cfg, default_flow_style=False)

        storage.refresh()
70767
def _asdict(self):
    """"""
    with self._cond:
      if self._prompt is None:
        return
      return {'id': self._prompt.id,
              'message': self._prompt.message,
              'text-input': self._prompt.text_input}
401452
def post2pydict(post, ignore_list):
    """"""
    root_element = PYUNTL_DISPATCH['metadata']()
    untl_form_dict = {}
    # Turn the posted data into usable data
    # (otherwise the value lists get messed up).
    form_post = dict(post.copy())
    # Loop through all the field lists.
    for key, value_list in form_post.items():
        if key not in ignore_list:
            # Split the key into the element_tag (ex. title)
            # and element attribute (ex. qualifier, content).
            (element_tag, element_attribute) = key.split('-', 1)
            if element_tag not in untl_form_dict:
                untl_form_dict[element_tag] = ()
            # Add the value list to the dictionary.
            untl_form_dict[element_tag] += (element_attribute, value_list),

    for element_tag, attribute_tuple in untl_form_dict.items():
        # Get the count of attributes/content in the element tuple.
        attribute_count = len(attribute_tuple)
        # Get the count of the first attribute's values.
        value_count = len(attribute_tuple[0][1])
        # Check to see that all attribute/content values align numerically.
        for i in range(0, attribute_count):
            if not len(attribute_tuple[i][1]) == value_count:
                raise PyuntlException('Field values did not match up '
                                      'numerically for %s' % (element_tag))
        # Create a value loop to get all values from the tuple.
        for i in range(0, value_count):
            untl_element = None
            content = ''
            qualifier = ''
            child_list = []
            # Loop through the attributes.
            # attribute_tuple[j][0] represents the attribute/content name.
            # attribute_tuple[j][1][i] represents the
            # current attribute/content value.
            for j in range(0, attribute_count):
                if attribute_tuple[j][0] == 'content':
                    content = unicode(attribute_tuple[j][1][i])
                elif attribute_tuple[j][0] == 'qualifier':
                    qualifier = attribute_tuple[j][1][i]
                # Create a child UNTL element from the data.
                else:
                    # If the child has content, append it to the child list.
                    if attribute_tuple[j][1][i] != '':
                        child_tag = attribute_tuple[j][0]
                        # Check if the child is the attribute of the element.
                        if child_tag in PARENT_FORM:
                            qualifier = attribute_tuple[j][1][i]
                        # Else, the child is a normal child of the element.
                        else:
                            child_list.append(
                                PYUNTL_DISPATCH[attribute_tuple[j][0]](
                                    content=attribute_tuple[j][1][i]
                                )
                            )
            # Create the UNTL element.
            if content != '' and qualifier != '':
                untl_element = PYUNTL_DISPATCH[element_tag](content=content,
                                                            qualifier=qualifier)
            elif content != '':
                untl_element = PYUNTL_DISPATCH[element_tag](content=content)
            elif qualifier != '':
                untl_element = PYUNTL_DISPATCH[element_tag](qualifier=qualifier)
            # This element only has children elements.
            elif len(child_list) > 0:
                untl_element = PYUNTL_DISPATCH[element_tag]()
            # If the element has children, add them.
            if len(child_list) > 0 and untl_element is not None:
                for child in child_list:
                    untl_element.add_child(child)
            # Add the UNTL element to the root element.
            if untl_element is not None:
                root_element.add_child(untl_element)
    return root_element.create_element_dict()
98208
def write_data(data, out_file):
    """"""
    with open(out_file, 'w') as handle_out:
        handle_out.write(json.dumps([data], skipkeys=True, indent=2))