Commit f728ab06 authored by guinux's avatar guinux
Browse files

optimizations and fixes

parent 850a2d5d
......@@ -1160,8 +1160,11 @@ namespace Pamac {
max_length = prop.length;
}
}
foreach (string pkgname in pkgnames) {
var details = yield database.get_aur_pkg_details (pkgname);
var aur_pkgs = yield database.get_aur_pkgs_details (pkgnames);
var iter = HashTableIter<string, AURPackageDetails> (aur_pkgs);
unowned string pkgname;
unowned AURPackageDetails details;
while (iter.next (out pkgname, out details)) {
if (details.name == "") {
print_error (dgettext (null, "target not found: %s").printf (pkgname) + "\n");
return;
......@@ -1748,11 +1751,15 @@ namespace Pamac {
}
async void clone_build_files_real (string[] pkgnames, bool overwrite, bool recurse) {
foreach (unowned string pkgname in pkgnames) {
var aur_pkg_details = yield database.get_aur_pkg_details (pkgname);
string[] dep_to_check = {};
var aur_pkgs = yield database.get_aur_pkgs_details (pkgnames);
var iter = HashTableIter<string, AURPackageDetails> (aur_pkgs);
unowned string pkgname;
unowned AURPackageDetails aur_pkg_details;
while (iter.next (out pkgname, out aur_pkg_details)) {
if (aur_pkg_details.name == "") {
print_error (dgettext (null, "target not found: %s").printf (pkgname) + "\n");
return;
continue;
} else {
// clone build files
stdout.printf (dgettext (null, "Cloning %s build files".printf (pkgname)) + "...\n");
......@@ -1762,7 +1769,6 @@ namespace Pamac {
// error
return;
} else if (recurse) {
string[] dep_to_check = {};
var depends = new List<string> ();
foreach (unowned string depend in aur_pkg_details.depends) {
depends.append (depend);
......@@ -1783,34 +1789,30 @@ namespace Pamac {
string dep_name = database.get_alpm_dep_name (dep_string);
if (!(dep_name in already_checked_aur_dep)) {
already_checked_aur_dep.add (dep_name);
var aur_pkg = yield database.get_aur_pkg (dep_name);
if (aur_pkg.name != "") {
dep_to_check += (owned) dep_name;
}
dep_to_check += (owned) dep_name;
}
}
}
if (dep_to_check.length > 0) {
yield clone_build_files_real (dep_to_check, overwrite, recurse);
}
}
}
}
if (dep_to_check.length > 0) {
yield clone_build_files_real (dep_to_check, overwrite, recurse);
}
}
async bool check_build_pkgs () {
bool success = true;
foreach (unowned string pkgname in to_build) {
var aur_pkg = yield database.get_aur_pkg (pkgname);
var aur_pkgs = yield database.get_aur_pkgs (to_build);
var iter = HashTableIter<string, AURPackage> (aur_pkgs);
unowned string pkgname;
unowned AURPackage aur_pkg;
while (iter.next (out pkgname, out aur_pkg)) {
if (aur_pkg.name == "") {
print_error (dgettext (null, "target not found: %s").printf (pkgname) + "\n");
success = false;
}
if (!success) {
break;
return false;
}
}
return success;
return true;
}
void build_pkgs (string[] to_build) {
......
......@@ -1196,170 +1196,200 @@ namespace Pamac {
return null;
}
public async AURPackage get_aur_pkg (string pkgname) {
if (config.enable_aur) {
async void populate_aur_infos (string[] pkgnames) {
string[] names = {};
foreach (unowned string pkgname in pkgnames) {
if (!aur_infos.contains (pkgname)) {
Json.Array results = yield aur_multiinfo ({pkgname});
if (results.get_length () > 0) {
aur_infos.insert (pkgname, results.get_object_element (0));
}
names += pkgname;
}
unowned Json.Object? json_object = aur_infos.lookup (pkgname);
return new AURPackage.from_struct (initialise_aur_struct (json_object));
}
if (names.length > 0) {
Json.Array results = yield aur_multiinfo (names);
results.foreach_element ((array, index, node) => {
unowned Json.Object? json_object = node.get_object ();
aur_infos.insert (json_object.get_string_member ("Name"), json_object);
});
}
}
public async AURPackage get_aur_pkg (string pkgname) {
if (config.enable_aur) {
yield populate_aur_infos ({pkgname});
return new AURPackage.from_struct (initialise_aur_struct (aur_infos.lookup (pkgname)));
} else {
return new AURPackage ();
}
}
public async AURPackageDetails get_aur_pkg_details (string pkgname) {
public async HashTable<string, AURPackage> get_aur_pkgs (string[] pkgnames) {
var data = new HashTable<string, AURPackage> (str_hash, str_equal);
if (config.enable_aur) {
string name = "";
string version = "";
string desc = "";
double popularity = 0;
string packagebase = "";
string url = "";
string maintainer = "";
string firstsubmitted = "";
string lastmodified = "";
string outofdate = "";
int64 numvotes = 0;
string[] licenses = {};
string[] depends = {};
string[] makedepends = {};
string[] checkdepends = {};
string[] optdepends = {};
string[] provides = {};
string[] replaces = {};
string[] conflicts = {};
var details = AURPackageDetailsStruct ();
if (!aur_infos.contains (pkgname)) {
Json.Array results = yield aur_multiinfo ({pkgname});
if (results.get_length () > 0) {
aur_infos.insert (pkgname, results.get_object_element (0));
}
yield populate_aur_infos (pkgnames);
foreach (unowned string pkgname in pkgnames) {
data.insert (pkgname, new AURPackage.from_struct (initialise_aur_struct (aur_infos.lookup (pkgname))));
}
unowned Json.Object? json_object = aur_infos.lookup (pkgname);
if (json_object != null) {
// name
name = json_object.get_string_member ("Name");
// version
version = json_object.get_string_member ("Version");
// desc can be null
if (!json_object.get_null_member ("Description")) {
desc = json_object.get_string_member ("Description");
}
popularity = json_object.get_double_member ("Popularity");
// packagebase
packagebase = json_object.get_string_member ("PackageBase");
// url can be null
unowned Json.Node? node = json_object.get_member ("URL");
if (!node.is_null ()) {
url = node.get_string ();
}
// maintainer can be null
node = json_object.get_member ("Maintainer");
if (!node.is_null ()) {
maintainer = node.get_string ();
}
// firstsubmitted
GLib.Time time = GLib.Time.local ((time_t) json_object.get_int_member ("FirstSubmitted"));
firstsubmitted = time.format ("%x");
// lastmodified
time = GLib.Time.local ((time_t) json_object.get_int_member ("LastModified"));
lastmodified = time.format ("%x");
// outofdate can be null
node = json_object.get_member ("OutOfDate");
if (!node.is_null ()) {
time = GLib.Time.local ((time_t) node.get_int ());
outofdate = time.format ("%x");
}
//numvotes
numvotes = json_object.get_int_member ("NumVotes");
// licenses
node = json_object.get_member ("License");
if (!node.is_null ()) {
node.get_array ().foreach_element ((array, index, _node) => {
licenses += _node.get_string ();
});
} else {
licenses += dgettext (null, "Unknown");
}
// depends
node = json_object.get_member ("Depends");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
depends += _node.get_string ();
});
}
// optdepends
node = json_object.get_member ("OptDepends");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
optdepends += _node.get_string ();
});
}
// makedepends
node = json_object.get_member ("MakeDepends");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
makedepends += _node.get_string ();
});
}
// checkdepends
node = json_object.get_member ("CheckDepends");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
checkdepends += _node.get_string ();
});
}
// provides
node = json_object.get_member ("Provides");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
provides += _node.get_string ();
});
}
// replaces
node = json_object.get_member ("Replaces");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
replaces += _node.get_string ();
});
}
// conflicts
node = json_object.get_member ("Conflicts");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
conflicts += _node.get_string ();
});
}
}
return data;
}
AURPackageDetailsStruct initialise_aur_details_struct (Json.Object? json_object) {
string name = "";
string version = "";
string desc = "";
double popularity = 0;
string packagebase = "";
string url = "";
string maintainer = "";
string firstsubmitted = "";
string lastmodified = "";
string outofdate = "";
int64 numvotes = 0;
string[] licenses = {};
string[] depends = {};
string[] makedepends = {};
string[] checkdepends = {};
string[] optdepends = {};
string[] provides = {};
string[] replaces = {};
string[] conflicts = {};
if (json_object != null) {
// name
name = json_object.get_string_member ("Name");
// version
version = json_object.get_string_member ("Version");
// desc can be null
if (!json_object.get_null_member ("Description")) {
desc = json_object.get_string_member ("Description");
}
popularity = json_object.get_double_member ("Popularity");
// packagebase
packagebase = json_object.get_string_member ("PackageBase");
// url can be null
unowned Json.Node? node = json_object.get_member ("URL");
if (!node.is_null ()) {
url = node.get_string ();
}
// maintainer can be null
node = json_object.get_member ("Maintainer");
if (!node.is_null ()) {
maintainer = node.get_string ();
}
// firstsubmitted
GLib.Time time = GLib.Time.local ((time_t) json_object.get_int_member ("FirstSubmitted"));
firstsubmitted = time.format ("%x");
// lastmodified
time = GLib.Time.local ((time_t) json_object.get_int_member ("LastModified"));
lastmodified = time.format ("%x");
// outofdate can be null
node = json_object.get_member ("OutOfDate");
if (!node.is_null ()) {
time = GLib.Time.local ((time_t) node.get_int ());
outofdate = time.format ("%x");
}
//numvotes
numvotes = json_object.get_int_member ("NumVotes");
// licenses
node = json_object.get_member ("License");
if (!node.is_null ()) {
node.get_array ().foreach_element ((array, index, _node) => {
licenses += _node.get_string ();
});
} else {
licenses += dgettext (null, "Unknown");
}
// depends
node = json_object.get_member ("Depends");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
depends += _node.get_string ();
});
}
// optdepends
node = json_object.get_member ("OptDepends");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
optdepends += _node.get_string ();
});
}
// makedepends
node = json_object.get_member ("MakeDepends");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
makedepends += _node.get_string ();
});
}
// checkdepends
node = json_object.get_member ("CheckDepends");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
checkdepends += _node.get_string ();
});
}
// provides
node = json_object.get_member ("Provides");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
provides += _node.get_string ();
});
}
// replaces
node = json_object.get_member ("Replaces");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
replaces += _node.get_string ();
});
}
// conflicts
node = json_object.get_member ("Conflicts");
if (node != null) {
node.get_array ().foreach_element ((array, index, _node) => {
conflicts += _node.get_string ();
});
}
details.name = (owned) name;
details.version = (owned) version ;
details.desc = (owned) desc;
details.popularity = popularity;
details.packagebase = (owned) packagebase;
details.url = (owned) url;
details.maintainer = (owned) maintainer ;
details.firstsubmitted = (owned) firstsubmitted;
details.lastmodified = (owned) lastmodified;
details.outofdate = (owned) outofdate;
details.numvotes = numvotes;
details.licenses = (owned) licenses;
details.depends = (owned) depends;
details.optdepends = (owned) optdepends;
details.checkdepends = (owned) checkdepends;
details.makedepends = (owned) makedepends;
details.provides = (owned) provides;
details.replaces = (owned) replaces;
details.conflicts = (owned) conflicts;
return new AURPackageDetails.from_struct (details);
}
var details = AURPackageDetailsStruct ();
details.name = (owned) name;
details.version = (owned) version ;
details.desc = (owned) desc;
details.popularity = popularity;
details.packagebase = (owned) packagebase;
details.url = (owned) url;
details.maintainer = (owned) maintainer ;
details.firstsubmitted = (owned) firstsubmitted;
details.lastmodified = (owned) lastmodified;
details.outofdate = (owned) outofdate;
details.numvotes = numvotes;
details.licenses = (owned) licenses;
details.depends = (owned) depends;
details.optdepends = (owned) optdepends;
details.checkdepends = (owned) checkdepends;
details.makedepends = (owned) makedepends;
details.provides = (owned) provides;
details.replaces = (owned) replaces;
details.conflicts = (owned) conflicts;
return details;
}
public async AURPackageDetails get_aur_pkg_details (string pkgname) {
if (config.enable_aur) {
yield populate_aur_infos ({pkgname});
return new AURPackageDetails.from_struct (initialise_aur_details_struct (aur_infos.lookup (pkgname)));
} else {
return new AURPackageDetails ();
}
}
public async HashTable<string, AURPackageDetails> get_aur_pkgs_details (string[] pkgnames) {
var data = new HashTable<string, AURPackageDetails> (str_hash, str_equal);
if (config.enable_aur) {
yield populate_aur_infos (pkgnames);
foreach (unowned string pkgname in pkgnames) {
data.insert (pkgname, new AURPackageDetails.from_struct (initialise_aur_details_struct (aur_infos.lookup (pkgname))));
}
}
return data;
}
public async List<AURPackage> get_aur_updates () {
// get local pkgs
string[] local_pkgs = {};
......
......@@ -136,9 +136,15 @@ namespace Pamac {
}
int width = get_term_width () - action.char_count () - 1;
string current_status = "[%s]".printf (status);
current_line = "%s %*s".printf (action, width, current_status);
stdout.printf (current_line);
stdout.printf ("\r");
if (width > current_status.length) {
current_line = "%s %*s".printf (action, width, current_status);
stdout.printf (current_line);
stdout.printf ("\r");
} else {
current_line = "%s %s".printf (action, current_status);
stdout.printf (current_line);
stdout.printf ("\n");
}
}
stdout.flush ();
}
......
......@@ -267,7 +267,6 @@ namespace Pamac {
&& summary.to_upgrade.length () > 0) {
return true;
}
summary_shown = true;
int response = show_summary (summary);
if (response == Gtk.ResponseType.OK) {
// Commit
......@@ -690,7 +689,6 @@ namespace Pamac {
} else {
warning_textbuffer = new StringBuilder ();
}
summary_shown = false;
transaction_summary.remove_all ();
reset_progress_box ();
show_in_term ("");
......
......@@ -371,13 +371,17 @@ namespace Pamac {
async bool check_aur_dep_list (string[] pkgnames) {
string[] dep_to_check = {};
var aur_pkgs = new HashTable<string, AURPackage> (str_hash, str_equal);
if (clone_build_files) {
aur_pkgs = yield database.get_aur_pkgs (pkgnames);
}
foreach (unowned string pkgname in pkgnames) {
if (build_cancellable.is_cancelled ()) {
return false;
}
File? clone_dir;
if (clone_build_files) {
var aur_pkg = yield database.get_aur_pkg (pkgname);
unowned AURPackage aur_pkg = aur_pkgs.lookup (pkgname);
if (aur_pkg.name == "") {
emit_error (dgettext (null, "target not found: %s").printf (pkgname), {});
return false;
......@@ -398,6 +402,9 @@ namespace Pamac {
}
yield regenerate_srcinfo (pkgname);
}
if (build_cancellable.is_cancelled ()) {
return false;
}
emit_action (dgettext (null, "Checking %s dependencies".printf (pkgname)) + "...");
var srcinfo = clone_dir.get_child (".SRCINFO");
try {
......@@ -555,10 +562,7 @@ namespace Pamac {
string dep_name = database.get_alpm_dep_name (dep_string);
if (!(dep_name in already_checked_aur_dep)) {
already_checked_aur_dep.add (dep_name);
var aur_pkg = yield database.get_aur_pkg (dep_name);
if (aur_pkg.name != "") {
dep_to_check += (owned) dep_name;
}
dep_to_check += (owned) dep_name;
}
}
}
......@@ -1209,6 +1213,8 @@ namespace Pamac {
finish_transaction (true);
//handle_error (err);
}
} else if (build_cancellable.is_cancelled ()) {
finish_transaction (false);
} else if (to_build.length > 0) {
check_aur_unresolvables_and_edit_build_files.begin ();
} else {
......@@ -1278,7 +1284,6 @@ namespace Pamac {
void on_trans_commit_finished (bool success) {
if (success) {
if (to_build_queue.get_length () != 0) {
emit_script_output ("");
get_authorization_finished.connect (launch_build_next_aur_package);
start_get_authorization ();
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment