Parse params from install.json into a dict by name.
973251
def install_json_params(self):
        """"""
        if not self._install_json_params:
            for param in self.install_json.get('params') or []:
                self._install_json_params[param.get('name')] = param
        return self._install_json_params
1232843
def parse():
    """"""
    parser = argparse.ArgumentParser()

    parser.add_argument('--version', action='version',
                        version='f90nml {0}'.format(f90nml.__version__))

    parser.add_argument('--group', '-g', action='store',
                        help="specify namelist group to modify. "
                        "When absent, the first group is used")
    parser.add_argument('--variable', '-v', action='append',
                        help="specify the namelist variable to add or modify, "
                        "followed by the new value. Expressions are of the "
                        "form `VARIABLE=VALUE`")
    parser.add_argument('--patch', '-p', action='store_true',
                        help="modify the existing namelist as a patch")
    parser.add_argument('--format', '-f', action='store',
                        help="specify the output format (json, yaml, or nml)")
    parser.add_argument('--output', '-o', action='store',
                        help="specify namelist group to modify. "
                        "When absent, the first group is used")

    parser.add_argument('input', nargs='?')
    parser.add_argument('output', nargs='?')

    if len(sys.argv) == 1:
        parser.print_help()
        sys.exit()

    args = parser.parse_args()

    input_fname = args.input
    output_fname = args.output

    # Get input format
    # TODO: Combine with output format
    if input_fname:
        _, input_ext = os.path.splitext(input_fname)
        if input_ext == '.json':
            input_fmt = 'json'
        elif input_ext == '.yaml':
            input_fmt = 'yaml'
        else:
            input_fmt = 'nml'
    else:
        input_fmt = 'nml'

    # Output format flag validation
    valid_formats = ('json', 'yaml', 'nml')
    if args.format and args.format not in valid_formats:
        print('f90nml: error: format must be one of the following: {0}'
              ''.format(valid_formats), file=sys.stderr)
        sys.exit(-1)

    # Get output format
    # TODO: Combine with input format
    if not args.format:
        if output_fname:
            _, output_ext = os.path.splitext(output_fname)
            if output_ext == '.json':
                output_fmt = 'json'
            elif output_ext in ('.yaml', '.yml'):
                output_fmt = 'yaml'
            else:
                output_fmt = 'nml'
        else:
            output_fmt = 'nml'
    else:
        output_fmt = args.format

    # Confirm that YAML module is available
    if (input_fmt == 'yaml' or output_fmt == 'yaml') and not has_yaml:
        print('f90nml: error: YAML module could not be found.',
              file=sys.stderr)
        sys.exit(-1)

    # Do not patch non-namelist output
    if any(fmt != 'nml' for fmt in (input_fmt, output_fmt)) and args.patch:
        print('f90nml: error: Only namelist files can be patched.',
              file=sys.stderr)
        sys.exit(-1)

    # Read the input file
    if input_fname:
        if input_fmt in ('json', 'yaml'):
            if input_fmt == 'json':
                with open(input_fname) as input_file:
                    input_data = json.load(input_file)
            elif input_ext == '.yaml':
                with open(input_fname) as input_file:
                    input_data = yaml.safe_load(input_file)
        else:
            input_data = f90nml.read(input_fname)
    else:
        input_data = {}

    input_data = f90nml.Namelist(input_data)

    # Construct the update namelist
    update_nml = {}
    if args.variable:
        if not args.group:
            # Use the first available group
            grp = list(input_data.keys())[0]
            warnings.warn('f90nml: warning: Assuming variables are in group \'{0}\'.'.format(grp))
        else:
            grp = args.group

        update_nml_str = '&{0} {1} /\n'.format(grp, ', '.join(args.variable))
        update_io = StringIO(update_nml_str)
        update_nml = f90nml.read(update_io)
        update_io.close()

    # Target output
    output_file = open(output_fname, 'w') if output_fname else sys.stdout

    if args.patch:
        # We have to read the file twice for a patch.  The main reason is
        # to identify the default group, in case this is not provided.
        # It could be avoided if a group is provided, but logically that could
        # a mess that I do not want to sort out right now.
        f90nml.patch(input_fname, update_nml, output_file)

    else:
        # Update the input namelist directly
        if update_nml:
            try:
                input_data[grp].update(update_nml[grp])
            except KeyError:
                input_data[grp] = update_nml[grp]

        # Write to output
        if not args.patch:
            if output_fmt in ('json', 'yaml'):
                if output_fmt == 'json':
                    input_data = input_data.todict(complex_tuple=True)
                    json.dump(input_data, output_file,
                              indent=4, separators=(',', ': '))
                    output_file.write('\n')

                elif output_fmt == 'yaml':
                    input_data = input_data.todict(complex_tuple=True)
                    yaml.dump(input_data, output_file,
                              default_flow_style=False)
            else:
                # Default to namelist output
                f90nml.write(input_data, output_file)

    # Cleanup
    if output_file != sys.stdout:
        output_file.close()
