summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--geneticone/__init__.py1
-rw-r--r--geneticone/gui/main.py22
-rw-r--r--obsolete/geneticthread.c62
-rw-r--r--setup.py8
4 files changed, 80 insertions, 13 deletions
diff --git a/geneticone/__init__.py b/geneticone/__init__.py
index 0a160a3..b1ec682 100644
--- a/geneticone/__init__.py
+++ b/geneticone/__init__.py
@@ -18,4 +18,3 @@ vartree = gentoolkit.vartree
# import our packages
from helper import *
from package import *
-import modules
diff --git a/geneticone/gui/main.py b/geneticone/gui/main.py
index eb7f74d..dc980b6 100644
--- a/geneticone/gui/main.py
+++ b/geneticone/gui/main.py
@@ -1,19 +1,25 @@
#!/usr/bin/python
+# our backend stuff
import geneticone
-from geneticone.modules import geneticthread
+# gtk stuff
import pygtk
pygtk.require("2.0")
import gtk
+import gobject
# for doing emerge
from subprocess import *
+# threading
+from threading import Thread
+
# for the terminal
import pty
import vte
+# other
from portage_util import unique_array
class EmergeQueue:
@@ -56,9 +62,10 @@ class EmergeQueue:
if self.unmergeIt: # update tree
self.tree.append(self.unmergeIt, [sth])
- def __emerge(self):
- self.process.wait()
- for p in self.ps:
+ def update_packages(self, process, packages):
+ """This updates the packages-list. It simply removes all affected categories so they have to be rebuilt."""
+ process.wait()
+ for p in packages:
try:
cat = geneticone.split_package_name(p)[0]
while cat[0] in ["=",">","<","!"]:
@@ -73,9 +80,8 @@ class EmergeQueue:
"""Calls emerge and updates the terminal."""
(master, slave) = pty.openpty()
self.console.set_pty(master)
- self.process = Popen(["/usr/bin/python","/usr/bin/emerge"]+options+packages, stdout = slave, stderr = STDOUT, shell = False)
- self.ps = packages
- geneticthread.thread_start(self.__emerge)
+ process = Popen(["/usr/bin/python","/usr/bin/emerge"]+options+packages, stdout = slave, stderr = STDOUT, shell = False)
+ Thread(target=self.update_packages, args=(process, packages).start()
self.remove_all(it)
def emerge (self, force = False):
@@ -94,7 +100,6 @@ class EmergeQueue:
"""Unmerges everything in the umerge-queue. If force is 'False' (default) only "emerge -pv -C" is called."""
if len(self.unmergequeue) == 0: return
- #list = " ".join(self.unmergequeue)
list = self.unmergequeue[:]
s = ["-C"]
if not force: s = ["-Cpv"]
@@ -614,6 +619,7 @@ class MainWindow:
def main (self):
"""Main."""
+ gobject.threads_init()
gtk.main()
def blocked_dialog (blocked, blocks):
diff --git a/obsolete/geneticthread.c b/obsolete/geneticthread.c
new file mode 100644
index 0000000..33520a6
--- /dev/null
+++ b/obsolete/geneticthread.c
@@ -0,0 +1,62 @@
+/*
+ * This is a python module implementing real threads.
+ */
+#include <Python.h>
+#include <pthread.h>
+
+/**
+ * Callback for the thread. Just calls the argument's python function.
+ */
+static void * thread_cb (void * arg)
+{
+ PyObject * arglist;
+
+ arglist = Py_BuildValue("()",NULL);
+ PyEval_CallObject((PyObject*)arg, arglist);
+ Py_DECREF(arglist);
+ Py_DECREF((PyObject*)arg);
+
+ return NULL;
+}
+
+/**
+ * Function called from the python application.
+ */
+static PyObject * thread_start (PyObject * self, PyObject *args)
+{
+ PyObject *temp;
+ pthread_t ID;
+
+ if (PyArg_ParseTuple(args, "O:thread_start", &temp)) // get argument
+ {
+ if (!PyCallable_Check(temp)) // not callable
+ {
+ PyErr_SetString(PyExc_TypeError, "parameter must be callable");
+ return NULL;
+ }
+ Py_INCREF(temp); /* Add a reference to new callback */
+ int status = pthread_create(&ID, NULL, thread_cb, (void*) temp);
+ if (status)
+ {
+ PyErr_SetString(PyExc_SystemError, "error during thread start");
+ return NULL;
+ }
+ }
+
+ Py_RETURN_NONE;
+}
+
+static PyMethodDef ThreadMethods[] = {
+ {"thread_start", thread_start, METH_VARARGS,
+ "Start a new thread."},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+/**
+ * Init function.
+ */
+PyMODINIT_FUNC
+initgeneticthread(void)
+{
+ (void) Py_InitModule("geneticthread", ThreadMethods);
+}
diff --git a/setup.py b/setup.py
index a6a5290..b7612c0 100644
--- a/setup.py
+++ b/setup.py
@@ -2,12 +2,12 @@
from distutils.core import setup, Extension
-thread = Extension("geneticone.modules.geneticthread", sources=["geneticone/modules/geneticthread.c"])
+#thread = Extension("geneticone.modules.geneticthread", sources=["geneticone/modules/geneticthread.c"])
setup(name="Genetic/One",
- version="0.1-alpha",
+ version="SVN",
author="Necoro d.M. et.al.",
author_email="geneticone@projects.necoro.net",
- packages=["geneticone", "geneticone.gui", "geneticone.modules"],
- ext_modules=[thread]
+ packages=["geneticone", "geneticone.gui"],
+ #ext_modules=[thread]
)