Tidy up a license string

    e.g. "::OSI::   mit software license" -> "MIT"
556586
def license_cleanup(text):
    
    if not text:
        return None
    text = text.rsplit(':', 1)[-1]
    replacements = [
        'licenses',
        'license',
        'licences',
        'licence',
        'software',
        ',',
    ]
    for replacement in replacements:
        text = text.replace(replacement, '')
    text = text.strip().upper()
    text = text.replace(' ', '_')
    text = text.replace('-', '_')
    if any(trigger.upper() in text for trigger in BAD_LICENSES):
        return None
    return text
1333818
function matchLicense (licenseString) {
  // Find all textual matches on license text.
  var normalized = normalizeText(licenseString)
  var matchingLicenses = []

  var license

  // Check matches of normalized license content against signatures.
  for (var i = 0; i < licenses.length; i++) {
    license = licenses[i]
    var match = false
    for (var j = 0; j < license.signatures.length; j++) {
      if (normalized.indexOf(license.signatures[j]) >= 0) {
        match = true
        break
      }
    }
    if (match) {
      matchingLicenses.push(license)
    }
  }
  // For single-line license, check if it's a known license id.
  if (matchingLicenses.length === 0 && !/[\n\f\r]/.test(licenseString) && licenseString.length < 100) {
    var licenseName = normalizeText(licenseString)
    // If there's an extra "license" on the end of the name, drop it ("MIT License" -> "MIT").
    license = licenseIndex[licenseName] || licenseIndex[licenseName.replace(/ licen[sc]e$/, '')]
    if (!license) {
      license = {name: licenseName, id: null}
    }
    matchingLicenses.push(license)
  }
  if (matchingLicenses.length === 0) {
    return null
  }
  if (matchingLicenses.length > 1) {
    console.warn('Multiple matching licenses: ' + matchingLicenses.length, [licenseString, matchingLicenses])
  }
  return matchingLicenses[0]
}
417426
def cut_module_meta(app, what, name, obj, options, lines):
    
    if what != "module":
        return

    lines[:] = [
        line for line in lines if not line.startswith((":copyright:", ":license:"))
    ]
913377
function writeLicensesFile(rootDir) {

    var licenses = checkLicenses(rootDir),
        licensesFileContent = "LICENSES " + "\n \n";

    _(licenses).each(function(licenseData, licenseName) {

        licensesFileContent += licenseName + " : ";

        if(licenseData.isMIT) {
            licensesFileContent += "MIT";
        }
        else {
            licensesFileContent += "Unknown License";
        }

        licensesFileContent += "\n \n";

        if(licenseData.content) {
            licensesFileContent += licenseData.content + "\n \n";
        }

    });

    fs.writeFileSync(rootDir + "/LICENSES", licensesFileContent, "utf-8");
}
120502
def build_license_file(directory, spec):
    
    name, text = '', ''

    try:
        name = spec['LICENSE']
        text = spec['X_MSI_LICENSE_TEXT']
    except KeyError:
        pass # ignore this as X_MSI_LICENSE_TEXT is optional

    if name!='' or text!='':
        file = open( os.path.join(directory.get_path(), 'License.rtf'), 'w' )
        file.write('{\\rtf')
        if text!='':
             file.write(text.replace('\n', '\\par '))
        else:
             file.write(name+'\\par\\par')
        file.write('}')
        file.close()
360618
def cleanup():
        """"""
        for install_dir in linters.INSTALL_DIRS:
            try:
                shutil.rmtree(install_dir, ignore_errors=True)
            except Exception:
                print(
                    "{0}\nFailed to delete {1}".format(
                        traceback.format_exc(), install_dir
                    )
                )
                sys.stdout.flush()
593755
def licenses(family_directory):
  """"""
  found = []
  search_paths = [family_directory]
  gitroot = git_rootdir(family_directory)
  if gitroot and gitroot not in search_paths:
    search_paths.append(gitroot)

  for directory in search_paths:
    if directory:
      for license in ['OFL.txt', 'LICENSE.txt']:
        license_path = os.path.join(directory, license)
        if os.path.exists(license_path):
          found.append(license_path)
  return found
1236093
def license_destination(vendor_dir, libname, filename):
    """"""
    normal = vendor_dir / libname
    if normal.is_dir():
        return normal / filename
    lowercase = vendor_dir / libname.lower().replace('-', '_')
    if lowercase.is_dir():
        return lowercase / filename
    rename_dict = LIBRARY_RENAMES if vendor_dir.name != 'patched' else PATCHED_RENAMES
    # Short circuit all logic if we are renaming the whole library
    if libname in rename_dict:
        return vendor_dir / rename_dict[libname] / filename
    if libname in LIBRARY_DIRNAMES:
        override = vendor_dir / LIBRARY_DIRNAMES[libname]
        if not override.exists() and override.parent.exists():
            # for flattened subdeps, specifically backports/weakref.py
            return (
                vendor_dir / override.parent
            ) / '{0}.{1}'.format(override.name, filename)
        return vendor_dir / LIBRARY_DIRNAMES[libname] / filename
    # fallback to libname.LICENSE (used for nondirs)
    return vendor_dir / '{}.{}'.format(libname, filename)
