[chronojump: 6/6] Merge branch 'execute-process'



commit 65219a9446e87415d121e5a7d961b5073957dc80
Merge: 970ce36 1e44bc8
Author: Carles Pina i Estany <carles pina cat>
Date:   Fri Oct 7 23:16:22 2016 +0200

    Merge branch 'execute-process'
    
    Conflicts (resolved):
        chronojump.csproj
        src/chronojumpImporter.cs

 chronojump.csproj         |    1 +
 po/POTFILES.in            |    1 +
 src/Makefile.am           |    1 +
 src/chronojumpImporter.cs |   74 ++++++++------------------
 src/chronopicRegister.cs  |   53 +++++--------------
 src/executeProcess.cs     |  126 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 165 insertions(+), 91 deletions(-)
---
diff --cc chronojump.csproj
index ef9cf0e,7aa9c13..d474e1f
--- a/chronojump.csproj
+++ b/chronojump.csproj
@@@ -883,7 -883,7 +883,8 @@@
      <Compile Include="src\sqlite\chronopicRegister.cs" />
      <Compile Include="src\chronojumpImporter.cs" />
      <Compile Include="src\staticClassState.cs" />
 +    <Compile Include="src\gui\chronopicRegister.cs" />
+     <Compile Include="src\executeProcess.cs" />
    </ItemGroup>
    <ItemGroup>
      <Folder Include="src\" />
diff --cc src/chronojumpImporter.cs
index 980b0df,d516a28..687c307
--- a/src/chronojumpImporter.cs
+++ b/src/chronojumpImporter.cs
@@@ -97,11 -97,7 +97,13 @@@ class ChronojumpImporte
  
                List<string> parameters = new List<string> ();
                parameters.Add ("--source");
 -              parameters.Add (sourceFile);
 +              parameters.Add (temporarySourceFile);
++              
++              // Parent directory of the original database
++              // is where the importer can find the
++              // encoder files
 +              parameters.Add ("--source_base_directory");
-               parameters.Add (Path.Combine(Path.GetDirectoryName(sourceFile), "..")); // Parent directory 
of the original database
-                                                                                                             
                                                  // is where the importer can find the
-                                                                                                             
                                                  // encoder files
++              parameters.Add (Path.Combine(Path.GetDirectoryName(sourceFile), "..")); 
                parameters.Add ("--destination");
                parameters.Add (destinationFile);
                parameters.Add ("--source_session");
@@@ -168,58 -164,28 +170,28 @@@
                        importer_executable = System.IO.Path.Combine (Util.GetPrefixDir (), 
"bin\\chronojump-importer\\chronojump_importer.exe");
                } else {
                        importer_executable = "python";         // chronojump_importer works on Python 2 and 
Python 3
-                       importer_script_path = CommandLineEncoder.EncodeArgText (System.IO.Path.Combine 
(Util.GetPrefixDir (), "bin/chronojump_importer.py"));
+                       importer_script_path = System.IO.Path.Combine (Util.GetPrefixDir (), 
"bin/chronojump_importer.py");
                }
  
-               Process process = new Process();
-               ProcessStartInfo processStartInfo;
- 
-               processStartInfo = new ProcessStartInfo();
- 
-               processStartInfo.Arguments = importer_script_path + " " + string.Join (" ", parameters);
-               processStartInfo.FileName = importer_executable;
- 
-               LogB.Debug ("chronojump-importer fileName: " + processStartInfo.FileName);
-               LogB.Debug ("chronojump-importer Arguments: " + processStartInfo.Arguments);
- 
-               processStartInfo.CreateNoWindow = true;
-               processStartInfo.UseShellExecute = false;
-               processStartInfo.RedirectStandardInput = false;
-               processStartInfo.RedirectStandardError = true;
-               processStartInfo.RedirectStandardOutput = true;
- 
-               process.StartInfo = processStartInfo;
- 
-               try {
-                       process.Start();
-               }
-               catch(Exception e) {
-                       string errorMessage = String.Format (Catalog.GetString("Cannot start:\n" +
-                                                                              "{0}\n" +
-                                                                              "with the parameters:" +
-                                                                              "{1}\n" +
-                                                                              "Exception:\n" +
-                                                                              "{2}"),
-                                                            processStartInfo.FileName, 
processStartInfo.Arguments, e.Message);
-                       return new Result (false, "", errorMessage);
-               }
- 
-               string allOutput = "";
-               allOutput += process.StandardOutput.ReadToEnd();
-               allOutput += process.StandardError.ReadToEnd();
- 
-               process.WaitForExit ();
- 
-               if (process.ExitCode != 0) {
-                       string errorMessage = String.Format (Catalog.GetString("Error executing: {0}\n" +
-                                                                              "with the parameters: {1}\n" +
-                                                                              "output: {2}"),
-                                                            processStartInfo.FileName, 
processStartInfo.Arguments, allOutput);
+               parameters.Insert (0, importer_script_path);
+               ExecuteProcess.Result execute_result = ExecuteProcess.run (importer_executable, parameters);
  
+               if (execute_result.exitCode != 0) {
                        // Python interpretar was executed but the Python file wasn't found or the script 
failed
-                       return new Result (false, allOutput, errorMessage);
+                       string errorMessage = "";
+ 
+                       if (execute_result.errorMessage == "") {
+                               // The Python script has been executed and failed (syntax error, crashed).
+                               // The error message will be in the output:
+                               errorMessage = execute_result.allOutput;
+                       } else {
+                               // The Python script has not been executed, return the error message from 
ExecuteProcess
+                               errorMessage = execute_result.errorMessage;
+                       }
+                       return new Result (false, execute_result.allOutput, errorMessage);
                }
  
-               return new Result (true, allOutput);
+               // All good, returns the output
+               return new Result (true, execute_result.allOutput);
        }
--}
++}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]