scan directory and extract all .gpx files
184416
function ScanGpxDir (gpxdir) {
    var availableRoutes=[];
    var count=0;
    var routesDir = gpxdir;
    var directory = fs.readdirSync(routesDir);
    for (var i in directory) {
        var file = directory [i];
        var route  = path.basename (directory [i],".gpx");
        var name = routesDir + route + '.gpx';
        try {
            if (fs.statSync(name).isFile()) {
                count ++;
                availableRoutes [route] = name;
                console.log ("Found Gpx Route: " + route + " file: " + availableRoutes [route]);
            }
        } catch (err) {/* ignore errors */}
    }
    if (count < 3) {
        console.log ("Find only [%d] GPX file in [%s] please check your directory", count, parsing.opts.gpxdir);
        process.exit (-1);
    }
    return (availableRoutes);
}
973271
def extract_gcc_binaries():
    """"""
    patterns = ['/opt/local/bin/g++-mp-[0-9].[0-9]',
                '/opt/local/bin/g++-mp-[0-9]',
                '/usr/local/bin/g++-[0-9].[0-9]',
                '/usr/local/bin/g++-[0-9]']
    if 'darwin' in platform.platform().lower():
        gcc_binaries = []
        for pattern in patterns:
            gcc_binaries += glob.glob(pattern)
        gcc_binaries.sort()
        if gcc_binaries:
            _, gcc = os.path.split(gcc_binaries[-1])
            return gcc
        else:
            return None
    else:
        return None
1059286
def scan_file(project, project_dir, binaries, ips, urls, file_audit_list,
              file_audit_project_list, flag_list, ignore_list, hashlist,
              file_ignore, ignore_directories, url_ignore, ip_ignore, apikey):
    
    logger.info("Commencing scan tasks..")
    for root, dirs, files in os.walk(project_dir):
        # Filter out ignored directories from list.
        for items in files:
            full_path = os.path.join(root, items)
            split_path = full_path.split(project + '/', 1)[-1]
            # Check for Blacklisted file names
            if not any(x in split_path for x in ignore_directories):
                if file_audit_list.search(full_path) and not \
                        file_audit_project_list.search(full_path):
                    match = file_audit_list.search(full_path)
                    logger.error('Blacklisted filename: %s', full_path)
                    logger.error('Matched String: %s', match.group())
                    with open(reports_dir + "file-names_" + project + ".log",
                              "a") as gate_report:
                                gate_report. \
                                    write('Blacklisted filename: {0}\n'.
                                          format(full_path))
                                gate_report. \
                                    write('Matched String: {0}'.
                                          format(match.group()))

                # Check if Binary is whitelisted
                if is_binary(full_path) and binaries:

                    split_path = full_path.split(project + '/', 1)[-1]
                    binary_hash = hashlist.binary_hash(project, split_path)
                    with open(full_path, 'rb') as afile:
                        hasher = hashlib.sha256()
                        buf = afile.read()
                        hasher.update(buf)
                        sha256hash = hasher.hexdigest()
                    if sha256hash in binary_hash:
                        logger.info('Found matching file hash for: %s', full_path)
                        logger.info('No further action needed for: %s', full_path)
                    else:
                        logger.info('Non Whitelisted Binary file: %s', full_path)
                        scan_binary(full_path, split_path, project, sha256hash, apikey)

                else:
                    if not items.endswith(tuple(file_ignore)) and not is_binary(full_path):
                        try:
                            fo = open(full_path, 'r')
                            lines = fo.readlines()
                        except IOError:
                            logger.error('%s does not exist', full_path)

                        for line in lines:
                            # Find IP Addresses and send for report to Virus Total
                            if ips:
                                ipaddr = re.findall(r'(?:\d{1,3}\.)+(?:\d{1,3})', line)
                                if ipaddr:
                                    ipaddr = ipaddr[0]
                                    if re.search(ip_ignore, ipaddr):
                                        logger.info('%s is in IP ignore list.', ipaddr)
                                    else:
                                        try:
                                            ipaddress.ip_address(ipaddr).is_global
                                            scan_ipaddr(ipaddr, line, project, split_path, apikey)
                                        except:
                                            pass  # Ok to pass here, as this captures the odd string which is nt an IP Address

                            # Check for URLs and send for report to Virus Total
                            if urls:
                                url = re.search("(?P<url>https?://[^\s]+)", line) or re.search("(?P<url>www[^\s]+)", line)
                                if url:
                                    url = url.group("url")
                                    if re.search(url_ignore, url):
                                        logger.info('%s is in URL ignore list.', url)
                                    else:
                                        scan_url(url, line, project, split_path, apikey)

                            # Check flagged content in files
                            for key, value in flag_list.items():
                                regex = value['regex']
                                desc = value['desc']
                                if re.search(regex, line) and not re.search(ignore_list, line):
                                    logger.error('File contains violation: %s', full_path)
                                    logger.error('Flagged Content: %s', line.rstrip())
                                    logger.error('Matched Regular Exp: %s', regex)
                                    logger.error('Rationale: %s', desc.rstrip())
                                    with open(reports_dir + "contents-" + project + ".log", "a") as gate_report:
                                        gate_report.write('File contains violation: {0}\n'.format(full_path))
                                        gate_report.write('Flagged Content: {0}'.format(line))
                                        gate_report.write('Matched Regular Exp: {0}'.format(regex))
                                        gate_report.write('Rationale: {0}\n'.format(desc.rstrip()))
