Ejemplo n.º 1
0
static PyObject* pyalpm_trans_commit(PyObject *self, PyObject *args) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  alpm_list_t *data = NULL;
  int ret;
  enum _alpm_errno_t err;
  PyObject *err_info = NULL;

  ret = alpm_trans_commit(handle, &data);
  if (ret == 0) Py_RETURN_NONE;
  if (ret != -1) {
    PyErr_Format(PyExc_RuntimeError,
        "unexpected return value %d from alpm_trans_commit()", ret);
    return NULL;
  }

  err = alpm_errno(handle);
  switch(err) {
    case ALPM_ERR_FILE_CONFLICTS:
      /* return the list of file conflicts in the exception */
      err_info = alpmlist_to_pylist(data, pyobject_from_pmfileconflict);
      break;
    case ALPM_ERR_PKG_INVALID:
    case ALPM_ERR_PKG_INVALID_CHECKSUM:
    case ALPM_ERR_PKG_INVALID_SIG:
    case ALPM_ERR_DLT_INVALID:
      err_info = alpmlist_to_pylist(data, pyobject_from_string);
      break;
    default:
      break;
  }
  if (err_info)
    RET_ERR_DATA("transaction failed", err, err_info, NULL);
  else
    RET_ERR("transaction failed", err, NULL);
}
Ejemplo n.º 2
0
/** Initializes a transaction
 * @param self a Handle object
 * ...
 * @return a Transaction object with the same underlying object
 */
