mirror of https://github.com/Gnucash/gnucash
This library intends to wrap Finance::Quote the way price-quotes.scm currently does. In this first commit the library replaces price-quotes.scm's library to install quote sources. In addition it exposes a new command line parameter in gnucash-cli to show which version of Finance::Quote is installed on the system (if any) and which quotes sources that verions exposes.pull/892/head
parent
b0ae402c23
commit
2f7ed7f25d
@ -0,0 +1,90 @@
|
||||
/********************************************************************\
|
||||
* gnc-quotes.hpp -- proxy for Finance::Quote *
|
||||
* Copyright (C) 2021 Geert Janssens <geert@kobaltwit.be> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\ *******************************************************************/
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/process.hpp>
|
||||
#include <glib.h>
|
||||
#include "gnc-quotes.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include "gnc-path.h"
|
||||
}
|
||||
|
||||
namespace bp = boost::process;
|
||||
|
||||
static GncQuotes quotes_cached;
|
||||
|
||||
bool
|
||||
GncQuotes::check (void)
|
||||
{
|
||||
m_version.clear();
|
||||
m_sources.clear();
|
||||
m_error_msg.clear();
|
||||
m_cmd_result = 0;
|
||||
|
||||
auto perl_executable = bp::search_path("perl"); //or get it from somewhere else.
|
||||
auto fq_check = std::string(gnc_path_get_bindir()) + "/gnc-fq-check";
|
||||
|
||||
bp::ipstream out_stream;
|
||||
bp::ipstream err_stream;
|
||||
bp::child process (perl_executable, "-w", fq_check, bp::std_out > out_stream, bp::std_err > err_stream);
|
||||
|
||||
std::string stream_line;
|
||||
while (getline (out_stream, stream_line))
|
||||
if (m_version.empty())
|
||||
m_version = stream_line;
|
||||
else
|
||||
m_sources.push_back (stream_line);
|
||||
while (getline (err_stream, stream_line))
|
||||
m_error_msg.append(stream_line + "\n");
|
||||
|
||||
process.wait();
|
||||
m_cmd_result = process.exit_code();
|
||||
|
||||
auto success = (m_cmd_result == 0);
|
||||
|
||||
if (success)
|
||||
std::sort (m_sources.begin(), m_sources.end());
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
GList*
|
||||
GncQuotes::sources_as_glist()
|
||||
{
|
||||
GList* slist = nullptr;
|
||||
for (auto source : m_sources)
|
||||
slist = g_list_append (slist, g_strdup(source.c_str()));
|
||||
return slist;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GncQuotes&
|
||||
gnc_get_quotes_instance (void)
|
||||
{
|
||||
return quotes_cached;
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
/********************************************************************\
|
||||
* gnc-quotes.hpp -- proxy for Finance::Quote *
|
||||
* Copyright (C) 2021 Geert Janssens <geert@kobaltwit.be> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
#ifndef GNC_QUOTES_HPP
|
||||
#define GNC_QUOTES_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
extern "C" {
|
||||
#include <glib.h>
|
||||
}
|
||||
|
||||
class GncQuotes
|
||||
{
|
||||
public:
|
||||
bool check (void);
|
||||
|
||||
// Constructor - check for presence of Finance::Quote and import version and quote sources
|
||||
GncQuotes() { check(); }
|
||||
|
||||
// Function to check if Finance::Quote is properly installed
|
||||
int cmd_result() { return m_cmd_result; }
|
||||
std::string error_msg() { return m_error_msg; }
|
||||
std::string version() { return m_version.empty() ? "Not Found" : m_version; }
|
||||
std::vector <std::string> sources() { return m_sources; }
|
||||
GList* sources_as_glist ();
|
||||
private:
|
||||
std::string m_version;
|
||||
std::vector <std::string> m_sources;
|
||||
int m_cmd_result;
|
||||
std::string m_error_msg;
|
||||
};
|
||||
|
||||
GncQuotes& gnc_get_quotes_instance (void);
|
||||
|
||||
#endif /* GNC_QUOTES_HPP */
|
||||
Loading…
Reference in new issue