Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Action information methods

  • Loading branch information...
commit 5343fff06a18b73ff63f93dce04b9e534624e9d9 1 parent 0271231
Bahadır Kandemir authored
Showing with 35 additions and 51 deletions.
  1. +5 −2 polkit.py
  2. +26 −35 pypolkit.c
  3. +4 −14 test.py
View
7 polkit.py
@@ -53,7 +53,7 @@ def action_list():
returns :
A list() of action_ids
"""
- return _polkit.action_list()
+ return [x["action_id"] for x in _polkit.action_list()]
def action_info(action_id):
"""
@@ -65,7 +65,10 @@ def action_info(action_id):
returns :
A dict() of details about action_id
"""
- return _polkit.action_info(action_id)
+ for act in _polkit.action_list():
+ if act["action_id"] == action_id:
+ return act
+ return {}
def auth_list_uid(uid):
"""
View
61 pypolkit.c
@@ -57,51 +57,43 @@ pk_action_list(PyObject *self, PyObject *args)
glist = polkit_authority_enumerate_actions_sync(authority, NULL, &error);
for (gitem = glist; gitem; gitem = g_list_next(gitem)) {
gpointer data = gitem->data;
- PyList_Append(py_list, PyString_FromString(polkit_action_description_get_action_id(data)));
- }
-
- // g_list_free(glist);
- // g_list_free(gitem);
+ PyObject *py_dict = PyDict_New();
+ // ID
+ dict_set_unless_null(py_dict, "action_id", polkit_action_description_get_action_id(data));
- return py_list;
-}
+ // Description
+ dict_set_unless_null(py_dict, "description", polkit_action_description_get_description(data));
-//! Returns action details
-static PyObject *
-pk_action_info(PyObject *self, PyObject *args)
-{
- const char* action_id;
- if (!PyArg_ParseTuple(args, "s", &action_id)) {
- return NULL;
- }
+ // Message
+ dict_set_unless_null(py_dict, "message", polkit_action_description_get_message(data));
- PyObject *dict = PyDict_New();
+ // Vendor
+ dict_set_unless_null(py_dict, "vendor", polkit_action_description_get_vendor_name(data));
- // Description
- dict_set_unless_null(dict, "description", NULL);
+ // Vendor URL
+ dict_set_unless_null(py_dict, "vendor_url", polkit_action_description_get_vendor_url(data));
- // Message
- dict_set_unless_null(dict, "message", NULL);
+ // Icon
+ dict_set_unless_null(py_dict, "icon", polkit_action_description_get_icon_name(data));
- // Vendor
- dict_set_unless_null(dict, "vendor", NULL);
+ // Annotations
+ PyObject *py_list2 = PyList_New(0);
+ PyDict_SetItemString(py_dict, "annotations", py_list2);
- // Vendor URL
- dict_set_unless_null(dict, "vendor_url", NULL);
+ // Default policy
+ PyDict_SetItemString(py_dict, "policy_any", PyString_FromString(polkit_implicit_authorization_to_string(polkit_action_description_get_implicit_any(data))));
+ PyDict_SetItemString(py_dict, "policy_active", PyString_FromString(polkit_implicit_authorization_to_string(polkit_action_description_get_implicit_active(data))));
+ PyDict_SetItemString(py_dict, "policy_inactive", PyString_FromString(polkit_implicit_authorization_to_string(polkit_action_description_get_implicit_inactive(data))));
- // Icon
- dict_set_unless_null(dict, "icon", NULL);
- // Annotations
- PyObject *list = PyList_New(0);
- PyDict_SetItemString(dict, "annotations", list);
+ PyList_Append(py_list, py_dict);
+ g_object_unref(data);
+ }
- // Default policy
- PyDict_SetItemString(dict, "policy_any", NULL);
- PyDict_SetItemString(dict, "policy_active", NULL);
- PyDict_SetItemString(dict, "policy_inactive", NULL);
+ g_list_free(glist);
+ g_list_free(gitem);
- return dict;
+ return py_list;
}
//! Returns granted authorizations
@@ -190,7 +182,6 @@ pk_auth_block(PyObject *self, PyObject *args)
//! polkit methods
static PyMethodDef polkit_methods[] = {
{"action_list", (PyCFunction) pk_action_list, METH_NOARGS, "Lists all actions."},
- {"action_info", (PyCFunction) pk_action_info, METH_VARARGS, "Get action details."},
{"auth_list_uid", (PyCFunction) pk_auth_list_uid, METH_VARARGS, "List granted authorizations for specified UID."},
{"auth_list_all", (PyCFunction) pk_auth_list_all, METH_NOARGS, "List granted authorizations."},
{"auth_add", (PyCFunction) pk_auth_add, METH_VARARGS, "Authorize user for the given action."},
View
18 test.py
@@ -1,17 +1,7 @@
import polkit
import os
-action_ids = ("org.freedesktop.hal.device-access.camera", "org.freedesktop.hal.storage.mount-fixed")
-
-for a in action_ids:
- print a, polkit.check_auth(os.getpid(), a)
-
-print "= " * 20
-print action_ids, polkit.check_auth(os.getpid(), *action_ids)
-print "= " * 20
-print action_ids, polkit.check_authv(os.getpid(), action_ids)
-print "= " * 20
-print "org.freedesktop.hal.device-access.camera", polkit.check_auth(os.getpid(), "org.freedesktop.hal.device-access.camera")
-print "= " * 20
-
-print polkit.auth_obtain("org.freedesktop.hal.storage.mount-fixed", 0, os.getpid())
+for action_id in polkit.action_list():
+ print action_id
+ print polkit.action_info(action_id)
+ print "= " * 20
Please sign in to comment.
Something went wrong with that request. Please try again.