PyObject* pyalpm_trans_init(PyObject *self, PyObject *args, PyObject *kwargs) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  PyObject *result;
  const char* keywords[] = { INDEX_FLAGS(flagnames), NULL };
  char flags[18] = "\0\0\0\0\0" /* 5 */ "\0\0\0\0\0" /* 10 */ "\0\0\0\0\0" /* 15 */ "\0\0\0";

  /* check all arguments */
  if (!PyArg_ParseTupleAndKeywords(args, kwargs,
        "|bbbbbbbbbbbbbbbbOOO", (char**)keywords,
        INDEX_FLAGS(&flags))) {
    return NULL;
  }

  /* run alpm_trans_init() */
  {
    alpm_transflag_t flag_int = 0;
    int i, ret;
    for (i = 0; i < 18; i++) {
      if (flags[i]) flag_int |= 1U << i;
    }
    ret = alpm_trans_init(handle, flag_int);
    if (ret == -1) {
      RET_ERR("transaction could not be initialized", alpm_errno(handle), NULL);
    }
  }
  result = pyalpm_transaction_from_pmhandle(handle);
  return result;
}
Ejemplo n.º 3
0
static PyObject *_get_string_attr(PyObject *self, const struct _alpm_str_getset *closure) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  const char *str = closure->getter(handle);
  if(str == NULL)
    RET_ERR("failed getting option value", alpm_errno(handle), NULL);
  return Py_BuildValue("s", str);
}
Ejemplo n.º 4
0
static PyObject *pyalpm_trans_get_remove(PyObject *self, void *closure)
{
  alpm_handle_t *handle = ALPM_HANDLE(self);
  alpm_list_t *to_remove;
  /* sanity check */
  int flags = alpm_trans_get_flags(handle);
  if (flags == -1) RET_ERR("no transaction defined", alpm_errno(handle), NULL);

  to_remove = alpm_trans_get_remove(handle);
  return alpmlist_to_pylist(to_remove, pyalpm_package_from_pmpkg);
}
Ejemplo n.º 5
0
static PyObject* pyalpm_trans_sysupgrade(PyObject *self, PyObject *args, PyObject *kwargs) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  char* keyword[] = {"downgrade", NULL};
  PyObject *downgrade;
  int do_downgrade, ret;

  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", keyword, &PyBool_Type, &downgrade))
    return NULL;

  do_downgrade = (downgrade == Py_True) ? 1 : 0;
  ret = alpm_sync_sysupgrade(handle, do_downgrade);
  if (ret == -1) RET_ERR("unable to update transaction", alpm_errno(handle), NULL);
  Py_RETURN_NONE;
}
Ejemplo n.º 6
0
static PyObject* pyalpm_trans_prepare(PyObject *self, PyObject *args) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  alpm_list_t *data;

  int ret = alpm_trans_prepare(handle, &data);
  if (ret == -1) {
    /* return the list of package conflicts in the exception */
    PyObject *info = alpmlist_to_pylist(data, pyobject_from_pmdepmissing);
    if (!info) return NULL;
    RET_ERR_DATA("transaction preparation failed", alpm_errno(handle), info, NULL);
  }

  Py_RETURN_NONE;
}
Ejemplo n.º 7
0
static PyObject *pyalpm_trans_get_flags(PyObject *self, void *closure)
{
  PyObject *result;
  alpm_handle_t *handle = ALPM_HANDLE(self);
  int flags = alpm_trans_get_flags(handle);
  int i;
  if (flags == -1) RET_ERR("no transaction defined", alpm_errno(handle), NULL);
  result = PyDict_New();
  for (i = 0; i < 18; i++) {
    if(flagnames[i])
      PyDict_SetItemString(result, flagnames[i], flags & (1 << i) ? Py_True : Py_False);
  }
  return result;
}
Ejemplo n.º 8
0
static PyObject* pyalpm_trans_remove_pkg(PyObject *self, PyObject *args) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  PyObject *pkg;
  alpm_pkg_t *pmpkg;
  int ret;

  if (!PyArg_ParseTuple(args, "O!", &AlpmPackageType, &pkg)) {
    return NULL;
  }

  pmpkg = pmpkg_from_pyalpm_pkg(pkg);
  ret = alpm_remove_pkg(handle, pmpkg);
  if (ret == -1) RET_ERR("unable to update transaction", alpm_errno(handle), NULL);
  Py_RETURN_NONE;
}
Ejemplo n.º 9
0
static PyObject* pyalpm_set_pkgreason(PyObject* self, PyObject* args) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  alpm_pkg_t *pmpkg = NULL;
  PyObject *pkg = NULL;
  alpm_pkgreason_t reason;
  int ret;
  if (!PyArg_ParseTuple(args, "O!i:set_pkgreason", &AlpmPackageType, &pkg, &reason)) {
    return NULL;
  }
  pmpkg = ALPM_PACKAGE(pkg);
  ret = alpm_pkg_set_reason(pmpkg, reason);

  if (ret == -1) RET_ERR("failed setting install reason", alpm_errno(handle), NULL);
  Py_RETURN_NONE;
}
Ejemplo n.º 10
0
static PyObject* pyalpm_register_syncdb(PyObject *self, PyObject *args) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  const char *dbname;
  alpm_db_t *result;
  int pgp_level;

  if (!PyArg_ParseTuple(args, "si", &dbname, &pgp_level)) {
    PyErr_Format(PyExc_TypeError, "%s() takes a string and an integer", __func__);
    return NULL;
  }

  result = alpm_register_syncdb(handle, dbname, pgp_level);
  if (! result) {
    PyErr_Format(alpm_error, "unable to register sync database %s", dbname);
    return NULL;
  }

  return pyalpm_db_from_pmdb(result);
}
Ejemplo n.º 11
0
static int _set_string_attr(PyObject *self, PyObject *value, const struct _alpm_str_getset *closure) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  char *path = NULL;
  int ret;
  if (PyBytes_Check(value)) {
    path = strdup(PyBytes_AS_STRING(value));
  } else if (PyUnicode_Check(value)) {
    PyObject* utf8 = PyUnicode_AsUTF8String(value);
    path = strdup(PyBytes_AS_STRING(utf8));
    Py_DECREF(utf8);
  } else {
    PyErr_SetString(PyExc_TypeError, "logfile path must be a string");
    return -1;
  }

  ret = closure->setter(handle, path);
  free(path);
  if (ret == -1) RET_ERR("failed setting option value", alpm_errno(handle), -1);
  return 0;
}
Ejemplo n.º 12
0
PyObject *pyalpm_package_load(PyObject *self, PyObject *args, PyObject *kwargs) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  char *filename;
  int check_sig = ALPM_SIG_PACKAGE_OPTIONAL;
  char *kws[] = { "path", "check_sig", NULL };
  alpm_pkg_t *result;
  AlpmPackage *pyresult;
  if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|i:load_pkg", kws, &filename, &check_sig)) {
    return NULL;
  }

  if ((alpm_pkg_load(handle, filename, 1, check_sig, &result) == -1) || !result) {
    RET_ERR("loading package failed", alpm_errno(handle), NULL);
  }

  pyresult = (AlpmPackage*)pyalpm_package_from_pmpkg(result);
  if (!pyresult) return NULL;
  pyresult->needs_free = 1;
  return (PyObject*)pyresult;
}
Ejemplo n.º 13
0
PyObject* pyalpm_trans_release(PyObject *self, PyObject *args) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  int ret = alpm_trans_release(handle);
  if (ret == -1) RET_ERR("unable to release transaction", alpm_errno(handle), NULL);
  Py_RETURN_NONE;
}
Ejemplo n.º 14
0
static PyObject* pyalpm_get_syncdbs(PyObject *self, PyObject *dummy) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  return alpmlist_to_pylist(alpm_get_syncdbs(handle),
			    pyalpm_db_from_pmdb);
}
Ejemplo n.º 15
0
static PyObject* pyalpm_get_localdb(PyObject *self, PyObject *dummy) {
  alpm_handle_t *handle = ALPM_HANDLE(self);
  return pyalpm_db_from_pmdb(alpm_get_localdb(handle));
}