482608
def extract_chm (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    return [cmd, os.path.abspath(archive), outdir]
1238477
def extract_alzip (archive, compression, cmd, verbosity, interactive, outdir):
    """"""
    return [cmd, '-d', outdir, archive]
700687
function findAllCompressionFiles(fs, folderPath) {
        // check if folder exists
        if (!fs.existsSync(folderPath))  return; 
        
        var files = fs.readdirSync(folderPath);
        //iterate all files in the current folder
        for (var i = 0; i < files.length; i++) {
            var filePath = folderPath + "/" + files[i];
            var stats = fs.statSync(filePath);
            if (stats.isDirectory()) {
                //recursively search folders and append the matching files
                findAllCompressionFiles(fs, filePath);
            } else {
                addAllMatchingCompressionsToFile(files[i], filePath);
            }
        }
    }
815217
function scanAll(cb) {
    var done = u.after(staticPaths.length, u.maybe(cb));
    u.each(staticPaths, function(sp) {
      scan(sp, function() {
        done();
      });
    });
  }
359477
def extract(self):
        """"""
        if self.files:
            return dict((f, self.read_file(f)) for f in self.files)
        else:
            raise RuntimeError("Can't extract whole archive without listfile.")
305823
private static Set<File> findAllFiles(File dir) {
        Set<File> foundFiles = new HashSet<>();
        if (dir == null) {
            return foundFiles;
        }
        recurse(dir, foundFiles);
        return foundFiles;
    }
798442
def grep(rootdir, searched):
    ""
    to_inspect = []
    for root, dirs, files in os.walk(rootdir):
        for _file in files:
            if _file.endswith('.rst'):
                to_inspect.append(join(root, _file))

    to_check = ((_file, open(_file, 'r').read()) for _file in to_inspect)
    to_check = filter(lambda item: searched in item[1], to_check)
    to_check = map(lambda item: item[0], to_check)
    return to_check
974776
def extract_files(files):
    """"""
    expanded_files = []
    legal_extensions = [".md", ".txt", ".rtf", ".html", ".tex", ".markdown"]

    for f in files:
        # If it's a directory, recursively walk through it and find the files.
        if os.path.isdir(f):
            for dir_, _, filenames in os.walk(f):
                for filename in filenames:
                    fn, file_extension = os.path.splitext(filename)
                    if file_extension in legal_extensions:
                        joined_file = os.path.join(dir_, filename)
                        expanded_files.append(joined_file)

        # Otherwise add the file directly.
        else:
            expanded_files.append(f)

    return expanded_files
682477
function scanSourceDir() {
		var directoryLen = srcDirectory.length;

		glob.sync(srcDirectory + '/**/*.js').forEach(function(filename) {
			var module = require(filename);

			// Remove the srcDirectory from the file name
			// We don't want that to be part of the module ID
			var moduleFilename = filename.substr(directoryLen+1);
			var newMapping = buildMapping(module, moduleFilename);
			mappings[newMapping.normId.id] = newMapping;
		});
	}
454376
def list_files(path = Dir.pwd)
      g = MiniGit.new(path)
      g.capturing.ls_files.split
    end
981759
def gp_ccX():
    """"""
    inDir, outDir = getWorkDirs()
    data, alldata = OrderedDict(), None
    for infile in os.listdir(inDir):
        # get key and import data
        key = os.path.splitext(infile)[0].replace('_', '/')
        data_import = np.loadtxt(open(os.path.join(inDir, infile), 'rb'))
        # convert to log10 vs log10 plot, z=log10(y) => dz=0.434*dy/y
        data_import[:,3] = 0.434*(data_import[:,3]/data_import[:,1])
        data_import[:,(0,1)] = np.log10(data_import[:,(0,1)])
        data_import[:,2] = 0
        # fill dictionary
        data[key] = data_import
        alldata = data[key] if alldata is None else np.vstack((alldata, data[key]))
    # fit linear part first
    lindata = alldata[alldata[:,0]>2.5]
    m = (lindata[-1,1]-lindata[0,1])/(lindata[-1,0]-lindata[0,0])
    t = lindata[0,1] - m * lindata[0,0]
    popt1, pcov = curve_fit(
        linear, lindata[:,0], lindata[:,1], p0=[m, t],
        sigma=lindata[:,3], absolute_sigma=True
    )
    # fit full range
    popt2, pcov = curve_fit(
        lambda x, c, d: fitfunc(x, popt1[0], popt1[1], c, d),
        alldata[:,0], alldata[:,1], sigma=alldata[:,3], absolute_sigma=True,
    )
    popt = np.hstack((popt1, popt2))
    model = lambda x: fitfunc(x, *popt)
    # calculate mean standard deviation of data from parameterization
    yfit = np.array([model(x) for x in alldata[:,0]])
    stddev = 1.5*np.sqrt( # multiple of "sigma"
        np.average((alldata[:,1]-yfit)**2, weights=1./alldata[:,3])
    )
    print 'stddev = %.2g' % stddev
    errorband = np.array([[x, model(x), 0, 0, stddev] for x in np.linspace(1,4)])
    # make plot
    fitdata = np.array([[x, model(x), 0, 0, 0] for x in np.linspace(1,4)])
    par_names = ['a', 'b', 'c', 'd']
    energies = [19.6, 27, 39, 62.4, 200]
    labels = dict(
        ('%s = %.3g' % (par_name, popt[i]), [3.3, 3-i*0.2, True])
        for i,par_name in enumerate(par_names)
    )
    ccX_vals = [10**model(np.log10(energy)) for energy in energies]
    ccX = [' '.join([
        '%g GeV:' % energy,
        '({})'.format(ufloat(ccX_vals[i], stddev/0.434*ccX_vals[i])),
        '{/Symbol \155}b'
    ]) for i,energy in enumerate(energies)]
    print ccX
    #labels.update(dict(
    #    (cc, [1+i*0.5, 4.5+(i%2+1)*0.2, True]) for i,cc in enumerate(ccX)
    #))
    make_plot(
        data = [errorband] + data.values() + [fitdata],
        properties = [
            'with filledcurves lt 1 lw 5 pt 0 lc %s' % default_colors[8]
        ] + [
            'lc %s lw 4 lt 1 pt 18 ps 1.5' % (default_colors[i])
            for i in xrange(len(data))
        ] + ['with lines lc 0 lw 4 lt 1'],
        titles = [''] + data.keys() + ['y = ax+b - e^{-cx+d}'],
        xlabel = 'x = log_{10}[{/Symbol \326}s_{NN} (GeV)]',
        ylabel = 'y = log_{10}[{/Symbol \163}@_{c@^{/=18-}c}^{NN} ({/Symbol \155}b)]',
        name = os.path.join(outDir, 'ccX'),
        size = '11.4in,8.3in', xr = [1, 4], yr = [0.5,4.5],
        key = ['bottom right', 'nobox', 'width -5'],
        tmargin = 0.98, rmargin = 0.99, bmargin = 0.13,
        lines = dict(
            ('y=%f' % (np.log10(energy)), 'lc 0 lw 2 lt 2') for energy in energies
        ), labels = labels,
    )
1293585
protected void scanDir(File srcDir, File destDir, String[] files) {
    GlobPatternMapper m = new GlobPatternMapper();
    SourceFileScanner sfs = new SourceFileScanner(this);
    List<File> newFiles;
    if(!isForce()) {
      log.warn("Relying on ant's SourceFileScanner, which only looks at timestamps.  If broken references result, try setting option 'force' to true.");
    }
    for (String extension : getScriptExtensions()) {
      m.setFrom("*." + extension);
      m.setTo("*.class");
      log.debug("Scanning for *." + extension + " files...");
      if(isForce()) {
        newFiles = asFiles(srcDir, files, m);
      } else {
        newFiles = Arrays.asList(sfs.restrictAsFiles(files, srcDir, destDir, m));
      }
      log.debug("Found these files:");
      for(File newFile : newFiles) {
        log.debug('\t' + newFile.getAbsolutePath());
      }
      compileList.addAll(newFiles);
    }

  }
129372
def _prep_grabix_indexes(in_files, data):
    
    # if we have gzipped but not bgzipped, add a fake index for CWL support
    # Also skips bgzip indexing if we don't need alignment splitting
    if _ready_gzip_fastq(in_files, data) and (not _ready_gzip_fastq(in_files, data, require_bgzip=True) or
                                              dd.get_align_split_size(data) is False):
        for in_file in in_files:
            if not utils.file_exists(in_file + ".gbi"):
                with file_transaction(data, in_file + ".gbi") as tx_gbi_file:
                    with open(tx_gbi_file, "w") as out_handle:
                        out_handle.write("Not grabix indexed; index added for compatibility.\n")
    else:
        items = [[{"bgzip_file": x, "config": copy.deepcopy(data["config"])}] for x in in_files if x]
        run_multicore(_grabix_index, items, data["config"])
    return data
684495
def extract(self, extractdir=None, verbose=False):
        """"""
        if extractdir is None:
            filebase, ext = os.path.splitext(self.path)
            if ext in ('.gz', '.bz2', '.xz'):
                filebase, _ext = os.path.splitext(filebase)
            extractdir = os.path.basename(filebase)
            if os.path.exists(extractdir):
                tempdir = tempfile.mkdtemp(prefix='vimball-', dir=os.getcwd())
                extractdir = os.path.join(tempdir.split('/')[-1], extractdir)

        self.fd.seek(0)
        for filename, lines, offset in self.files:
            filepath = os.path.join(extractdir, filename)
            try:
                directory = os.path.dirname(filepath)
                mkdir_p(directory)
            except OSError as e:
                raise ArchiveError(f"failed creating directory {directory!r}: {e.strerror}")
            with open(filepath, 'w') as f:
                if verbose:
                    print(filepath)
                self.fd.seek(offset)
                for i in range(lines):
                    f.write(self.readline())