1221911
def load_param(params, ctx=None):
    """"""
    if ctx is None:
        ctx = mx.cpu()
    save_dict = mx.nd.load(params)
    arg_params = {}
    aux_params = {}
    for k, v in save_dict.items():
        tp, name = k.split(':', 1)
        if tp == 'arg':
            arg_params[name] = v.as_in_context(ctx)
        if tp == 'aux':
            aux_params[name] = v.as_in_context(ctx)
    return arg_params, aux_params
492584
def _from_dict(cls, _dict):
        """"""
        args = {}
        if 'configuration_id' in _dict:
            args['configuration_id'] = _dict.get('configuration_id')
        if 'name' in _dict:
            args['name'] = _dict.get('name')
        else:
            raise ValueError(
                'Required property \'name\' not present in Configuration JSON')
        if 'created' in _dict:
            args['created'] = string_to_datetime(_dict.get('created'))
        if 'updated' in _dict:
            args['updated'] = string_to_datetime(_dict.get('updated'))
        if 'description' in _dict:
            args['description'] = _dict.get('description')
        if 'conversions' in _dict:
            args['conversions'] = Conversions._from_dict(
                _dict.get('conversions'))
        if 'enrichments' in _dict:
            args['enrichments'] = [
                Enrichment._from_dict(x) for x in (_dict.get('enrichments'))
            ]
        if 'normalizations' in _dict:
            args['normalizations'] = [
                NormalizationOperation._from_dict(x)
                for x in (_dict.get('normalizations'))
            ]
        if 'source' in _dict:
            args['source'] = Source._from_dict(_dict.get('source'))
        return cls(**args)
543059
def LoadInstallations(counter):
    
    process = subprocess.Popen(["pip", "list", "--format=json"],
                               stdout=subprocess.PIPE)
    output, _ = process.communicate()
    installations = json.loads(output)
    for i in installations:
        counter.labels(i["name"], i["version"]).inc()
199994
def _get_installed(self):
        
        from utility import get_json
        #This is a little tricky because the data file doesn't just have a list
        #of installed servers. It also manages the script's database that tracks
        #the user's interactions with it.
        fulldata = get_json(self.instpath, {})
        if "installed" in fulldata:
            return fulldata["installed"]
        else:
            return []
430093
def get_params(names):
    
    params = {}
    for name in names:
        value = request.form.get(name) or request.files.get(name)
        if value is not None:
            params[name] = value
    return params
1333532
def parse_reqs(req_path='./requirements/requirements.txt'):
    """"""
    install_requires = []
    with codecs.open(req_path, 'r') as handle:
        # remove comments and empty lines
        lines = (line.strip() for line in handle
                 if line.strip() and not line.startswith('#'))

        for line in lines:
            # check for nested requirements files
            if line.startswith('-r'):
                # recursively call this function
                install_requires += parse_reqs(req_path=line[3:])
            else:
                # add the line as a new requirement
                install_requires.append(line)

    return install_requires
