lmi-commits
[Top][All Lists]
Advanced

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

[lmi-commits] [6323] Use unique_filepath() for all PDF and spreadsheet o


From: Greg Chicares
Subject: [lmi-commits] [6323] Use unique_filepath() for all PDF and spreadsheet output
Date: Tue, 06 Oct 2015 15:17:19 +0000

Revision: 6323
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6323
Author:   chicares
Date:     2015-10-06 15:17:19 +0000 (Tue, 06 Oct 2015)
Log Message:
-----------
Use unique_filepath() for all PDF and spreadsheet output

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/emit_ledger.cpp
    lmi/trunk/emit_ledger.hpp
    lmi/trunk/gpt_server.cpp
    lmi/trunk/illustration_view.cpp
    lmi/trunk/mec_server.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2015-10-06 13:26:42 UTC (rev 6322)
+++ lmi/trunk/ChangeLog 2015-10-06 15:17:19 UTC (rev 6323)
@@ -37007,3 +37007,40 @@
   ledger_invariant.hpp
 Fix defect introduced 20151003T0126Z: misspelling.
 
+20151006T1248Z <address@hidden> [474]
+
+  path_utility_test.cpp
+Demonstrate a latent problem.
+
+20151006T1302Z <address@hidden> [474]
+
+  path_utility.cpp
+  path_utility.hpp
+  path_utility_test.cpp
+Remove the problem identified 20151006T1248Z.
+
+20151006T1309Z <address@hidden> [474]
+
+  ihs_avdebug.cpp
+Remove code that became truly superfluous 20151006T1302Z.
+
+20151006T1313Z <address@hidden> [474]
+
+  census_document.cpp
+Improve documentation.
+
+20151006T1326Z <address@hidden> [474]
+
+  main_cgi.cpp
+  main_cli.cpp
+Supply a nonempty name to illustrator::operator().
+
+20151006T1517Z <address@hidden> [474]
+
+  emit_ledger.cpp
+  emit_ledger.hpp
+  gpt_server.cpp
+  illustration_view.cpp
+  mec_server.cpp
+Use unique_filepath() for all PDF and spreadsheet output.
+

Modified: lmi/trunk/emit_ledger.cpp
===================================================================
--- lmi/trunk/emit_ledger.cpp   2015-10-06 13:26:42 UTC (rev 6322)
+++ lmi/trunk/emit_ledger.cpp   2015-10-06 15:17:19 UTC (rev 6323)
@@ -28,6 +28,7 @@
 
 #include "emit_ledger.hpp"
 
+#include "assert_lmi.hpp"
 #include "configurable_settings.hpp"
 #include "custom_io_0.hpp"
 #include "custom_io_1.hpp"
@@ -37,12 +38,12 @@
 #include "ledger_text_formats.hpp"
 #include "ledger_xsl.hpp"
 #include "miscellany.hpp"               // ios_out_trunc_binary()
+#include "path_utility.hpp"             // unique_filepath()
 #include "timer.hpp"
 
-#include <boost/filesystem/convenience.hpp>
+#include <boost/filesystem/convenience.hpp> // change_extension()
 #include <boost/filesystem/fstream.hpp>
 
-#include <cstdio>                       // std::remove()
 #include <iostream>
 #include <string>
 
@@ -55,9 +56,15 @@
     (fs::path const& case_filepath
     ,mcenum_emission emission
     )
-    :case_filepath_ (case_filepath)
-    ,emission_      (emission)
-{}
+    :case_filepath_              (case_filepath)
+    ,tsv_ext_                    
(configurable_settings::instance().spreadsheet_file_extension())
+    ,case_filepath_spreadsheet_  (unique_filepath(case_filepath,             
tsv_ext_))
+    ,case_filepath_group_roster_ (unique_filepath(case_filepath, ".roster" + 
tsv_ext_))
+    ,case_filepath_group_quote_  (unique_filepath(case_filepath, ".quote.pdf"  
      ))
+    ,emission_                   (emission)
+{
+    LMI_ASSERT(!case_filepath_.empty());
+}
 
 ledger_emitter::~ledger_emitter()
 {}
