Replace file placeholders in params with actual file data.

@param {Object} params
@param {Object} files
420869
function resolveFilesInParams(params, files) {
	var fileIds = Object.keys(files || {});

	var fileCount = fileIds.length;
	if (fileCount === 0) {
		return;
	}

	// scan all members for files, and collect children

	function addMembers(list, obj) {
		var keys = Object.keys(obj || {});

		for (var i = 0; i < keys.length; i++) {
			list.push({
				owner: obj,
				key: keys[i],
				value: obj[keys[i]]
			});
		}
	}

	var list = [];

	addMembers(list, params);

	for (var i = 0; i < list.length && fileCount > 0; i++) {
		var member = list[i];

		if (!member.value) {
			continue;
		}

		var type = typeof member.value;

		if (type === 'object') {
			// append children to the end of the list

			addMembers(list, member.value);
		} else if (type === 'string' && files[member.value]) {
			// file found for this property, so assign it

			var file = files[member.value];

			logger.verbose('Accepted file', '"' + file.partName + '":', file.fileName);

			member.owner[member.key] = file;

			delete files[member.value];
			fileCount -= 1;
		}
	}
}
676359
function replacePlaceholders(src, options) {
	return Object.keys(placeholders).reduce((out, placeholder) => {
		return out.replace(new RegExp(`${placeholder}`, 'g'), placeholders[placeholder]);
	}, src);
}
1312599
function generateFileHashes(options, files) {
    if (options.verbose) {
        _utils.logger.info('Generating files hash...');
    }
    if (files.length === 0) _utils.logger.info('No files found!');else if (options.verbose) {
        _utils.logger.info('Files found: ');
        var _iteratorNormalCompletion = true;
        var _didIteratorError = false;
        var _iteratorError = undefined;

        try {
            for (var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
                var file = _step.value;

                _utils.logger.info(file);
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally {
            try {
                if (!_iteratorNormalCompletion && _iterator.return) {
                    _iterator.return();
                }
            } finally {
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
    }

    var promises = [];
    var _iteratorNormalCompletion2 = true;
    var _didIteratorError2 = false;
    var _iteratorError2 = undefined;

    try {
        for (var _iterator2 = files[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
            var file = _step2.value;

            promises.push((0, _utils.hash)(file));
        }
    } catch (err) {
        _didIteratorError2 = true;
        _iteratorError2 = err;
    } finally {
        try {
            if (!_iteratorNormalCompletion2 && _iterator2.return) {
                _iterator2.return();
            }
        } finally {
            if (_didIteratorError2) {
                throw _iteratorError2;
            }
        }
    }

    return Promise.all(promises);
}
623724
function addFileResource(cmd, file, params, callback) {
    if( !file ) return callback({error:true,message:"no file provided"});
    if( !fs.existsSync(file) ) return callback({error:true,message:"no file found: "+file});
    if( !fs.statSync(file).isFile() ) return callback({error:true,message:"not a file: "+file});
    if( !params ) return callback({error:true,message:"no resource parameters provided"});
    if( !params.package_id ) return callback({error:true,message:"no package_id provided"});

    // clean up filename
    var name = getCkanFilename(file);
    var folder = new Date().toISOString()+'/'+name;
    
    // set default / known parameters
    params.url = server+"/storage/f/"+encodeURIComponent(folder);
    if( !params.name ) params.name = file.replace(/.*\//,'');
    params.size = fs.statSync(file).size;
    params.resource_type = "file.upload";
    
    exports.exec(cmd, params, function(err, pkg){
        if( err ) return callback(err);
        
        rest.post(server + '/storage/upload_handle', {
            multipart: true,
            headers : {
                Authorization : key
            },
            data: {
              key: folder,
              file: rest.file(file, null, fs.statSync(file).size, null, params.mimetype)
            }
        }).on('complete', function(data) {
            // HACK: redirects seem to fire complete twice.  this is bad
            if( !callback ) return;
            
            if (data instanceof Error) {
                callback(data);
            } else {
                callback(null, data);
            }
            callback = null;
        });
    });

}
430761
function copyReadmeFiles() {
    const resolvedSrcReadmePaths = path.resolve(rootDir, srcReadmePaths);

    glob(resolvedSrcReadmePaths, void(0), function(error, files) {
        files.forEach((filePath) => {
        const destReadmePath = filePath.replace(/(\bsrc\b)(?!.*\1)/, destDir);
            fs.copyFileSync(filePath, destReadmePath);
        });
    });
}
949169
def with_params(self, params):
        
        return self.replace(params=_merge_maps(self.params, params))
167244
def prepare_post_parameters(self, post_params=None, files=None):
        
        params = []

        if post_params:
            params = post_params

        if files:
            for k, v in six.iteritems(files):
                if not v:
                    continue
                file_names = v if type(v) is list else [v]
                for n in file_names:
                    with open(n, 'rb') as f:
                        filename = os.path.basename(f.name)
                        filedata = f.read()
                        mimetype = (mimetypes.guess_type(filename)[0] or
                                    'application/octet-stream')
                        params.append(
                            tuple([k, tuple([filename, filedata, mimetype])]))

        return params
1269754
function pickParams(params, keys) {
    params = _.cloneDeep(params);
    // decamelize all options
    for (var key in params) {
        var value = params[key];
        delete params[key];
        // TODO: handle this inconsistency consistently in the library :(
        // 'base64String': introduced by 'image.upload()'
        if (["base64String"].indexOf(key) === -1) {
            key = decamelize(key, "_");
        }
        params[key] = value;
    }
    if (SETTINGS.enforce_params_filter) {
        return _.pick(params, keys);
    }
    return params;
}
1104504
function normalizeParams(params) {
        if (params && params.constructor !== Array && typeof params === 'object') {
            params = _.mapKeys(params, function (value, key) {
                return ':' + _.trimStart(key, ':');
            });
        }
        return params;
    }
94391
function(files, name){
        var reg = /(_STYLE_NAME_|_SCRIPT_NAME_)/gi;
        var tpl = files.replace(reg, function(m,$1,$2){
            if(m == "_STYLE_NAME_"){
                return name;
            }else if(m == "_SCRIPT_NAME_"){
                return name;
            }else{
                return m;
            }
        });
        return tpl;
    }
161330
function (files) {
  return files.reduce(function (filesMap, file) {
    let fileName = path.parse(file).name;
    filesMap[fileName] = readFile(file, 'utf8');

    return filesMap;
  }, {});
}
548654
def source_files(self):
        """"""
        if 'srcs' in self.params and self.params['srcs'] is not None:
            return util.flatten(self.params['srcs'])
155648
function parse_files(files, options) {
  let nodes = {
    // root section node
    '': {
      id: '',
      type: 'section',
      children: [],
      description: '',
      short_description: '',
      href: '#',
      root: true,
      file: '',
      line: 0
    }
  };

  files.forEach(file => {
    let fn = NDoc.parsers[path.extname(file)];

    if (!fn) return;

    /* eslint-disable no-console */
    console.info('Parsing file: ' + file);

    let file_nodes = fn(file, options);

    // TODO:  fail on name clash here as well -- as we might get name clash
    //        from different parsers, or even differnret files
    _.extend(nodes, file_nodes);
  });

  return nodes;
}
416164
function (params) {

            var message = translate(errors[params.caseNum])
                .replace('%n', (params.lineNum + 1).toString())
                .replace('%p', params.pattern)
                .replace('%x', params.start)
                .replace('%y', (params.endLineNum + 1).toString())
                .replace('%f', currentFile);
            if (options.testMode === true) {
                grunt.log.writeln(message);
            } else {
                grunt.warn(message);
            }
        }
593169
def paras(self: object, fileids: str):
        

        for text in self.texts(fileids):
            for para in text.split('\n\n'):
                yield para
541585
def _populate_placeholders_in_files(
            self):
        
        self.log.info(
            'starting the ``_populate_placeholders_in_files`` method')

        rev = reversed(self.directoryContents)
        phs = self.settings["frankenstein"]["placeholder delimiters"]

        # FILE CONTENT FIRST
        for i in self.directoryContents:
            if os.path.isfile(i):
                pathToReadFile = i
                if ".DS_Store" in i:
                    os.remove(i)
                    continue
                try:
                    self.log.debug(
                        "attempting to open the file %s" % (pathToReadFile,))
                    if i[-4:] in [".png", ".jpg", ".gif"]:
                        continue
                    readFile = codecs.open(
                        pathToReadFile, encoding='ISO-8859-1', mode='r')
                    thisData = readFile.read()
                    readFile.close()
                except IOError, e:
                    message = 'could not open the file %s' % (pathToReadFile,)
                    self.log.critical(message)
                    raise IOError(message)

                newContent = thisData
                for k, v in self.phDict.iteritems():
                    for ph in phs:
                        fullPH = ph + k + ph
                        if fullPH in thisData:
                            newContent = newContent.replace(fullPH, v)

                if newContent != thisData:
                    writeFile = codecs.open(
                        pathToReadFile, encoding='ISO-8859-1', mode='w')
                    writeFile.write(newContent)
                    writeFile.close()

        # NOW FILE NAMES
        for i in self.directoryContents:
            if os.path.isfile(i):
                newPath = i
                newFile = i.split("/")[-1]
                for k, v in self.phDict.iteritems():
                    for ph in phs:
                        fullPH = ph + k + ph
                        if fullPH in newFile:
                            newFile = newFile.replace(fullPH, v)
                            newPath = "/".join(i.split("/")
                                               [:-1]) + "/" + newFile
                if newPath != i:
                    try:
                        self.log.debug("attempting to rename file %s to %s" %
                                       (i, newPath))
                        shutil.move(i, newPath)
                    except Exception, e:
                        self.log.error(
                            "could not rename file %s to %s - failed with this error: %s " % (i, newPath, str(e),))
                        sys.exit(0)

        # NOW DRIECTORY NAMES
        theseDirs = []
        for i in reversed(self.directoryContents):
            if os.path.isdir(i):
                theseDirs.append(i)
        for i in theseDirs:
            newPath = i
            newFolder = i.split("/")[-1]
            for k, v in self.phDict.iteritems():
                for ph in phs:
                    fullPH = ph + k + ph
                    if fullPH in newFolder:
                        newFolder = newFolder.replace(fullPH, v)
                        newPath = "/".join(i.split("/")[:-1]) + "/" + newFolder
            if newPath != i:
                try:
                    self.log.debug("attempting to rename file %s to %s" %
                                   (i, newPath))
                    shutil.move(i, newPath)
                except Exception, e:
                    self.log.error(
                        "could not rename file %s to %s - failed with this error: %s " % (i, newPath, str(e),))
                    sys.exit(0)

        self.log.info(
            'completed the ``_populate_placeholders_in_files`` method')
        return None
151946
def do_fileplaceholder(parser, token):
    
    name, params = parse_placeholder(parser, token)
    return FilePlaceholderNode(name, **params)