944382
def parse_package_name(self):  # type: () -> Optional[str]
        
        if not self.setup_source:
            return None
        for row in self.setup_source.split("\n"):
            simplified_row = row.replace(" ", "").replace("'", '"').strip(" \t\n")
            if "name=" in simplified_row:
                if '"' in simplified_row:
                    return simplified_row.split('"')[1]

        name = self.execute_setup_name()
        if name:
            return name

        return ""
1260123
function (params) {
	var i = params.length, dependencies = [];
	while (i--) {
		dependencies[i] = `"${ params[i].name }"`;
	}

	return dependencies.join(", ");
}
569644
def parse_pkg_info(fn):
    
    res = {}
    for ln in open(fn).read().splitlines():
        if not ln or not ln[:1].strip():
            continue
        key, value = ln.split(": ", 1)
        res[key] = value
    return res
1050510
def get_installer_desc(build_context, target) -> tuple:
    """"""
    workspace_dir = build_context.get_workspace('CustomInstaller', target.name)
    target_name = split_name(target.name)
    script_name = basename(target.props.script)
    package_tarball = '{}.tar.gz'.format(join(workspace_dir, target_name))
    return target_name, script_name, package_tarball
35748
def ParseMultiple(self, result_dicts):
    """"""
    status = rdf_client.SoftwarePackage.InstallState.INSTALLED

    packages = []
    for result_dict in result_dicts:
      result = result_dict.ToDict()

      # InstalledOn comes back in a godawful format such as '7/10/2013'.
      installed_on = self.AmericanDateToEpoch(result.get("InstalledOn", ""))
      packages.append(
          rdf_client.SoftwarePackage(
              name=result.get("HotFixID"),
              description=result.get("Caption"),
              installed_by=result.get("InstalledBy"),
              install_state=status,
              installed_on=installed_on))

    if packages:
      yield rdf_client.SoftwarePackages(packages=packages)
213350
def parse_setup() -> Tuple[PackagesType, PackagesType, Set[str], Set[str]]:
    """"""
    essential_packages: PackagesType = {}
    test_packages: PackagesType = {}
    essential_duplicates: Set[str] = set()
    test_duplicates: Set[str] = set()

    with open('setup.py') as setup_file:
        contents = setup_file.read()

    # Parse out essential packages.
    package_string = re.search(r"""install_requires=\[[\s\n]*['"](.*?)['"],?[\s\n]*\]""",
                               contents, re.DOTALL).groups()[0].strip()
    for package in re.split(r"""['"],[\s\n]+['"]""", package_string):
        module, version = parse_package(package)
        if module in essential_packages:
            essential_duplicates.add(module)
        else:
            essential_packages[module] = version

    # Parse packages only needed for testing.
    package_string = re.search(r"""tests_require=\[[\s\n]*['"](.*?)['"],?[\s\n]*\]""",
                               contents, re.DOTALL).groups()[0].strip()
    for package in re.split(r"""['"],[\s\n]+['"]""", package_string):
        module, version = parse_package(package)
        if module in test_packages:
            test_duplicates.add(module)
        else:
            test_packages[module] = version

    return essential_packages, test_packages, essential_duplicates, test_duplicates
1039755
def Parse(self, statentry, file_object, knowledge_base):
    """"""

    plist = biplist.readPlist(file_object)

    if not isinstance(plist, list):
      raise parser.ParseError(
          "InstallHistory plist is a '%s', expecting a list" % type(plist))

    packages = []
    for sw in plist:
      packages.append(
          rdf_client.SoftwarePackage(
              name=sw.get("displayName"),
              version=sw.get("displayVersion"),
              description=",".join(sw.get("packageIdentifiers")),
              # TODO(hanuszczak): make installed_on an RDFDatetime
              installed_on=_DateToEpoch(sw.get("date")),
              install_state=rdf_client.SoftwarePackage.InstallState.INSTALLED))

    if packages:
      yield rdf_client.SoftwarePackages(packages=packages)
142598
def dict_jsonify(param):
    """"""
    if not isinstance(param, dict):
        param = dict(param)
    return jsonify(param)
389700
def params(self, dict):
        """"""
        self._configuration.update(dict)
        self._measurements.update()