Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
pidgin emerge plugin
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
LinuxRulz
n00b
n00b


Joined: 27 Apr 2004
Posts: 4
Location: Carnada(without the R)

PostPosted: Sun Mar 16, 2008 5:50 am    Post subject: pidgin emerge plugin Reply with quote

A friend of mine thought of it while compiling, but I did it before him, and now here is the code: The pidgin "currently compiling" plugin. Assuming you are in the portage group, it will scan /var/log/emerge.log and add a status message titled GENTOO saying which package you're currently compiling. It's not really useful, but I found the concept to be amusing.

Code:

//author Simon Poirier <simpoir AT hotmail DOT com>
//file: pidgin_gentoo.c
//compile with: gcc -shared -o pidgin_gentoo.so pidgin_gentoo.c $(pkg-config --cflags --libs pidgin)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
#define PURPLE_PLUGINS

#include <glib.h>

#include <pthread.h>
#include <string.h>

#include "notify.h"
#include "plugin.h"
#include "version.h"
#include "savedstatuses.h"
#include "status.h"


void set_savedstatus(const char* message);
char get_currentCompile();
static void *stupidloop(void* unused);
static gboolean plugin_unload(PurplePlugin* plugin);


char currentCompile[100];
pthread_t thread;
char threadrun = TRUE;

static gboolean
plugin_load(PurplePlugin *plugin) {
    pthread_create(&thread, NULL, stupidloop, NULL);
    //purple_notify_message(plugin, PURPLE_NOTIFY_MSG_INFO, "pidgin gentoo",
    //                        "hello", NULL, NULL, NULL);

    return TRUE;
}

static PurplePluginInfo info = {
    PURPLE_PLUGIN_MAGIC,
    PURPLE_MAJOR_VERSION,
    PURPLE_MINOR_VERSION,
    PURPLE_PLUGIN_STANDARD,
    NULL,
    0,
    NULL,
    PURPLE_PRIORITY_DEFAULT,

    "core-pigin_gentoo",
    "Pidgin Emerge",
    "0.1",

    "pidgin gentoo",
    "This is a plugin to update status to package currently building",
    "Simon Poirier <simpoir@hotmail.com>",
    "http://nowebsite.nodomain",

    plugin_load,
    plugin_unload,
    NULL,
   
    NULL,
    NULL,
    NULL,
    NULL,

    NULL,
    NULL,
    NULL,
    NULL
};

static void
init_plugin(PurplePlugin *plugin)
{
}

static gboolean
plugin_unload(PurplePlugin* plugin)
{
    threadrun = FALSE;
    pthread_join(thread, NULL);
    return TRUE;
}

void
set_savedstatus(const char* message)
{
    PurpleSavedStatus* savedStatus = NULL;
    PurpleSavedStatus* currentSavedStatus = purple_savedstatus_get_current();
    savedStatus = purple_savedstatus_find("GENTOO");
    //create new status if no gentoo status exists
    if (!savedStatus)
    {
        savedStatus = purple_savedstatus_new("GENTOO", purple_savedstatus_get_type(currentSavedStatus));
    }

    //fill status with emerge state
    if (strcmp("GENTOO", purple_savedstatus_get_title(currentSavedStatus)))
    {
        //set new status same type as current
        purple_savedstatus_set_type(savedStatus, purple_savedstatus_get_type(currentSavedStatus));
    }
    purple_savedstatus_set_message(savedStatus, message);
}

static void
*stupidloop(void* unused)
{
    while (TRUE)
    {
        char msg[1024];
        int i;

        get_currentCompile();
        strcpy(msg, "GENTOO building: ");
        strcat(msg, currentCompile);
        purple_debug_info("core-pigin_gentoo", "new status %s\n", msg);
        set_savedstatus(msg);

        // 30 second refresh should be good for compilation
        for (i=0; i<30; ++i)
        {
            if (!threadrun)
                break;
            sleep(1);
        }
    }
}

