From 620aa325bbf2845c393a6ac5278d81484fe3540f Mon Sep 17 00:00:00 2001 From: Renzo Ferrara Date: Tue, 27 Dec 2016 21:43:10 +0100 Subject: [PATCH] Added copy option. Changed output folder naming convention (removed extension) --- README.md | 33 ++++++++++++++++++++++++-- mbpm2git/Assets/DestinationFolder.cs | 3 ++- mbpm2git/Assets/Procedure.cs | 13 +++++----- mbpm2git/Executer.cs | 24 ++++++++++++------- mbpm2git/Operations/Extractor.cs | 2 +- mbpm2git/Operations/FormatterForXML.cs | 1 + mbpm2git/Options.cs | 10 ++++---- mbpm2git/Properties/AssemblyInfo.cs | 2 +- 8 files changed, 64 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 2df9c60..1d7062f 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,31 @@ -# mbpm2git -* This utility converts .xep or .xel file into text file to be used with git or any other version control system +mbpm2git +=== +mbpm2git is a command line tool that converts *.xep* or *.xel* file into text file to be used with git or any other version control system. + +Overview +--- +Metastorm BPM 7 procedures and libraries files are stored in zip format files with .xep or .xel extension. +This format is unsuitable to track changes or to be used with a version control system like git. +mbpm2git automates the workflow and extracts the content in text and xml files ready to be committed to git. + +Install +--- +- Copy the bin directory in *Programs Files* folder renaming it mbpm2git (`C:\Program Files\mbpm2git`) +- Add the folder to the system's path with **setx** command (`setx /m path "%path%;C:\Program Files\mbpm2git"`) + +Use +--- +**`mbpm2git.exe -i`***`xep/xel-file`***`-o`***`output-directory`***`[-f] [-c]`** + +Options: +``` + -i, --input Required. Input file to read + -o, --output Required. Output path to write + -f, --formatxml Format xml file + -c, --copy Copy xep or xel file + --help Display this help screen. +``` + +License +--- +The license of the project is the [MIT](LICENSE). \ No newline at end of file diff --git a/mbpm2git/Assets/DestinationFolder.cs b/mbpm2git/Assets/DestinationFolder.cs index fa25dae..3b94fb3 100644 --- a/mbpm2git/Assets/DestinationFolder.cs +++ b/mbpm2git/Assets/DestinationFolder.cs @@ -41,7 +41,8 @@ public DestinationFolder(string d) } catch (Exception ex) { - logger.Debug(ex.Message); + logger.Debug(ex.Message); + throw ex; } } diff --git a/mbpm2git/Assets/Procedure.cs b/mbpm2git/Assets/Procedure.cs index 367cfe0..6778a68 100644 --- a/mbpm2git/Assets/Procedure.cs +++ b/mbpm2git/Assets/Procedure.cs @@ -15,7 +15,7 @@ public bool IsLibrary() { bool lib = false; - if (_path.Extension.ToLower() == "xel".ToLower()) + if (_path.Extension.ToLower() == ".xel".ToLower()) { lib = true; } @@ -33,17 +33,18 @@ public string Name() return _path.Name; } + public string NameForDirectory() + { + string name4dir = Path.GetFileNameWithoutExtension(_path.Name); + return name4dir; + } + public Procedure(string path) { _path = new FileInfo(path); if (_path == null) throw new Exception("invalid procedure path"); - if (!_path.Exists) - { - _path = new FileInfo(Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, path)); - } - if (!_path.Exists) { throw new Exception("procedure file does not exist"); diff --git a/mbpm2git/Executer.cs b/mbpm2git/Executer.cs index 0316815..30c1f19 100644 --- a/mbpm2git/Executer.cs +++ b/mbpm2git/Executer.cs @@ -18,31 +18,37 @@ public static void Execute(string[] args) { string procedureName = string.Empty; string procedureDirecory = string.Empty; - bool formatExtractedXML = false; var options = new Options(); + if (CommandLine.Parser.Default.ParseArguments(args, options)) { procedureName = options.InputFile; procedureDirecory = options.OutputPath; - if (options.FormatExtractedXML) - { - formatExtractedXML = true; - } - - logger.Debug("checking file {0}", procedureName); + logger.Debug("checking file: {0}", procedureName); Procedure p = new Procedure(procedureName); + logger.Debug("procedure file: {0}", p.FullName()); - logger.Debug("checking destination folder {0}", procedureDirecory); + logger.Debug("checking destination folder: {0}", procedureDirecory); DestinationFolder d = new DestinationFolder(procedureDirecory); + logger.Debug("destination folder: {0}", d.FullName()); Extractor.Execute(p, d); - if (formatExtractedXML) + + if (options.FormatExtractedXML) { logger.Debug("formatting xml files.."); FormatterForXML.XmlSearch(d.FullName()); } + + if (options.CopyZippedFile) + { + string dest = Path.Combine(d.FullName(), p.Name()); + logger.Debug("copy file {0}..", dest); + File.Copy(p.FullName(), dest, true); + } + logger.Info("Extraction done"); } else diff --git a/mbpm2git/Operations/Extractor.cs b/mbpm2git/Operations/Extractor.cs index 26312dc..c2141f4 100644 --- a/mbpm2git/Operations/Extractor.cs +++ b/mbpm2git/Operations/Extractor.cs @@ -26,7 +26,7 @@ public static void Execute(Procedure p, DestinationFolder d) try { - string subFolder = Path.Combine(d.FullName(), p.Name()); + string subFolder = Path.Combine(d.FullName(), p.NameForDirectory()); finalDestination = new DirectoryInfo(subFolder); logger.Debug("checking procedure folder {0}..", finalDestination.FullName); if (finalDestination.Exists) diff --git a/mbpm2git/Operations/FormatterForXML.cs b/mbpm2git/Operations/FormatterForXML.cs index 599bb65..c8075c0 100644 --- a/mbpm2git/Operations/FormatterForXML.cs +++ b/mbpm2git/Operations/FormatterForXML.cs @@ -52,6 +52,7 @@ private static void FormatFile(string filePath) } catch(Exception ex) { + logger.Error("Error {0}", ex.Message); logger.Error("Error converting {0}", filePath); } diff --git a/mbpm2git/Options.cs b/mbpm2git/Options.cs index ed7c240..9f6a2e6 100644 --- a/mbpm2git/Options.cs +++ b/mbpm2git/Options.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using CommandLine; using CommandLine.Text; +using System.Reflection; namespace mbpm2git { @@ -20,19 +21,20 @@ class Options [Option('f', "formatxml", Required = false, HelpText = "Format xml file")] public bool FormatExtractedXML { get; set; } - //[Option("length", DefaultValue = -1, HelpText = "The maximum number of bytes to process.")] - //public int MaximumLength { get; set; } + [Option('c', "copy", Required = false, HelpText = "Copy xep or xel file")] + public bool CopyZippedFile { get; set; } [HelpOption] public string GetUsage() { + string v = Assembly.GetExecutingAssembly().GetName().Version.ToString(3); var help = new HelpText { - Heading = new HeadingInfo("mbpm2git.exe", "" ), + Heading = new HeadingInfo("mbpm2git.exe", v ), AdditionalNewLineAfterOption = false, AddDashesToOption = true }; - help.AddPreOptionsLine("Usage: mbpm2git.exe -i [xep file path] -o [output directory file path]"); + help.AddPreOptionsLine("Usage: mbpm2git.exe -i xep_file_path -o output_directory_path [-f] [-c]"); help.AddOptions(this); return help; diff --git a/mbpm2git/Properties/AssemblyInfo.cs b/mbpm2git/Properties/AssemblyInfo.cs index 92f2429..27e9a46 100644 --- a/mbpm2git/Properties/AssemblyInfo.cs +++ b/mbpm2git/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyVersion("1.0.4.0")] [assembly: AssemblyFileVersion("1.0.0.0")]