@@ -68,31 +75,12 @@
 {
     Timer timer;
 
-    if(emission_ & mce_emit_spreadsheet)
-        {
-        LMI_ASSERT(!case_filepath_.empty());
-        std::string spreadsheet_filename =
-                case_filepath_.string()
-            +   configurable_settings::instance().spreadsheet_file_extension()
-            ;
-        std::remove(spreadsheet_filename.c_str());
-        }
     if(emission_ & mce_emit_group_roster)
         {
-        LMI_ASSERT(!case_filepath_.empty());
-        std::string spreadsheet_filename =
-                case_filepath_.string()
-            +   ".roster"
-            +   configurable_settings::instance().spreadsheet_file_extension()
-            ;
-        std::remove(spreadsheet_filename.c_str());
-        PrintRosterHeaders(spreadsheet_filename);
+        PrintRosterHeaders(case_filepath_group_roster_.string());
         }
     if(emission_ & mce_emit_group_quote)
         {
-        LMI_ASSERT(!case_filepath_.empty());
-        std::string const pdf_filename = case_filepath_.string() + 
".quote.pdf";
-        std::remove(pdf_filename.c_str());
         group_quote_gen_ = group_quote_pdf_generator::create();
         }
 
@@ -136,22 +124,11 @@
         }
     if(emission_ & mce_emit_spreadsheet)
         {
-        LMI_ASSERT(!case_filepath_.empty());
-        PrintCellTabDelimited
-            (ledger
-            ,   case_filepath_.string()
-            +   configurable_settings::instance().spreadsheet_file_extension()
-            );
+        PrintCellTabDelimited(ledger, case_filepath_spreadsheet_.string());
         }
     if(emission_ & mce_emit_group_roster)
         {
-        LMI_ASSERT(!case_filepath_.empty());
-        PrintRosterTabDelimited
-            (ledger
-            ,   case_filepath_.string()
-            +   ".roster"
-            +   configurable_settings::instance().spreadsheet_file_extension()
-            );
+        PrintRosterTabDelimited(ledger, case_filepath_group_roster_.string());
         }
     if(emission_ & mce_emit_group_quote)
         {
@@ -194,9 +171,7 @@
 
     if(emission_ & mce_emit_group_quote)
         {
-        LMI_ASSERT(!case_filepath_.empty());
-        std::string const pdf_filename = case_filepath_.string() + 
".quote.pdf";
-        group_quote_gen_->save(pdf_filename);
+        group_quote_gen_->save(case_filepath_group_quote_.string());
         }
 
     return timer.stop().elapsed_seconds();
@@ -205,6 +180,14 @@
 /// Emit a single ledger in various guises.
 ///
 /// Return time spent, which is almost always wanted.
+///
+/// See constrain_values() for emission types not allowed on the
+/// command line.
+///
+/// Argument 'cell_filepath' is forwarded to ledger_emitter's ctor,
+/// which interprets it as a "case" rather than a "cell" filepath.
+/// Repurposing it here does no harm, and allows 'emission' to
+/// include mce_emit_spreadsheet.
 
 double emit_ledger
     (fs::path const& cell_filepath
@@ -212,7 +195,7 @@
     ,mcenum_emission emission
     )
 {
-    ledger_emitter emitter("", emission);
+    ledger_emitter emitter  (cell_filepath, emission);
     return emitter.emit_cell(cell_filepath, ledger);
 }
 

Modified: lmi/trunk/emit_ledger.hpp
===================================================================
--- lmi/trunk/emit_ledger.hpp   2015-10-06 13:26:42 UTC (rev 6322)
+++ lmi/trunk/emit_ledger.hpp   2015-10-06 15:17:19 UTC (rev 6323)
@@ -55,8 +55,12 @@
     double finish   ();
 
   private:
-    fs::path const& case_filepath_;
-    mcenum_emission emission_;
+    fs::path    const& case_filepath_;
+    std::string const  tsv_ext_;
+    fs::path    const  case_filepath_spreadsheet_;
+    fs::path    const  case_filepath_group_roster_;
+    fs::path    const  case_filepath_group_quote_;
+    mcenum_emission    emission_;
 
     // Used only if emission includes mce_emit_group_quote; empty otherwise.
     boost::shared_ptr<group_quote_pdf_generator> group_quote_gen_;

Modified: lmi/trunk/gpt_server.cpp
===================================================================
--- lmi/trunk/gpt_server.cpp    2015-10-06 13:26:42 UTC (rev 6322)
+++ lmi/trunk/gpt_server.cpp    2015-10-06 15:17:19 UTC (rev 6323)
@@ -47,7 +47,7 @@
 #include "mc_enum_types_aux.hpp"        // mc_state_from_string()
 #include "miscellany.hpp"               // ios_out_trunc_binary()
 #include "oecumenic_enumerations.hpp"
-#include "path_utility.hpp"             // fs::path inserter
+#include "path_utility.hpp"             // unique_filepath(), fs::path inserter
 #include "premium_tax.hpp"
 #include "product_data.hpp"
 #include "round_to.hpp"
@@ -56,7 +56,7 @@
 #include "timer.hpp"
 #include "value_cast.hpp"
 
-#include <boost/filesystem/convenience.hpp>
+#include <boost/filesystem/convenience.hpp> // extension(), change_extension()
 #include <boost/filesystem/fstream.hpp>
 
 #include <algorithm>                    // std::min()
@@ -451,7 +451,7 @@
 
     configurable_settings const& c = configurable_settings::instance();
     std::string const extension(".gpt" + c.spreadsheet_file_extension());
-    fs::path spreadsheet_filename = fs::change_extension(file_path, extension);
+    fs::path spreadsheet_filename = unique_filepath(file_path, extension);
     fs::ofstream ofs(spreadsheet_filename, ios_out_trunc_binary());
     ofs << "This temporary output file will be removed in a future release.\n";
     ofs

Modified: lmi/trunk/illustration_view.cpp
===================================================================
--- lmi/trunk/illustration_view.cpp     2015-10-06 13:26:42 UTC (rev 6322)
+++ lmi/trunk/illustration_view.cpp     2015-10-06 15:17:19 UTC (rev 6323)
@@ -53,6 +53,7 @@
 #include "istream_to_string.hpp"
 #include "ledger.hpp"
 #include "ledger_text_formats.hpp"
+#include "path_utility.hpp"             // unique_filepath()
 #include "safely_dereference_as.hpp"
 #include "timer.hpp"
 #include "wx_new.hpp"
@@ -63,7 +64,6 @@
 #include <wx/menu.h>
 #include <wx/xrc/xmlres.h>
 
-#include <cstdio>                       // std::remove()
 #include <fstream>
 #include <string>
 
@@ -201,16 +201,25 @@
     return has_view_been_created;
 }
 
