<commit_before>/*
 * grunt-easy-rpm
 * https://github.com/panitw/easy-rpm
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var shortid = require("shortid"),
  path = require("path");

function writeSpecFile(grunt, files, options) {

    var pkgName = options.name + "-" + options.version + "-" + options.buildArch,
      specFilepath = path.join(options.tempDir, "SPECS", pkgName + ".spec"),
      b = [],
      i = 0;
    
    b.push("%define   _topdir " + path.resolve(options.tempDir));
    b.push("");
    b.push("Name: "+options.name);
    b.push("Version: "+options.version);
    b.push("Release: "+options.release);
    b.push("Group: "+options.group);
    b.push("Summary: "+options.summary);
    b.push("Group: "+options.group);
    b.push("License: "+options.license);
    b.push("BuildArch: "+options.buildArch);
    if (typeof options.autoReqProv !== "undefined") {
        b.push("AutoReqProv: "+options.autoReqProv);
    }

    if (options.dependencies.length > 0) {
      b.push("Requires: " + options.dependencies.join(","));
    }

    b.push("");
    b.push("%description");
    b.push(options.description);
    b.push("");
    b.push("%files");
    for (i=0;i<files.length;i++) {
       b.push(files[i]);
    }
    b.push("");
    b.push("%pre");
    for (i=0; i<options.preInstallScript.length; i++) {
      b.push(options.preInstallScript[i]);
    }
    b.push("");
    b.push("%post");
    for (i=0; i<options.postInstallScript.length; i++) {
      b.push(options.postInstallScript[i]);
    }
    b.push("");
    b.push("%preun");
    for (i=0; i<options.preUninstallScript.length; i++) {
      b.push(options.preUninstallScript[i]);
    }
    b.push("");
    b.push("%postun");
    for (i=0; i<options.postUninstallScript.length; i++) {
      b.push(options.postUninstallScript[i]);
    }

    var specFileContent = b.join("\n");
    grunt.file.write(specFilepath, specFileContent);

    return specFilepath;
}


module.exports = function(grunt) {

  grunt.registerMultiTask("easy_rpm", "Easily create RPM package to install files/directories", function() {

    var options = this.options({
      name: "noname",
      summary: "No Summary",
      description: "No Description",
      version: "0.1.0",
      release: "1",
      license: "MIT",
      vendor: "Vendor",
      group: "Development/Tools",
      buildArch: "noarch",
      dependencies: [],
      preInstallScript: [],
      postInstallScript: [],
      preUninstallScript: [],
      postUninstallScript: [],
      tempDir: "tmp-"+shortid.generate(),
      rpmDestination: ".",
      keepTemp: false,
      quoteFilePaths: true
    });

    var tmpDir = path.resolve(options.tempDir),
        buildRoot = tmpDir + "/BUILDROOT/",
        rpmStructure = ["BUILD","BUILDROOT","RPMS","SOURCES","SPECS","SRPMS"],
        done = this.async();

    //If the tmpDir exists (probably from previous build), delete it first
    if (grunt.file.exists(tmpDir)) {
      grunt.log.writeln("Deleting old tmp dir");
      grunt.file.delete(tmpDir);
    }

    //Create RPM build folder structure
    grunt.log.writeln("Creating RPM folder structure at "+tmpDir);
    for (var i=0;i<rpmStructure.length;i++) {
      grunt.file.mkdir(tmpDir+"/"+rpmStructure[i]);
    }

    //Files to exclude
    var filesToExclude = [];
    if (this.data.excludeFiles) {
      filesToExclude = grunt.file.expand(this.data.excludeFiles).map(function (fileName) {
        return path.normalize(fileName);
      });
    }

    //Copy source to the BUILDROOT folder<commit_msg>Package settings precede default options.<commit_after>/*
 * grunt-easy-rpm
 * https://github.com/panitw/easy-rpm
 *
 * Copyright (c) 2013 <NAME>
 * Licensed under the MIT license.
 */

'use strict';

var shortid = require("shortid"),
  path = require("path");

function writeSpecFile(grunt, files, options) {

    var pkgName = options.name + "-" + options.version + "-" + options.buildArch,
      specFilepath = path.join(options.tempDir, "SPECS", pkgName + ".spec"),
      b = [],
      i = 0;
    
    b.push("%define   _topdir " + path.resolve(options.tempDir));
    b.push("");
    b.push("Name: "+options.name);
    b.push("Version: "+options.version);
    b.push("Release: "+options.release);
    b.push("Group: "+options.group);
    b.push("Summary: "+options.summary);
    b.push("Group: "+options.group);
    b.push("License: "+options.license);
    b.push("BuildArch: "+options.buildArch);
    if (typeof options.autoReqProv !== "undefined") {
        b.push("AutoReqProv: "+options.autoReqProv);
    }

    if (options.dependencies.length > 0) {
      b.push("Requires: " + options.dependencies.join(","));
    }

    b.push("");
    b.push("%description");
    b.push(options.description);
    b.push("");
    b.push("%files");
    for (i=0;i<files.length;i++) {
       b.push(files[i]);
    }
    b.push("");
    b.push("%pre");
    for (i=0; i<options.preInstallScript.length; i++) {
      b.push(options.preInstallScript[i]);
    }
    b.push("");
    b.push("%post");
    for (i=0; i<options.postInstallScript.length; i++) {
      b.push(options.postInstallScript[i]);
    }
    b.push("");
    b.push("%preun");
    for (i=0; i<options.preUninstallScript.length; i++) {
      b.push(options.preUninstallScript[i]);
    }
    b.push("");
    b.push("%postun");
    for (i=0; i<options.postUninstallScript.length; i++) {
      b.push(options.postUninstallScript[i]);
    }

    var specFileContent = b.join("\n");
    grunt.file.write(specFilepath, specFileContent);

    return specFilepath;
}


module.exports = function(grunt) {

  grunt.registerMultiTask("easy_rpm", "Easily create RPM package to install files/directories", function() {

    var pkg = grunt.file.readJSON('package.json'),
        defaults = {
          name: "noname",
          summary: "No Summary",
          description: "No Description",
          version: "0.1.0",
          release: "1",
          license: "MIT",
          vendor: "Vendor",
          group: "Development/Tools",
          buildArch: "noarch",
          dependencies: [],
          preInstallScript: [],
          postInstallScript: [],
          preUninstallScript: [],
          postUninstallScript: [],
          tempDir: "tmp-"+shortid.generate(),
          rpmDestination: ".",
          keepTemp: false,
          quoteFilePaths: true
        },
        // Apply options and defaults in the following order of precedence:
        //    gruntInit > package > defaults
        // Where options on the left take precedence over those on the right.
        options = this.options(grunt.util._.defaults(pkg, defaults)),
        tmpDir = path.resolve(options.tempDir),
        buildRoot = tmpDir + "/BUILDROOT/",
        rpmStructure = ["BUILD","BUILDROOT","RPMS","SOURCES","SPECS","SRPMS"],
        done = this.async();

    //If the tmpDir exists (probably from previous build), delete it first
    if (grunt.file.exists(tmpDir)) {
      grunt.log.writeln("Deleting old tmp dir");
      grunt.file.delete(tmpDir);
    }

    //Create RPM build folder structure
    grunt.log.writeln("Creating RPM folder structure at "+tmpDir);
    for (var i=0;i<rpmStructure.length;i++) {
      grunt.file.mkdir(tmpDir+"/"+rpmStructure[i]);
    }

    //Files to exclude
    var filesToExclude = [];
    if (this.data.excludeFiles) {
      filesToExclude = grunt.file.expand(this.data.excludeFiles).map(function (fileName) {
        return path.normalize(fileName);
      });
    }

    //Copy source to the BUILDROOT folder
{'fraction_non_alphanumeric': 0.17192889360573096, 'fraction_numerical': 0.0042451578668081715, 'mean_word_length': 2.8018154311649015, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3347003', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2430, 'n_words': 465}