397157
def license_loader(lic_dir=LIC_DIR):
    """"""
    lics = []
    for ln in os.listdir(lic_dir):
        lp = os.path.join(lic_dir, ln)
        with open(lp) as lf:
            txt = lf.read()
            lic = License(txt)
            lics.append(lic)
    return lics
46697
def _split_tidy(self, string, maxsplit=None):
        """"""

        if maxsplit is None:
            return string.rstrip("\n").split("\t")
        else:
            return string.rstrip("\n").split("\t", maxsplit)
1204042
function cleanupOS(os, pattern, label) {
    // Platform tokens are defined at:
    // http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx
    // http://web.archive.org/web/20081122053950/http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx
    var data = {
      '10.0': '10',
      '6.4':  '10 Technical Preview',
      '6.3':  '8.1',
      '6.2':  '8',
      '6.1':  'Server 2008 R2 / 7',
      '6.0':  'Server 2008 / Vista',
      '5.2':  'Server 2003 / XP 64-bit',
      '5.1':  'XP',
      '5.01': '2000 SP1',
      '5.0':  '2000',
      '4.0':  'NT',
      '4.90': 'ME'
    };
    // Detect Windows version from platform tokens.
    if (pattern && label && /^Win/i.test(os) && !/^Windows Phone /i.test(os) &&
        (data = data[/[\d.]+$/.exec(os)])) {
      os = 'Windows ' + data;
    }
    // Correct character case and cleanup string.
    os = String(os);

    if (pattern && label) {
      os = os.replace(RegExp(pattern, 'i'), label);
    }

    os = format(
      os.replace(/ ce$/i, ' CE')
        .replace(/\bhpw/i, 'web')
        .replace(/\bMacintosh\b/, 'Mac OS')
        .replace(/_PowerPC\b/i, ' OS')
        .replace(/\b(OS X) [^ \d]+/i, '$1')
        .replace(/\bMac (OS X)\b/, '$1')
        .replace(/\/(\d)/, ' $1')
        .replace(/_/g, '.')
        .replace(/(?: BePC|[ .]*fc[ \d.]+)$/i, '')
        .replace(/\bx86\.64\b/gi, 'x86_64')
        .replace(/\b(Windows Phone) OS\b/, '$1')
        .replace(/\b(Chrome OS \w+) [\d.]+\b/, '$1')
        .split(' on ')[0]
    );

    return os;
  }
1306978
def cleanup():
    """"""
    lib_dir = os.path.join(os.environ['CONTAINER_DIR'], '_lib')
    if os.path.exists(lib_dir):
        shutil.rmtree(lib_dir)
    os.mkdir(lib_dir)
89283
def sanitize(filename: str, platform: str=None) -> str:
    
    win_map = {
        # taken from samba Catia module.
        # https://www.samba.org/samba/docs/current/man-html/vfs_catia.8.html
        "\"": "¨",
        "*": "¤",
        "/": "ÿ",
        ":": "÷",
        "<": "«",
        ">": "»",
        "?": "¿",
        "\\": "ÿ",
        "|": "¦",
    }

    posix_map = {
        "/": "-",
    }

    if platform is None:
        platform = sys.platform

    if platform.startswith("win32"):
        replace_map = win_map
    else:
        replace_map = posix_map

    for key, entry in replace_map.items():
        filename = filename.replace(key, entry)

    return filename
348634
def licenses(self):
        """"""
        return {self._acronym_lic(l): l for l in self.resp_text.split('\n')
                if l.startswith(self.prefix_lic)}
352765
private static String cleanSystemId(final String sysId)
    {
        int ix = sysId.indexOf('|');
        if (ix > 0 && URI_WINDOWS_FILE_PATTERN.matcher(sysId).matches()) {
            StringBuilder sb = new StringBuilder(sysId);
            sb.setCharAt(ix, ':');
            return sb.toString();
        }
        return sysId;
    }
1252304
def Clean():
  """"""
  # Find all the compiled proto files and unlink them.
  for (root, _, files) in os.walk(ROOT):
    for filename in files:
      full_filename = os.path.join(root, filename)
      if full_filename.endswith("_pb2.py") or full_filename.endswith(
          "_pb2.pyc"):
        os.unlink(full_filename)
856845
def fix(license = '')
      xml = Nokogiri::XML(File.open(@path), &:noblanks)
      unless license.empty?
        xml.xpath('/comment()').remove
        xml.children.before(
          Nokogiri::XML::Comment.new(xml, "\n#{license.strip}\n")
        )
      end
      ideal = xml.to_xml(indent: 2)
      File.write(@path, ideal)
    end