+/// Place full illustration data on the clipboard as TSV.
+///
+/// Because this is implemented by calling PrintCellTabDelimited(), it
+/// has the occasionally desirable side effect of writing a TSV file.
+///
+/// The implementation might alternatively call
+///   emit_ledger(base_filename(), *ledger_values_, mce_emit_spreadsheet);
+/// which constructs a suitable filename, calling unique_filepath() if
+/// necessary; but if that filename needed to be made "unique", then
+/// it would be unavailable here for copying to the clipboard.
+
 void IllustrationView::UponCopyFull(wxCommandEvent&)
 {
     LMI_ASSERT(ledger_values_.get());
     Timer timer;
     configurable_settings const& c = configurable_settings::instance();
-    std::string spreadsheet_filename =
-            base_filename()
-        +   c.spreadsheet_file_extension()
-        ;
-    std::remove(spreadsheet_filename.c_str());
+    std::string const b = base_filename();
+    std::string const e = c.spreadsheet_file_extension();
+    std::string spreadsheet_filename = unique_filepath(b, e).string();
     PrintCellTabDelimited(*ledger_values_, spreadsheet_filename);
     std::ifstream ifs(spreadsheet_filename.c_str());
     std::string s;

Modified: lmi/trunk/mec_server.cpp
===================================================================
--- lmi/trunk/mec_server.cpp    2015-10-06 13:26:42 UTC (rev 6322)
+++ lmi/trunk/mec_server.cpp    2015-10-06 15:17:19 UTC (rev 6323)
@@ -46,7 +46,7 @@
 #include "mec_xml_document.hpp"
 #include "miscellany.hpp"               // ios_out_trunc_binary()
 #include "oecumenic_enumerations.hpp"
-#include "path_utility.hpp"             // fs::path inserter
+#include "path_utility.hpp"             // unique_filepath(), fs::path inserter
 #include "premium_tax.hpp"
 #include "product_data.hpp"
 #include "round_to.hpp"
@@ -55,7 +55,7 @@
 #include "timer.hpp"
 #include "value_cast.hpp"
 
-#include <boost/filesystem/convenience.hpp>
+#include <boost/filesystem/convenience.hpp> // extension(), change_extension()
 #include <boost/filesystem/fstream.hpp>
 
 #include <algorithm>                    // std::min()
@@ -434,7 +434,7 @@
 
     configurable_settings const& c = configurable_settings::instance();
     std::string const extension(".mec" + c.spreadsheet_file_extension());
-    fs::path spreadsheet_filename = fs::change_extension(file_path, extension);
+    fs::path spreadsheet_filename = unique_filepath(file_path, extension);
     fs::ofstream ofs(spreadsheet_filename, ios_out_trunc_binary());
     ofs << "This temporary output file will be removed in a future release.\n";
     ofs




reply via email to

[Prev in Thread] Current Thread [Next in Thread]