summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apt/package.py9
-rw-r--r--debian/changelog6
-rw-r--r--python/apt_pkgmodule.cc60
-rw-r--r--tests/lock.py47
4 files changed, 119 insertions, 3 deletions
diff --git a/apt/package.py b/apt/package.py
index 5268b8f9..9749da52 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -214,6 +214,14 @@ class Package(object):
return ver.InstalledSize
installedSize = property(installedSize)
+ # canidate origin
+ def candidateOrigin(self):
+ ver = self._depcache.GetCandidateVer(self._pkg)
+ (VerFileIter,index) = ver.FileList.pop()
+ print len(VerFileIter)
+ print VerFileIter
+ return VerFileIter.Component
+ candidateOrigin = property(candidateOrigin)
# depcache actions
def markKeep(self):
@@ -275,6 +283,7 @@ if __name__ == "__main__":
print "Priority (Installed): %s " % pkg.installedPriority
print "Installed: %s " % pkg.installedVersion
print "Candidate: %s " % pkg.candidateVersion
+ print "CandiateOrigin: %s" % pkg.candidateOrigin
print "SourcePkg: %s " % pkg.sourcePackageName
print "Section: %s " % pkg.section
print "Summary: %s" % pkg.summary
diff --git a/debian/changelog b/debian/changelog
index d551fd7d..2ec0f488 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+python-apt (0.6.14.1) breezy; urgency=low
+
+ * export locking via: GetLock(),PkgSystem{Lock,UnLock}
+
+ --
+
python-apt (0.6.14) unstable; urgency=low
* doc/examples/build-deps.py:
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc
index 1c58316c..9a3aac37 100644
--- a/python/apt_pkgmodule.cc
+++ b/python/apt_pkgmodule.cc
@@ -114,7 +114,6 @@ static PyObject *RealParseDepends(PyObject *Self,PyObject *Args,
if (PyArg_ParseTuple(Args,"s#",&Start,&Len) == 0)
return 0;
Stop = Start + Len;
-
PyObject *List = PyList_New(0);
PyObject *LastRow = 0;
while (1)
@@ -283,6 +282,56 @@ static PyObject *InitSystem(PyObject *Self,PyObject *Args)
}
/*}}}*/
+// fileutils.cc: GetLock /*{{{*/
+// ---------------------------------------------------------------------
+static char *doc_GetLock =
+"GetLock(string) -> int\n"
+"This will create an empty file of the given name and lock it. Once this"
+" is done all other calls to GetLock in any other process will fail with"
+" -1. The return result is the fd of the file, the call should call"
+" close at some time\n";
+static PyObject *GetLock(PyObject *Self,PyObject *Args)
+{
+ const char *file;
+ char errors = false;
+ if (PyArg_ParseTuple(Args,"s|b",&file,&errors) == 0)
+ return 0;
+
+ int fd = GetLock(file, errors);
+
+ return HandleErrors(Py_BuildValue("i", fd));
+}
+
+static char *doc_PkgSystemLock =
+"PkgSystemLock() -> boolean\n"
+"Get the global pkgsystem lock\n";
+static PyObject *PkgSystemLock(PyObject *Self,PyObject *Args)
+{
+ if (PyArg_ParseTuple(Args,"") == 0)
+ return 0;
+
+ bool res = _system->Lock();
+
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_BuildValue("b", res));
+}
+
+static char *doc_PkgSystemUnLock =
+"PkgSystemUnLock() -> boolean\n"
+"Unset the global pkgsystem lock\n";
+static PyObject *PkgSystemUnLock(PyObject *Self,PyObject *Args)
+{
+ if (PyArg_ParseTuple(Args,"") == 0)
+ return 0;
+
+ bool res = _system->UnLock();
+
+ Py_INCREF(Py_None);
+ return HandleErrors(Py_BuildValue("b", res));
+}
+
+ /*}}}*/
+
// initapt_pkg - Core Module Initialization /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -298,7 +347,12 @@ static PyMethodDef methods[] =
{"ParseSection",ParseSection,METH_VARARGS,doc_ParseSection},
{"ParseTagFile",ParseTagFile,METH_VARARGS,doc_ParseTagFile},
{"RewriteSection",RewriteSection,METH_VARARGS,doc_RewriteSection},
-
+
+ // Locking
+ {"GetLock",GetLock,METH_VARARGS,doc_GetLock},
+ {"PkgSystemLock",PkgSystemLock,METH_VARARGS,doc_PkgSystemLock},
+ {"PkgSystemUnLock",PkgSystemUnLock,METH_VARARGS,doc_PkgSystemUnLock},
+
// Command line
{"ReadConfigFile",LoadConfig,METH_VARARGS,doc_LoadConfig},
{"ReadConfigFileISC",LoadConfigISC,METH_VARARGS,doc_LoadConfig},
@@ -387,7 +441,7 @@ extern "C" void initapt_pkg()
AddStr(Dict,"Date",__DATE__);
AddStr(Dict,"Time",__TIME__);
- // My constants!!
+ // My constants
AddInt(Dict,"DepDepends",pkgCache::Dep::Depends);
AddInt(Dict,"DepPreDepends",pkgCache::Dep::PreDepends);
AddInt(Dict,"DepSuggests",pkgCache::Dep::Suggests);
diff --git a/tests/lock.py b/tests/lock.py
new file mode 100644
index 00000000..5d2697f1
--- /dev/null
+++ b/tests/lock.py
@@ -0,0 +1,47 @@
+#!/usr/bin/env python2.4
+#
+# Test for the pkgCache code
+#
+
+import apt_pkg
+import sys, os
+
+
+if __name__ == "__main__":
+ lock = "/tmp/test.lck"
+
+ apt_pkg.init()
+
+ # system-lock
+ apt_pkg.PkgSystemLock()
+
+ pid = os.fork()
+ if pid == 0:
+ try:
+ apt_pkg.PkgSystemLock()
+ except SystemError, s:
+ print "Can't get lock: (error text:\n%s)" % s
+ sys.exit(0)
+
+ apt_pkg.PkgSystemUnLock()
+
+ # low-level lock
+ fd = apt_pkg.GetLock(lock,True)
+ print "Lockfile fd: %s" % fd
+
+ # try to get lock without error flag
+ pid = os.fork()
+ if pid == 0:
+ # child
+ fd = apt_pkg.GetLock(lock,False)
+ print "Lockfile fd (child): %s" % fd
+ sys.exit(0)
+
+ # try to get lock with error flag
+ pid = os.fork()
+ if pid == 0:
+ # child
+ fd = apt_pkg.GetLock(lock,True)
+ print "Lockfile fd (child): %s" % fd
+ sys.exit(0)
+