/// <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); }
internal static void ParseControlContentForValues(DebianControl controlFile, ref string programName, ref string contactEmail, ref string sourceUrl) { DebianParagraph sourcePara = null; foreach (var para in controlFile.Paragraphs) { if (para.Fields.Count > 0 && para.Fields[0].Tag == "Source") { sourcePara = para; break; } } if (sourcePara != null) { var sourceField = sourcePara.FindField("Source"); programName = sourceField.Value; var maintainerField = sourcePara.FindField("Maintainer"); if (maintainerField != null) { contactEmail = maintainerField.Value; } // Find the "source URL" from // 1) Vcs-Browser (url to see source code repository in the browser), or if that isn't provided // 2) HomePage (url to see some sort of project home page in the browser), or if that isn't provided // 3) Vcs-Git (url to clone git repository on local machine) var urlField = sourcePara.FindField("Vcs-Browser"); if (urlField == null) { urlField = sourcePara.FindField("HomePage"); } if (urlField == null) { urlField = sourcePara.FindField("Vcs-Git"); } if (urlField != null) { sourceUrl = urlField.Value; } } }