mirror of https://github.com/KLayout/klayout.git
WIP: download capabilities for salt grains.
This commit is contained in:
parent
820c291623
commit
1353c9dfb0
|
|
@ -23,6 +23,7 @@
|
|||
#include "laySaltGrain.h"
|
||||
#include "tlString.h"
|
||||
#include "tlXMLParser.h"
|
||||
#include "tlHttpStream.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
|
|
@ -319,7 +320,7 @@ static tl::XMLStruct<lay::SaltGrain> xml_struct ("salt-grain",
|
|||
bool
|
||||
SaltGrain::is_readonly () const
|
||||
{
|
||||
return QFileInfo (tl::to_qstring (path ())).isWritable ();
|
||||
return !QFileInfo (tl::to_qstring (path ())).isWritable ();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -329,6 +330,13 @@ SaltGrain::load (const std::string &p)
|
|||
xml_struct.parse (source, *this);
|
||||
}
|
||||
|
||||
void
|
||||
SaltGrain::load (tl::InputStream &p)
|
||||
{
|
||||
tl::XMLStreamSource source (p);
|
||||
xml_struct.parse (source, *this);
|
||||
}
|
||||
|
||||
void
|
||||
SaltGrain::save () const
|
||||
{
|
||||
|
|
@ -353,6 +361,18 @@ SaltGrain::from_path (const std::string &path)
|
|||
return g;
|
||||
}
|
||||
|
||||
SaltGrain
|
||||
SaltGrain::from_url (const std::string &url)
|
||||
{
|
||||
tl::InputHttpStream http (SaltGrain::spec_url (url));
|
||||
tl::InputStream stream (http);
|
||||
|
||||
SaltGrain g;
|
||||
g.load (stream);
|
||||
g.set_url (url);
|
||||
return g;
|
||||
}
|
||||
|
||||
bool
|
||||
SaltGrain::is_grain (const std::string &path)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "layCommon.h"
|
||||
#include "tlObject.h"
|
||||
#include "tlStream.h"
|
||||
|
||||
#include <QTime>
|
||||
#include <QImage>
|
||||
|
|
@ -334,6 +335,11 @@ public:
|
|||
*/
|
||||
void load (const std::string &file_path);
|
||||
|
||||
/**
|
||||
* @brief Loads the data from a given stream
|
||||
*/
|
||||
void load (tl::InputStream &stream);
|
||||
|
||||
/**
|
||||
* @brief Saves the data to the path inside the grain folder given by the "path" property
|
||||
*/
|
||||
|
|
@ -370,6 +376,14 @@ public:
|
|||
*/
|
||||
static SaltGrain from_path (const std::string &path);
|
||||
|
||||
/**
|
||||
* @brief Loads the grain from the given URL
|
||||
* This method will return a grain constructed from the downloaded data.
|
||||
* The data is read from "URL/grain.xml". This method will throw an
|
||||
* exception if an error occurs during reading.
|
||||
*/
|
||||
static SaltGrain from_url (const std::string &url);
|
||||
|
||||
/**
|
||||
* @brief Forms the spec file download URL from a given download URL
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -554,14 +554,17 @@ SaltGrainPropertiesDialog::accept ()
|
|||
<< tr ("A download URL should be specified to ensure the package dependencies can be resolved.") << tl::endl
|
||||
<< tr ("If the dependency package was downloaded itself, the URL is automatically set to the download source.");
|
||||
} else {
|
||||
std::string spec_url = SaltGrain::spec_url (d->url);
|
||||
tl::InputHttpStream stream (spec_url);
|
||||
SaltGrain gdep;
|
||||
try {
|
||||
char b;
|
||||
stream.read (&b, 1);
|
||||
gdep = SaltGrain::from_url (d->url);
|
||||
if (gdep.name () != d->name) {
|
||||
dependencies_alert->error () << tr ("Package name obtained from download URL is not the expected name.") << tl::endl
|
||||
<< tr ("Downloaded name: ") << gdep.name () << tl::endl
|
||||
<< tr ("Expected name: ") << d->name;
|
||||
}
|
||||
} catch (tl::Exception &ex) {
|
||||
dependencies_alert->error () << tr ("Attempt to read download URL failed. Error details follow.") << tl::endl
|
||||
<< tr ("URL: ") << spec_url << tl::endl
|
||||
dependencies_alert->error () << tr ("Attempt to test-download package from URL failed. Error details follow.") << tl::endl
|
||||
<< tr ("URL: ") << d->url << tl::endl
|
||||
<< tr ("Message: ") << ex.msg ();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue