Commit b365baac authored by guinux's avatar guinux

introduce pamac cli (still in dev)

parent be3e1b11
This diff is collapsed.
......@@ -18,22 +18,14 @@
*/
namespace Pamac {
public struct UpdateInfos {
public string name;
public string old_version;
public string new_version;
public string repo;
public uint64 download_size;
}
public struct TransactionSummary {
public UpdateInfos[] to_install;
public UpdateInfos[] to_upgrade;
public UpdateInfos[] to_downgrade;
public UpdateInfos[] to_reinstall;
public UpdateInfos[] to_remove;
public UpdateInfos[] to_build;
public UpdateInfos[] aur_conflicts_to_remove;
public AlpmPackage[] to_install;
public AlpmPackage[] to_upgrade;
public AlpmPackage[] to_downgrade;
public AlpmPackage[] to_reinstall;
public AlpmPackage[] to_remove;
public AURPackage[] to_build;
public AURPackage[] aur_conflicts_to_remove;
public string[] aur_pkgbases_to_build;
}
......@@ -44,7 +36,7 @@ namespace Pamac {
}
public struct ErrorInfos {
public uint errno;
public uint no;
public string message;
public string[] details;
public ErrorInfos () {
......
......@@ -34,6 +34,13 @@ common_sources = ['common.vala', 'package.vala', 'pamac_config.vala']
transaction_sources = ['transaction.vala', 'choose_provider_dialog.vala', 'transaction_sum_dialog.vala', 'progress_box.vala']
preferences_sources = ['preferences_dialog.vala', 'choose_ignorepkgs_dialog.vala']
executable('pamac',
sources: ['cli.vala', 'common.vala', 'package.vala', 'pamac_config.vala'],
dependencies: [gio, posix, math],
vala_args: [common_vala_args, '--pkg=linux'],
c_args: common_c_args,
install: true)
executable('pamac-clean-cache',
sources: ['pamac_config.vala', 'clean_cache.vala'],
dependencies: [gio],
......
......@@ -39,6 +39,7 @@ namespace Pamac {
public string long_desc;
public string repo;
public uint origin;
public uint64 size;
public string url;
public string icon;
public string screenshot;
......
This diff is collapsed.
......@@ -20,6 +20,7 @@
namespace Pamac {
[DBus (name = "org.manjaro.pamac.user")]
interface UserDaemon : Object {
public abstract void enable_appstream () throws Error;
public abstract void refresh_handle () throws Error;
public abstract string[] get_mirrors_countries () throws Error;
public abstract string get_mirrors_choosen_country () throws Error;
......@@ -68,8 +69,8 @@ namespace Pamac {
public abstract void clean_cache (uint64 keep_nb, bool only_uninstalled) throws Error;
public abstract void start_set_pkgreason (string pkgname, uint reason) throws Error;
public abstract void start_refresh (bool force) throws Error;
public abstract void start_sysupgrade_prepare (bool enable_downgrade, string[] temporary_ignorepkgs, string[] to_build) throws Error;
public abstract void start_trans_prepare (int transflags, string[] to_install, string[] to_remove, string[] to_load, string[] to_build) throws Error;
public abstract void start_sysupgrade_prepare (bool enable_downgrade, string[] temporary_ignorepkgs, string[] to_build, string[] overwrite_files) throws Error;
public abstract void start_trans_prepare (int transflags, string[] to_install, string[] to_remove, string[] to_load, string[] to_build, string[] overwrite_files) throws Error;
public abstract void choose_provider (int provider) throws Error;
public abstract TransactionSummary get_transaction_summary () throws Error;
public abstract void start_trans_commit () throws Error;
......@@ -829,7 +830,7 @@ namespace Pamac {
connecting_dbus_signals ();
try {
// this will respond with trans_prepare_finished signal
system_daemon.start_sysupgrade_prepare (enable_downgrade, temporary_ignorepkgs_, to_build_);
system_daemon.start_sysupgrade_prepare (enable_downgrade, temporary_ignorepkgs_, to_build_, {});
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
success = false;
......@@ -906,7 +907,7 @@ namespace Pamac {
void start_trans_prepare (int transflags, string[] to_install, string[] to_remove, string[] to_load, string[] to_build) {
try {
system_daemon.start_trans_prepare (transflags, to_install, to_remove, to_load, to_build);
system_daemon.start_trans_prepare (transflags, to_install, to_remove, to_load, to_build, {});
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
stop_progressbar_pulse ();
......@@ -994,11 +995,11 @@ namespace Pamac {
var iter = Gtk.TreeIter ();
if (summary.to_remove.length > 0) {
type |= Type.STANDARD;
foreach (unowned UpdateInfos infos in summary.to_remove) {
foreach (unowned AlpmPackage infos in summary.to_remove) {
transaction_summary.add (infos.name);
transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
1, infos.name,
2, infos.old_version);
2, infos.version);
}
Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
int pos = (path.get_indices ()[0]) - (summary.to_remove.length - 1);
......@@ -1007,11 +1008,11 @@ namespace Pamac {
}
if (summary.aur_conflicts_to_remove.length > 0) {
// do not add type enum because it is just infos
foreach (unowned UpdateInfos infos in summary.aur_conflicts_to_remove) {
foreach (unowned AURPackage infos in summary.aur_conflicts_to_remove) {
transaction_summary.add (infos.name);
transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
1, infos.name,
2, infos.old_version);
2, infos.version);
}
Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
int pos = (path.get_indices ()[0]) - (summary.aur_conflicts_to_remove.length - 1);
......@@ -1020,13 +1021,13 @@ namespace Pamac {
}
if (summary.to_downgrade.length > 0) {
type |= Type.STANDARD;
foreach (unowned UpdateInfos infos in summary.to_downgrade) {
foreach (unowned AlpmPackage infos in summary.to_downgrade) {
dsize += infos.download_size;
transaction_summary.add (infos.name);
transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
1, infos.name,
2, infos.new_version,
3, "(%s)".printf (infos.old_version));
2, infos.version,
3, "(%s)".printf (infos.installed_version));
}
Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
int pos = (path.get_indices ()[0]) - (summary.to_downgrade.length - 1);
......@@ -1040,12 +1041,12 @@ namespace Pamac {
to_build_queue.push_tail (name);
}
aur_pkgs_to_install = {};
foreach (unowned UpdateInfos infos in summary.to_build) {
foreach (unowned AURPackage infos in summary.to_build) {
aur_pkgs_to_install += infos.name;
transaction_summary.add (infos.name);
transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
1, infos.name,
2, infos.new_version);
2, infos.version);
}
Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
int pos = (path.get_indices ()[0]) - (summary.to_build.length - 1);
......@@ -1054,12 +1055,12 @@ namespace Pamac {
}
if (summary.to_install.length > 0) {
type |= Type.STANDARD;
foreach (unowned UpdateInfos infos in summary.to_install) {
foreach (unowned AlpmPackage infos in summary.to_install) {
dsize += infos.download_size;
transaction_summary.add (infos.name);
transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
1, infos.name,
2, infos.new_version);
2, infos.version);
}
Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
int pos = (path.get_indices ()[0]) - (summary.to_install.length - 1);
......@@ -1068,12 +1069,12 @@ namespace Pamac {
}
if (summary.to_reinstall.length > 0) {
type |= Type.STANDARD;
foreach (unowned UpdateInfos infos in summary.to_reinstall) {
foreach (unowned AlpmPackage infos in summary.to_reinstall) {
dsize += infos.download_size;
transaction_summary.add (infos.name);
transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
1, infos.name,
2, infos.old_version);
2, infos.version);
}
Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
int pos = (path.get_indices ()[0]) - (summary.to_reinstall.length - 1);
......@@ -1083,13 +1084,13 @@ namespace Pamac {
if (summary.to_upgrade.length > 0) {
type |= Type.UPDATE;
if (mode == Mode.INSTALLER) {
foreach (unowned UpdateInfos infos in summary.to_upgrade) {
foreach (unowned AlpmPackage infos in summary.to_upgrade) {
dsize += infos.download_size;
transaction_summary.add (infos.name);
transaction_sum_dialog.sum_list.insert_with_values (out iter, -1,
1, infos.name,
2, infos.new_version,
3, "(%s)".printf (infos.old_version));
2, infos.version,
3, "(%s)".printf (infos.installed_version));
}
Gtk.TreePath path = transaction_sum_dialog.sum_list.get_path (iter);
int pos = (path.get_indices ()[0]) - (summary.to_upgrade.length - 1);
......@@ -1806,7 +1807,7 @@ namespace Pamac {
// if it is an authentication or a download error, database was not modified
var err = get_current_error ();
if (err.message == dgettext (null, "Authentication failed")
|| err.errno == 54) { //Alpm.Errno.EXTERNAL_DOWNLOAD
|| err.no == 54) { //Alpm.Errno.EXTERNAL_DOWNLOAD
// recover old pkgnames
foreach (unowned string name in previous_to_install) {
to_install.add (name);
......@@ -1867,6 +1868,7 @@ namespace Pamac {
if (user_daemon == null) {
try {
user_daemon = Bus.get_proxy_sync (BusType.SESSION, "org.manjaro.pamac.user", "/org/manjaro/pamac/user");
user_daemon.enable_appstream ();
} catch (Error e) {
stderr.printf ("Error: %s\n", e.message);
}
......
......@@ -121,6 +121,9 @@ namespace Pamac {
} else {
locale = "C";
}
}
public void enable_appstream () throws Error {
try {
app_store.load (As.StoreLoadFlags.APP_INFO_SYSTEM);
app_store.set_search_match (As.AppSearchMatch.PKGNAME
......@@ -418,6 +421,10 @@ namespace Pamac {
}
public async AlpmPackage[] get_installed_pkgs () throws Error {
return get_installed_pkgs_sync ();
}
public AlpmPackage[] get_installed_pkgs_sync () throws Error {
AlpmPackage[] pkgs = {};
unowned Alpm.List<unowned Alpm.Package> pkgcache = alpm_handle.localdb.pkgcache;
while (pkgcache != null) {
......@@ -472,6 +479,10 @@ namespace Pamac {
}
public async AlpmPackage[] get_foreign_pkgs () throws Error {
return get_foreign_pkgs_sync ();
}
public AlpmPackage[] get_foreign_pkgs_sync () throws Error {
AlpmPackage[] pkgs = {};
unowned Alpm.List<unowned Alpm.Package> pkgcache = alpm_handle.localdb.pkgcache;
while (pkgcache != null) {
......@@ -498,6 +509,10 @@ namespace Pamac {
}
public async AlpmPackage[] get_orphans () throws Error {
return get_orphans_sync ();
}
public AlpmPackage[] get_orphans_sync () throws Error {
AlpmPackage[] pkgs = {};
unowned Alpm.List<unowned Alpm.Package> pkgcache = alpm_handle.localdb.pkgcache;
while (pkgcache != null) {
......@@ -613,6 +628,10 @@ namespace Pamac {
}
public async AlpmPackage[] search_pkgs (string search_string) throws Error {
return search_pkgs_sync (search_string);
}
public AlpmPackage[] search_pkgs_sync (string search_string) throws Error {
AlpmPackage[] pkgs = {};
Alpm.List<unowned Alpm.Package> alpm_pkgs = search_all_dbs (search_string);
unowned Alpm.List<unowned Alpm.Package> list = alpm_pkgs;
......@@ -816,6 +835,10 @@ namespace Pamac {
}
public async AlpmPackage[] get_repo_pkgs (string repo) throws Error {
return get_repo_pkgs_sync (repo);
}
public AlpmPackage[] get_repo_pkgs_sync (string repo) throws Error {
AlpmPackage[] pkgs = {};
unowned Alpm.List<unowned Alpm.DB> syncdbs = alpm_handle.syncdbs;
while (syncdbs != null) {
......@@ -900,6 +923,10 @@ namespace Pamac {
}
public async AlpmPackage[] get_group_pkgs (string groupname) throws Error {
return get_group_pkgs_sync (groupname);
}
public AlpmPackage[] get_group_pkgs_sync (string groupname) throws Error {
AlpmPackage[] pkgs = {};
Alpm.List<unowned Alpm.Package> alpm_pkgs = group_pkgs (groupname);
unowned Alpm.List<unowned Alpm.Package> list = alpm_pkgs;
......@@ -1046,6 +1073,7 @@ namespace Pamac {
}
}
details.origin = (uint) alpm_pkg.origin;
details.size = alpm_pkg.isize;
// url can be null
if (alpm_pkg.url != null) {
url = alpm_pkg.url;
......@@ -1179,7 +1207,7 @@ namespace Pamac {
Alpm.File* file_ptr = filelist.files;
for (size_t i = 0; i < filelist.count; i++, file_ptr++) {
if (!file_ptr->name.has_suffix ("/")) {
files += "/" + file_ptr->name;
files += alpm_handle.root + file_ptr->name;
}
}
} else {
......@@ -1192,7 +1220,7 @@ namespace Pamac {
Alpm.File* file_ptr = filelist.files;
for (size_t i = 0; i < filelist.count; i++, file_ptr++) {
if (!file_ptr->name.has_suffix ("/")) {
files += "/" + file_ptr->name;
files += alpm_handle.root + file_ptr->name;
}
}
break;
......@@ -1203,6 +1231,34 @@ namespace Pamac {
return files;
}
public HashTable<string, Variant> search_files (string[] files) throws Error {
var result = new HashTable<string, Variant> (str_hash, str_equal);
unowned Alpm.List<unowned Alpm.Package> pkgcache = alpm_handle.localdb.pkgcache;
while (pkgcache != null) {
unowned Alpm.Package alpm_pkg = pkgcache.data;
string[] found = {};
unowned Alpm.FileList filelist = alpm_pkg.files;
Alpm.File* file_ptr = filelist.files;
for (size_t i = 0; i < filelist.count; i++, file_ptr++) {
foreach (string file in files) {
// exclude directory name
if (!file_ptr->name.has_suffix ("/")) {
// adding / to compare
string real_file_name = alpm_handle.root + file_ptr->name;
if (file in real_file_name) {
found += real_file_name;
}
}
}
}
if (found.length > 0) {
result.insert (alpm_pkg.name, new Variant.strv (found));
}
pkgcache.next ();
}
return result;
}
private int get_updates () {
if (repos_updates_checked && (aur_updates_checked || !check_aur_updates)) {
var updates = Updates () {
......
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