Some enhancements to package manager

- So not update macros while installing: avoids
  transient error messages
- Offer to autorun macros also after package
  update (so far only on package new installation)
This commit is contained in:
Matthias Koefferlein 2023-09-05 00:35:49 +02:00
parent 3a6fecc71d
commit 12f9ad33f4
6 changed files with 85 additions and 27 deletions

View File

@ -385,9 +385,9 @@ MacroController::sync_implicit_macros (bool ask_before_autorun)
} else {
// determine the paths currently in use
std::map<std::string, const ExternalPathDescriptor *> prev_folders_by_path;
std::map<std::string, ExternalPathDescriptor> prev_folders_by_path;
for (std::vector<ExternalPathDescriptor>::const_iterator p = m_external_paths.begin (); p != m_external_paths.end (); ++p) {
prev_folders_by_path.insert (std::make_pair (p->path, p.operator-> ()));
prev_folders_by_path.insert (std::make_pair (p->path, *p));
}
// gets the external paths (tech, packages) into m_external_paths
@ -433,23 +433,39 @@ MacroController::sync_implicit_macros (bool ask_before_autorun)
for (std::vector<ExternalPathDescriptor>::const_iterator p = m_external_paths.begin (); p != m_external_paths.end (); ++p) {
if (prev_folders_by_path.find (p->path) != prev_folders_by_path.end ()) {
continue;
}
auto pf = prev_folders_by_path.find (p->path);
if (pf != prev_folders_by_path.end ()) {
if (tl::verbosity () >= 20) {
tl::info << "Adding macro folder " << p->path << ", category '" << p->cat << "' for '" << p->description << "'";
}
if (pf->second.version != p->version) {
// Add the folder. Note: it may happen that a macro folder for the tech specific macros already exists in
// a non-tech context.
// In that case, the add_folder method will return 0.
if (tl::verbosity () >= 20) {
tl::info << "New version (" << p->version << " vs. " << pf->second.version << ") of macro folder " << p->path << ", category '" << p->cat << "' for '" << p->description << "'";
}
lym::MacroCollection *mc = lym::MacroCollection::root ().folder_by_name (p->path);
if (mc) {
new_folders.push_back (mc);
}
}
} else {
if (tl::verbosity () >= 20) {
tl::info << "Adding macro folder " << p->path << ", category '" << p->cat << "' for '" << p->description << "'";
}
// Add the folder. Note: it may happen that a macro folder for the tech specific macros already exists in
// a non-tech context.
// In that case, the add_folder method will return 0.
// TODO: is it wise to make this writeable?
lym::MacroCollection *mc = lym::MacroCollection::root ().add_folder (p->description, p->path, p->cat, p->readonly);
if (mc) {
mc->set_virtual_mode (p->type);
new_folders.push_back (mc);
}
// TODO: is it wise to make this writeable?
lym::MacroCollection *mc = lym::MacroCollection::root ().add_folder (p->description, p->path, p->cat, p->readonly);
if (mc) {
mc->set_virtual_mode (p->type);
new_folders.push_back (mc);
}
}
@ -565,7 +581,7 @@ MacroController::sync_macro_sources ()
if (*f != macro_categories () [c].name) {
description += " - " + tl::to_string (tr ("%1 branch").arg (tl::to_qstring (*f)));
}
external_paths.push_back (ExternalPathDescriptor (tl::to_string (macro_dir.path ()), description, macro_categories () [c].name, lym::MacroCollection::SaltFolder, g->is_readonly ()));
external_paths.push_back (ExternalPathDescriptor (tl::to_string (macro_dir.path ()), description, macro_categories () [c].name, lym::MacroCollection::SaltFolder, g->is_readonly (), g->version ()));
}

View File

@ -204,8 +204,8 @@ private:
*/
struct ExternalPathDescriptor
{
ExternalPathDescriptor (const std::string &_path, const std::string &_description, const std::string &_cat, lym::MacroCollection::FolderType _type, bool _readonly)
: path (_path), description (_description), cat (_cat), type (_type), readonly (_readonly)
ExternalPathDescriptor (const std::string &_path, const std::string &_description, const std::string &_cat, lym::MacroCollection::FolderType _type, bool _readonly, const std::string &_version = std::string ())
: path (_path), description (_description), cat (_cat), type (_type), version (_version), readonly (_readonly)
{
// .. nothing yet ..
}
@ -214,6 +214,7 @@ private:
std::string description;
std::string cat;
lym::MacroCollection::FolderType type;
std::string version;
bool readonly;
};

View File

@ -26,6 +26,7 @@
#include "layConfig.h"
#include "layMainWindow.h"
#include "layQtTools.h"
#include "layBusy.h"
#include "tlLog.h"
#include <QDir>
@ -138,11 +139,12 @@ SaltController::show_editor ()
lay::restore_dialog_state (mp_salt_dialog, s);
}
// while running the dialog, don't watch file events - that would interfere with
// the changes applied by the dialog itself.
m_file_watcher->enable (false);
mp_salt_dialog->exec ();
m_file_watcher->enable (true);
{
// while running the dialog, don't watch file events - that would interfere with
// the changes applied by the dialog itself.
lay::BusySection busy_section; // disable file watcher
mp_salt_dialog->exec ();
}
mp_plugin_root->config_set (cfg_salt_manager_window_state, lay::save_dialog_state (mp_salt_dialog));
@ -154,13 +156,13 @@ SaltController::show_editor ()
void
SaltController::sync_file_watcher ()
{
lay::BusySection busy_section; // disable file watcher
if (m_file_watcher) {
m_file_watcher->clear ();
m_file_watcher->enable (false);
for (lay::Salt::flat_iterator g = m_salt.begin_flat (); g != m_salt.end_flat (); ++g) {
m_file_watcher->add_file ((*g)->path ());
}
m_file_watcher->enable (true);
}
}
@ -216,7 +218,18 @@ SaltController::install_packages (const std::vector<std::string> &packages, bool
manager.compute_packages (m_salt, salt_mine);
}
return manager.execute (0, m_salt);
bool result = false;
{
// while running the dialog, don't watch file events - that would interfere with
// the changes applied by the dialog itself.
lay::BusySection busy_section; // disable file watcher
result = manager.execute (0, m_salt);
}
sync_file_watcher ();
return result;
}
void

View File

@ -24,6 +24,7 @@
#include "layBusy.h"
#include "tlThreads.h"
#include "tlFileSystemWatcher.h"
namespace lay
{
@ -61,6 +62,9 @@ BusySection::BusySection ()
m_previous_mode = mp_busy_mode->is_busy ();
mp_busy_mode->enter_busy_mode (true);
}
// disable file system watchers during busy periods
tl::FileSystemWatcher::global_enable (false);
}
BusySection::~BusySection ()
@ -70,6 +74,8 @@ BusySection::~BusySection ()
mp_busy_mode->enter_busy_mode (m_previous_mode);
}
mp_busy_mode = 0;
tl::FileSystemWatcher::global_enable (true);
}
bool

View File

@ -31,6 +31,9 @@
namespace tl
{
// The global enable counter (<0: disable)
static int s_global_enable = 0;
// The maximum allowed processing time in seconds
const double processing_time = 0.02;
@ -47,6 +50,16 @@ FileSystemWatcher::FileSystemWatcher (QObject *parent)
m_batch_size = 1000;
}
void
FileSystemWatcher::global_enable (bool en)
{
if (en) {
++s_global_enable;
} else {
--s_global_enable;
}
}
void
FileSystemWatcher::enable (bool en)
{
@ -120,6 +133,10 @@ FileSystemWatcher::remove_file (const std::string &path)
void
FileSystemWatcher::timeout ()
{
if (s_global_enable < 0) {
return;
}
tl::Clock start = tl::Clock::current ();
if (m_iter == m_files.end ()) {

View File

@ -57,6 +57,11 @@ public:
*/
FileSystemWatcher (QObject *parent = 0);
/**
* @brief Global enable/disable
*/
static void global_enable (bool en);
/**
* @brief Enables or disables the file watcher
*/