Exemple #1
0
        /// <summary>
        /// Creates the data structure for a new copyright file (in memory only).
        /// </summary>
        /// <returns>A new CopyrightFile object</returns>
        /// <remarks>
        /// The format of the copyright file is defined at https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/.
        /// </remarks>
        public static CopyrightFile CreateNewCopyrightFile(string programName, string contactEmail, string sourceUrl)
        {
            var copyrights = new CopyrightFile();
            var para       = new DebianParagraph();

            copyrights.Paragraphs.Add(para);
            para.Fields.Add(new DebianField("Format", "http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/"));
            para.Fields.Add(new DebianField("Upstream-Name", programName));
            para.Fields.Add(new DebianField("Upstream-Contact", contactEmail));
            para.Fields.Add(new DebianField("Source", sourceUrl));

            // REVIEW: can we assume these values?
            var programCopyright = String.Format("{0} SIL International", DateTime.Now.Year);
            var programLicense   = "MIT";

            para = new DebianParagraph();
            copyrights.Paragraphs.Add(para);
            para.Fields.Add(new DebianField("Files", "*"));
            para.Fields.Add(new DebianField("Copyright", programCopyright));
            para.Fields.Add(new DebianField("License", programLicense));
            if (programLicense == "MIT")
            {
                copyrights.AddLicenseParagraphIfNeeded(programLicense, StandardMITLicense);
            }

            return(copyrights);
        }
Exemple #2
0
        /// <summary>
        /// Create or update the copyright file in the given debian folder.
        /// </summary>
        /// <param name="debianFolder">Debian folder.</param>
        /// <param name="assemblyFolder">Assembly folder.</param>
        /// <param name="prefixFolder">Prefix folder.</param>
        public static int CreateOrUpdateCopyrightFile(string debianFolder, string prefixFolder)
        {
            CopyrightFile copyrights;

            if (!File.Exists(Path.Combine(debianFolder, "copyright")))
            {
                string programName  = null;
                string contactEmail = null;
                string sourceUrl    = null;
                // First try to read the primary information from a "Source" paragraph in the control file.
                var controlFile = new DebianControl(Path.Combine(debianFolder, "control"));
                ParseControlContentForValues(controlFile, ref programName, ref contactEmail, ref sourceUrl);
                // If necessary, try to read some primary information from the changelog file.
                if (String.IsNullOrEmpty(programName) || String.IsNullOrEmpty(contactEmail))
                {
                    var lines = File.ReadAllLines(Path.Combine(debianFolder, "changelog"), Encoding.UTF8);
                    ParseChangelogContentForValues(lines, ref programName, ref contactEmail);
                }
                // If we can't derive any information, flag it as unknown.
                if (String.IsNullOrEmpty(programName))
                {
                    programName = "UNKNOWN";
                }
                if (String.IsNullOrEmpty(contactEmail))
                {
                    contactEmail = "UNKNOWN";
                }
                if (String.IsNullOrEmpty(sourceUrl))
                {
                    sourceUrl = "UNKNOWN";
                }
                copyrights           = CreateNewCopyrightFile(programName, contactEmail, sourceUrl);
                copyrights._filepath = Path.Combine(debianFolder, "copyright");
                Console.WriteLine("ExtractCopyright: creating new file at \"{0}\"", copyrights._filepath);
            }
            else
            {
                // Initialize from an existing copyright file.
                copyrights = new CopyrightFile(Path.Combine(debianFolder, "copyright"));
                Console.WriteLine("ExtractCopyright: updating existing file at \"{0}\"", copyrights._filepath);
            }

            var ackDict = SIL.Acknowledgements.AcknowledgementsProvider.CollectAcknowledgements();

            foreach (var key in ackDict.Keys)
            {
                copyrights.AddOrUpdateParagraphFromAcknowledgement(ackDict[key], prefixFolder);
            }

            copyrights.WriteDebianControlFile();

            return((int)ExitValue.Okay);
        }
Exemple #3
0
        static int Main(string[] args)
        {
            string debianFolder = null;
            string prefixFolder = null;

            for (int i = 0; i < args.Length; ++i)
            {
                switch (args[i])
                {
                case "-d":
                case "--debian":
                    if (++i < args.Length)
                    {
                        debianFolder = args[i];
                    }
                    else
                    {
                        return(ShowUsage(CopyrightFile.ExitValue.NoDebianFolder));
                    }
                    break;

                case "-?":
                case "-h":
                case "--help":
                    return(ShowUsage(CopyrightFile.ExitValue.Okay));

                    break;

                case "-p":
                case "--prefix":
                    if (++i < args.Length)
                    {
                        prefixFolder = args[i];
                    }
                    else
                    {
                        return(ShowUsage(CopyrightFile.ExitValue.NoPrefixFolder));
                    }
                    break;
                }
            }
            // If the user didn't supply the debian folder, try to find one at the current
            // location or at a parent location in the directory tree.
            if (debianFolder == null)
            {
                var current = Directory.GetCurrentDirectory();
                debianFolder = Path.Combine(current, "debian");
                while (!string.IsNullOrEmpty(current) && !Directory.Exists(debianFolder))
                {
                    current = Path.GetDirectoryName(current);
                    if (!string.IsNullOrEmpty(current))
                    {
                        debianFolder = Path.Combine(current, "debian");
                    }
                }
                if (Directory.Exists(debianFolder))
                {
                    Console.WriteLine("ExtractCopyright: found debian folder at \"{0}\"", debianFolder);
                }
            }
            if (!Directory.Exists(debianFolder))
            {
                return(ShowUsage(CopyrightFile.ExitValue.NoDebianFolder));
            }
            if (!File.Exists(Path.Combine(debianFolder, "control")) ||
                !File.Exists(Path.Combine(debianFolder, "changelog")))
            {
                Console.WriteLine("ExtractCopyright: the debian folder does not contain both the control and changelog files.");
                return(ShowUsage(CopyrightFile.ExitValue.NoDebianFolder));
            }

            // If the user didn't supply the prefix folder, use an empty string.
            if (prefixFolder == null)
            {
                prefixFolder = String.Empty;
            }

            return(CopyrightFile.CreateOrUpdateCopyrightFile(debianFolder, prefixFolder));
        }