char
get_currentCompile()
{
    FILE* logfile = NULL;
    char line[1024] = "";
    char* readptr = NULL;
    char gotdata = FALSE;
    char emergedone = FALSE;
    char* readend = NULL;

    logfile = fopen("/var/log/emerge.log", "r");
    if (logfile == NULL) return;

    // fetch end of emerge log
    fseek(logfile, -1024, SEEK_END);
    fread(line, 1024, 1, logfile);
    readptr = line;
    readend = line+1024;
   
    while (readptr!=readend)
    {
        // look for build
        if (!strncmp(readptr, ">>> emerge", 10))
        {
            int matched = 0;
            matched = sscanf(readptr, ">>> emerge (%*i of %*i) %s", currentCompile);
            if (matched)
            {
                emergedone = FALSE;
            }
        }
        // also look for en of compilation
        else if (!strncmp(readptr, "*** terminating", 15))
        {
            emergedone = FALSE;
            strcpy(currentCompile, "nothing! :D");
        }
        ++readptr;
    }

    fclose(logfile);
    return emergedone;
}

PURPLE_INIT_PLUGIN(pidgin_emerge, init_plugin, info)

Back to top
View user's profile Send private message
MichaelMH
n00b
n00b


Joined: 09 Jun 2007
Posts: 12
Location: Isle of Man (but originally from UK)

PostPosted: Sun Mar 16, 2008 6:12 am    Post subject: Reply with quote

:lol: you stole your friends idea? I think that sort of info is better suited for conky but gj.
Back to top
View user's profile Send private message
LinuxRulz
n00b
n00b


Joined: 27 Apr 2004
Posts: 4
Location: Carnada(without the R)

PostPosted: Sun Mar 16, 2008 6:35 am    Post subject: Reply with quote

MichaelMH wrote:
:lol: you stole your friends idea? I think that sort of info is better suited for conky but gj.

let's call it a concurrent implementation :D
Back to top
View user's profile Send private message
nixnut
Bodhisattva
Bodhisattva


Joined: 09 Apr 2004
Posts: 10974
Location: the dutch mountains

PostPosted: Sun Mar 16, 2008 8:10 am    Post subject: Reply with quote

Code:
logfile = fopen("/var/log/emerge.log", "r");
hardcoded paths are usually a bad thing. Can't you make that a plugin configuration option?

nice idea btw 8)
_________________
Please add [solved] to the initial post's subject line if you feel your problem is resolved. Help answer the unanswered

talk is cheap. supply exceeds demand
Back to top
View user's profile Send private message
sikick
n00b
n00b


Joined: 16 Mar 2008
Posts: 1

PostPosted: Sun Mar 16, 2008 5:23 pm    Post subject: Reply with quote

MichaelMH wrote:
:lol: you stole your friends idea? I think that sort of info is better suited for conky but gj.


He did steal my Idea, but I must admit his C implementation is a lot better than my bash/python dbus scripting code. Good job Simon!
Back to top
View user's profile Send private message
LinuxRulz
n00b
n00b


Joined: 27 Apr 2004
Posts: 4
Location: Carnada(without the R)

PostPosted: Sun Mar 16, 2008 7:00 pm    Post subject: Reply with quote

I added configuration menu and fixed some issues.
I also made it available on google code, so it'll be better than copy-pasting code from a forum... even if it's gentoo forum :wink:
You can get it from http://code.google.com/p/pidgin-gentoo/.
Back to top
View user's profile Send private message
seqizz
Tux's lil' helper
Tux's lil' helper


Joined: 14 Jan 2008
Posts: 103

PostPosted: Sun Mar 16, 2008 11:56 pm    Post subject: :\ Reply with quote

What'a idea!! :twisted:
Back to top
View user's profile Send private message
mark_alec
Bodhisattva
Bodhisattva


Joined: 11 Sep 2004
Posts: 6066
Location: Melbourne, Australia

PostPosted: Mon Mar 17, 2008 7:57 am    Post subject: Reply with quote

Moved from Gentoo Chat to Unsupported Software.
_________________
www.gentoo.org.au || #gentoo-au
Back to top
View user's profile Send private message
Genewb
Apprentice
Apprentice


Joined: 09 Jan 2007
Posts: 165

PostPosted: Mon Mar 17, 2008 3:45 pm    Post subject: Reply with quote

A novel idea, unfortunately:

Quote:
$ make
gcc -shared -o pidgin_gentoo.so pidgin_gentoo.c `pkg-config --cflags pidgin` `pkg-config --libs pidgin`
/usr/lib/gcc/x86_64-pc-linux-gnu/4.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccm4TWIf.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/tmp/ccm4TWIf.o: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [all] Error 1

Does that mean pidgin itself needs to be PIC, or does it mean that it won't build for x86_64?
_________________
I don't give a darn about "experience", just functional copyleft software.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum