public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <brian.dolbec@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/layman:master commit in: src/
Date: Wed,  5 Oct 2011 20:56:52 +0000 (UTC)	[thread overview]
Message-ID: <2e6f2b74e2c1c66afcadc67af1df1b112ba15cdb.dol-sen@gentoo> (raw)

commit:     2e6f2b74e2c1c66afcadc67af1df1b112ba15cdb
Author:     Detlev Casanova <detlev.casanova <AT> gmail <DOT> com>
AuthorDate: Thu Jul 15 14:11:49 2010 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Thu Jul 15 14:11:49 2010 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=2e6f2b74

Fix a warning in Dict
Add a method to get info for a list of overlays

---
 src/dict.c       |    6 +----
 src/dict.h       |    2 +-
 src/laymanapi.c  |   71 ++++++++++++++++++++++++++++++++++++++++++++----------
 src/laymanapi.h  |   16 ++----------
 src/stringlist.c |    2 +-
 src/tester.c     |   17 +++++++------
 6 files changed, 73 insertions(+), 41 deletions(-)

diff --git a/src/dict.c b/src/dict.c
index a818a69..0deebe9 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -46,7 +46,7 @@ unsigned int dictCount(Dict *list)
 	return (list ? list->count : 0);
 }
 
-void dictFree(Dict *list, int deref)
+void dictFree(Dict *list)
 {
 	if (!list)
 		return;
@@ -56,10 +56,6 @@ void dictFree(Dict *list, int deref)
 	{
 		DictElem *tmp = node;
 		node = node->next;
-		/*if (deref)
-		{
-			Py_DECREF(tmp->object);
-		}*/
 		free(tmp);
 	}
 

diff --git a/src/dict.h b/src/dict.h
index 844963c..47dd957 100644
--- a/src/dict.h
+++ b/src/dict.h
@@ -7,7 +7,7 @@ typedef struct Dict Dict;
 
 Dict*		dictCreate();
 //char*		tableFind(Dict *table, char* key);
-void		dictFree(Dict *t, int);
+void		dictFree(Dict *t);
 void		dictInsert(Dict* list, const char* key, const char* value);
 unsigned int	dictCount(Dict *table);
 PyObject*	dictToPyDict(Dict *dict);

diff --git a/src/laymanapi.c b/src/laymanapi.c
index 7620869..5de0140 100644
--- a/src/laymanapi.c
+++ b/src/laymanapi.c
@@ -11,12 +11,6 @@ struct LaymanAPI
 	PyObject *object;
 };
 
-OverlayInfo strToInfo(const char* str)
-{
-	OverlayInfo ret;
-	return ret;
-}
-
 LaymanAPI* laymanAPICreate(BareConfig* config, int report_error, int output)
 {
 	PyObject *obj = executeFunction("layman.api", "LaymanAPI", "Oii", _bareConfigObject(config), report_error, output);
@@ -41,11 +35,6 @@ StringList* laymanAPIGetAvailable(LaymanAPI* l, int reload)
 	return ret;
 }
 
-/*StringList* laymanAPIGetInstalled(LaymanAPI* l)
-{
-	return laymanAPIGetInstalled(l, 0);
-}*/
-
 StringList* laymanAPIGetInstalled(LaymanAPI* l, int reload)
 {
 	if (!l || !l->object)
@@ -97,13 +86,69 @@ int laymanAPIFetchRemoteList(LaymanAPI* l)
 	return ret;
 }
 
+int laymanAPIGetInfoList(LaymanAPI* l, StringList* overlays, OverlayInfo* results)
+{
+	if (!l || !l->object || !overlays || !results)
+		return 0;
+
+	PyObject *list = cListToPyList(overlays);
+	
+	PyObject *obj = PyObject_CallMethod(l->object, "get_info", "(O)", list);
+	Py_DECREF(list);
+
+	if (!obj || !PyDict_Check(obj))
+	{
+		if (obj)
+		{
+			Py_DECREF(obj);
+		}
+		return 0;
+	}
+
+	PyObject *name, *tuple;
+	Py_ssize_t i = 0;
+
+	int k = 0;
+
+	while (PyDict_Next(obj, &i, &name, &tuple))
+	{
+		if (!tuple || !PyTuple_Check(tuple))
+		{
+			Py_DECREF(obj);
+			continue;
+		}
+
+		PyObject *text = PyTuple_GetItem(tuple, 0);
+		PyObject *official = PyTuple_GetItem(tuple, 1);
+		PyObject *supported = PyTuple_GetItem(tuple, 2);
+
+		if (!PyString_Check(text) || !PyString_Check(name))
+			continue;
+
+		char* tmp = PyString_AsString(name);
+		results[k].name = malloc((strlen(tmp) + 1) * sizeof(char));
+		strcpy(results[k].name, tmp);
+
+		tmp = PyString_AsString(text);
+		results[k].text = malloc((strlen(tmp) + 1) * sizeof(char));
+		strcpy(results[k].text, tmp);
+
+		results[k].official = PyObject_IsTrue(official);
+		results[k].supported = PyObject_IsTrue(supported);
+		k++;
+	}
+
+	Py_DECREF(obj);
+	return k;
+}
+
 OverlayInfo *laymanAPIGetInfo(LaymanAPI* l, const char* overlay)
 {
 	if (!l || !l->object || !overlay)
 		return NULL;
 
 	PyObject *list = PyList_New(1);
-	PyList_SetItem(list, 0, PyBytes_FromString(overlay));
+	PyList_SetItem(list, 0, PyString_FromString(overlay));
 
 	PyObject *obj = PyObject_CallMethod(l->object, "get_info", "(O)", list);
 	Py_DECREF(list);
@@ -136,7 +181,7 @@ OverlayInfo *laymanAPIGetInfo(LaymanAPI* l, const char* overlay)
 
 	OverlayInfo *oi = malloc(sizeof(OverlayInfo));
 
-	char* tmp = PyBytes_AsString(text);
+	char* tmp = PyString_AsString(text);
 	oi->text = malloc((strlen(tmp) + 1) * sizeof(char));
 	strcpy(oi->text, tmp);
 

diff --git a/src/laymanapi.h b/src/laymanapi.h
index 0a38169..43f99e2 100644
--- a/src/laymanapi.h
+++ b/src/laymanapi.h
@@ -6,31 +6,21 @@
 
 typedef struct LaymanAPI LaymanAPI;
 
-typedef enum OverlayType {Svn = 0, Git, Bzr} OverlayType;
-typedef enum OverlayQuality {Experimental = 0, Stable, Testing} OverlayQuality;
 typedef struct OverlayInfo
 {
+	char *name;
 	char *text;
-	/*char *name;
-	char *source;
-	char *contact;
-	OverlayType type;
-	int priority;
-	OverlayQuality quality;
-	char *description;
-	char *link;
-	char *feed;*/
 	int official;
 	int supported;
 } OverlayInfo;
 
-
 LaymanAPI*	laymanAPICreate(BareConfig*, int, int);
 StringList*	laymanAPIGetAvailable(LaymanAPI*, int reload);
 StringList*	laymanAPIGetInstalled(LaymanAPI*, int reload);
 int		laymanAPISync(LaymanAPI* l, const char* overlay, int verbose);
 int 		laymanAPIFetchRemoteList(LaymanAPI*);
-OverlayInfo	*laymanAPIGetInfo(LaymanAPI* l, const char* overlay);
+int		laymanAPIGetInfoList(LaymanAPI* l, StringList* overlays, OverlayInfo* results);
+OverlayInfo*	laymanAPIGetInfo(LaymanAPI* l, const char* overlay);
 void		laymanAPIFree(LaymanAPI*);
 
 #endif

diff --git a/src/stringlist.c b/src/stringlist.c
index 7944564..96762a1 100644
--- a/src/stringlist.c
+++ b/src/stringlist.c
@@ -68,7 +68,7 @@ PyObject* cListToPyList(StringList* list)
 	PyObject *ret = PyList_New(list->count);
 	for(unsigned int i = 0; i < list->count; i++)
 	{
-		PyList_Append(ret, PyBytes_FromString(list->list[i]));
+		PyList_SetItem(ret, i, PyBytes_FromString(list->list[i]));
 	}
 
 	return ret;

diff --git a/src/tester.c b/src/tester.c
index 1d31407..61497a7 100644
--- a/src/tester.c
+++ b/src/tester.c
@@ -36,19 +36,20 @@ int main(int argc, char *argv[])
 	printf("\n");
 
 	unsigned int len = stringListCount(strs);
-	for (unsigned int i = 0; i < len; i++)
+	OverlayInfo *infos = malloc(sizeof(OverlayInfo) * len);
+	int count = laymanAPIGetInfoList(l, strs, infos);
+	
+	for (unsigned int i = 0; i < count; i++)
 	{
-		OverlayInfo *info = laymanAPIGetInfo(l, stringListGetAt(strs, i));
-		if (!info)
-			continue;
-		printf("%s\n", info->text);
-		free(info->text);
-		free(info);
+		printf("%s\n", infos[i].text);
+		free(infos[i].text);
+		free(infos[i].name);
 	}
 
 	printf("\n");
 
-finish:
+	free(infos);
+
 	bareConfigFree(cfg);
 	laymanAPIFree(l);
 	stringListFree(strs);



             reply	other threads:[~2011-10-05 20:58 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-05 20:56 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-10-05 20:56 [gentoo-commits] proj/layman:master commit in: src/ Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2e6f2b74e2c1c66afcadc67af1df1b112ba15cdb.dol-sen@gentoo \
    --to=brian.dolbec@gmail.com \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox