You are not logged in.

#26 2008-01-19 05:34:34

ploub
Member
Registered: 2007-05-16
Posts: 128

Re: Conky - update notifier in python

It's working again for me, thanks, nice prog

Offline

#27 2008-06-04 20:55:22

Stythys
Member
From: SF Bay Area
Registered: 2008-05-18
Posts: 878
Website

Re: Conky - update notifier in python

can someone provide the changes to display the packages horizontally instead of vertically?

Last edited by Stythys (2008-06-04 20:55:59)


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol

Offline

#28 2008-06-06 21:11:52

Majkhii
Member
Registered: 2007-07-29
Posts: 53

Re: Conky - update notifier in python

Stythys wrote:

can someone provide the changes to display the packages horizontally instead of vertically?

Yes, I can...how a display of packages may be show?
package1, package2...or any your idea would be helpful smile


Proud to be ArchLinux64 user.

configs: http://github.com/Mihairu/config-files/tree/master
current desktop: here

Offline

#29 2008-06-06 21:17:30

Stythys
Member
From: SF Bay Area
Registered: 2008-05-18
Posts: 878
Website

Re: Conky - update notifier in python

well just instead of a listing like:

pkg1  32MB
pkg2  2MB
pkg3  10MB

just put it horizontally:

pkg1: 32 MB -- pkg2: 2MB -- pkg3: 10MB


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol

Offline

#30 2008-06-06 21:33:32

Majkhii
Member
Registered: 2007-07-29
Posts: 53

Re: Conky - update notifier in python

Stythys wrote:

well just instead of a listing like:

pkg1  32MB
pkg2  2MB
pkg3  10MB

just put it horizontally:

pkg1: 32 MB -- pkg2: 2MB -- pkg3: 10MB

ok...tomorrow i'll make it


Proud to be ArchLinux64 user.

configs: http://github.com/Mihairu/config-files/tree/master
current desktop: here

Offline

#31 2008-06-06 23:57:19

Stythys
Member
From: SF Bay Area
Registered: 2008-05-18
Posts: 878
Website

Re: Conky - update notifier in python

awesome. thanks big_smile


[home page] -- [code / configs]

"Once you go Arch, you must remain there for life or else Allan will track you down and break you."
-- Bregol

Offline

#32 2008-06-07 21:57:14

Majkhii
Member
Registered: 2007-07-29
Posts: 53

Re: Conky - update notifier in python

updated...if something is wrong...just write it here


Proud to be ArchLinux64 user.

configs: http://github.com/Mihairu/config-files/tree/master
current desktop: here

Offline

#33 2008-06-14 18:02:00

xdeusx
Member
Registered: 2007-10-15
Posts: 168

Re: Conky - update notifier in python

doesn't work for me unfortunately

[deus@laptop scripts]$ ./conky-update.py 
Traceback (most recent call last):
  File "./conky-update.py", line 117, in <module>
    desc_path = desc_paths[0] + '/desc'
IndexError: list index out of range
[deus@laptop scripts]$

Last edited by xdeusx (2008-06-14 18:02:11)

Offline

#34 2008-06-14 19:03:53

Majkhii
Member
Registered: 2007-07-29
Posts: 53

Re: Conky - update notifier in python

Hmm...for me works normally...i'll try to find what's wrong...


Proud to be ArchLinux64 user.

configs: http://github.com/Mihairu/config-files/tree/master
current desktop: here

Offline

#35 2008-06-17 14:03:40

qbe
Member
Registered: 2008-06-17
Posts: 8
Website

Re: Conky - update notifier in python

Same error as xdeusx

Traceback (most recent call last):
  File "/home/qbe/bin/arch-updates/conky-updates.py", line 118, in <module>
    desc_path = desc_paths[0] + '/desc'
IndexError: list index out of range

Maybe something wrong with Python/Pacman paths? I'll appreciate if you can point me to a fix smile
BTW, your script is great!


Knowledge is power.
-- Francis Bacon

Offline

#36 2008-06-18 04:27:08

sabooky
Member
Registered: 2006-11-02
Posts: 89

Re: Conky - update notifier in python

qbe wrote:

Same error as xdeusx

Traceback (most recent call last):
  File "/home/qbe/bin/arch-updates/conky-updates.py", line 118, in <module>
    desc_path = desc_paths[0] + '/desc'
IndexError: list index out of range

Maybe something wrong with Python/Pacman paths? I'll appreciate if you can point me to a fix smile
BTW, your script is great!

The problem is it's not finding the 'item' (package) in your /var/lib/pacman/sync/ directory.
can you add in this code before line 118

print item

That'll tell you what the problem package is. I'm curious to see which packages cause this problem, so we can fix it.

an easy workaround for now.
change

if not desc_path:
    desc_path = desc_paths[0] + '/desc'

to

if desc_paths:
    desc_path = desc_paths[0] + '/desc'

note that it's "desc_paths" not "desc_path"
I assume this is on line 117 for you (my version is a little bit out of sync with the one posted here)
The `if not desc_path:` is actually pointless, just never got cleaned up when changes where made to the script. (supporting different versions of pacman..etc..)
This workaround will basically ignore any package that comes up in pacman -Qu, but isn't located in /var/lib/pacman/sync/*/pkgname directory.

Again, my local version is out of sync with what's currently up right now, and the issue might be something else. Please, if you have this problem, add in the print item and show us the output. Also, once you find the problem 'item' see if it exists in your repo dir..
for example if the problem item is 'wget-1.11.3-1':

ls /var/lib/pacman/sync/*/wget-1.11.3-1

Thank you.

Offline

#37 2008-06-18 05:23:42

qbe
Member
Registered: 2008-06-17
Posts: 8
Website

Re: Conky - update notifier in python

First of all, thank you very much for your answer smile

Added:

print item

just before line 118, so then code looked like this:

   if not desc_path:
            print item
            desc_path = desc_paths[0] + '/desc'

Now:

[qbe@Elisa arch-updates]\$ ./conky-updates.py 
procesará:
Traceback (most recent call last):
  File "conky-updates.py", line 119, in <module>
    desc_path = desc_paths[0] + '/desc'
IndexError: list index out of range

so I guess no package name is showing up. Also tried to put "print item" before the "if not desc_path" line to see if something changed but it showed up the same:

procesará:

(I'm using a spanish version and "procesará" means "Targets")

So after this first try I followed your workaround. First I deleted "print item" and then changed:

if not desc_path:
    desc_path = desc_paths[0] + '/desc'

to

if desc_paths:
    desc_path = desc_paths[0] + '/desc'

and then:

[qbe@Elisa arch-updates]\$ ./python conky-updates.py
Traceback (most recent call last):
  File "conky-updates.py", line 120, in <module>
    pkg['repo'] = desc_path.split('/')[-3]
AttributeError: 'bool' object has no attribute 'split'

I've also tried adding "print item" and changing the "if" line both together but no results.

I guess I've done things right.. hmm Correct me if I'm wrong please.

Thanks again.

p.d. Sorry for my bad english big_smile

Last edited by qbe (2008-06-18 05:57:44)


Knowledge is power.
-- Francis Bacon

Offline

#38 2008-06-18 21:37:00

sabooky
Member
Registered: 2006-11-02
Posts: 89

Re: Conky - update notifier in python

Oops yea.. my work around was wrong.
Anyways, this should fix the version that's up on the main thread right now

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Description: Python script for notifying archlinux updates.
# Usage: Put shell script with command 'pacman -Sy' into /etc/cron.hourly/
# Conky: e.g. put in conky '${texeci 1800 python path/to/this/file}'
# Author: Michal Orlik <thror.fw@gmail.com>, sabooky <sabooky@yahoo.com>

################################################################################
# SETTINGS - main settings
# set this to True if you just want one summary line (True/False)
brief = False
# number of packages to display (0 = display all)
num_of_pkgs = 5
#show only important packages
onlyImportant = False
########################################

# OPTIONAL SETTINGS
# PACKAGE RATING - prioritize packages by rating
# pkgs will be sorted by rating. pkg rating = ratePkg + rateRepo for that pkg
# pkg (default=0, wildcards accepted)
ratePkg = {
        'kernel*':10,
        'pacman':9,
        'nvidia*':8,
        }
# repo (default=0, wildcards accepted)
rateRepo = {
        'core':5,
        'extra':4,
        'community':3,
        'testing':2,
        'unstable':1,
        }
# at what point is a pkg considered "important"
iThresh = 5
########################################

# OUTPUT SETINGS - configure the output format
# change width of output
width = 52

# if you would use horizontal you possibly want to disable 'block'
horizontally = False
# separator of horizontal layout
separator = ' ---'
# pkg template - this is how individual pkg info is displayed ('' = disabled)
# valid keywords - %(name)s, %(repo)s, %(size).2f, %(ver)s, %(rate)s
pkgTemplate = " %(repo)s/%(name)s %(ver)s"
# important pkg tempalte - same as above but for "important" pkgs
ipkgTemplate = " *!* %(repo)s/%(name)s %(ver)s"
# summary template - this is the summary line at the end
# valid keywords - %(numpkg)d, %(size).2f, %(inumpkg), %(isize).2f, %(pkgstring)s
summaryTemplate = " %(numpkg)d %(pkgstring)s"
# important summary template - same as above if "important" pkgs are found
isummaryTemplate = summaryTemplate + " (%(inumpkg)d important %(isize).2f MB)"
# pkg right column template - individual pkg right column
# valid keywords - same as pkgTemplate
pkgrightcolTemplate = "%(size).2f MB"
# important pkg right column template - same as above but for important pkgs
ipkgrightcolTemplate = pkgrightcolTemplate
# summary right column template - summay line right column
# valid keywords - same as summaryTemplate
summaryrightcolTemplate = "%(size).2f MB"
# important summary right column template - same as above if "important" pkgs are found
isummaryrightcolTemplate = summaryrightcolTemplate
# seperator before summary ('' = disabled)
block = '-' * 12
# up to date msg
u2d = ' Your system is up-to-date'
################################################################################

import subprocess

from glob import glob
from fnmatch import fnmatch

program = []
pkgs = []
url = None

def runpacman():
    """runs pacman returning the popen object"""
    p = subprocess.Popen(['pacman','-Qu'],
            stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    return p

def cmpPkgs(x, y):
        """Compares packages for sorting"""
        if x['rate']==y['rate']:
                return cmp(x['size'], y['size'])
        else:
                return x['rate']-y['rate']

if onlyImportant:
        pkgTemplate, pkgrightcolTemplate = '',''

p = runpacman()
# parse pacmans output
capture = False
for line in p.stdout:
    if capture:
        if not line.strip():
            break
        program += line.split()
    elif not line.strip():
        capture = True

for item in program[1:]:
    pkg = {}
    desc_path =  glob('/var/lib/pacman/sync/*/%s'%item)[0] + '/desc'

    pkg['repo'] = desc_path.split('/')[-3]
    desc = open(desc_path).readlines()
    checkName = 0
    checkSize = 0
    checkVersion = 0
    for index, line in enumerate(desc):
        if line=='%NAME%\n' and checkName == 0:
            pkgName = desc[index+1].strip()
            pkg['name'] = pkgName
            checkName = 1
        if line=='%CSIZE%\n' and checkSize == 0:
            pkgSize = int(desc[index+1].strip())
            pkg['size'] = pkgSize / 1024.0 / 1024
            checkSize = 1
        if line=='%VERSION%\n' and checkVersion == 0:
            pkgVersion = desc[index+1].strip()
            pkg['ver'] = pkgVersion
            checkVersion = 1

    pkgRate = [v for x, v  in ratePkg.iteritems()
            if fnmatch(pkg['name'], x)]
    repoRate = [v for x, v in rateRepo.iteritems()
            if fnmatch(pkg['repo'], x)]
    pkg['rate'] = sum(pkgRate + repoRate)

    pkgs.append(pkg)

# echo list of pkgs
if pkgs:
    summary = {}
    summary['numpkg'] = len(pkgs)
    summary['size'] = sum([x['size'] for x in pkgs])
    if summary['numpkg'] == 1:
        summary['pkgstring'] = 'package'
    else:
        summary['pkgstring'] = 'packages'
    summary['inumpkg'] = 0
    summary['isize'] = 0
    lines = []
    pkgs.sort(cmpPkgs, reverse=True)
    for pkg in pkgs:
        important = False

        if pkg['rate'] >= iThresh:
            summary['isize'] += pkg['size']
            summary['inumpkg'] += 1
            pkgString = ipkgTemplate % pkg
            sizeValueString = ipkgrightcolTemplate % pkg
        else:
            pkgString = pkgTemplate % pkg
            sizeValueString = pkgrightcolTemplate % pkg

        if len(pkgString)+len(sizeValueString)>width-1:
                pkgString = pkgString[:width-len(sizeValueString)-4]+'...'

        line = pkgString.ljust(width - len(sizeValueString)) + sizeValueString
        if line.strip():
            lines.append(line)

    if not horizontally:
        separator = '\n'

    if not brief:
        if num_of_pkgs:
            print separator.join(lines[:num_of_pkgs])
        else:
            print separator.join(lines)
        if block:
            print block.rjust(width)


    if summary['inumpkg']:
        overallString = isummaryTemplate % summary
        overallMBString = summaryrightcolTemplate % summary
    else:
        overallString = summaryTemplate % summary
        overallMBString = isummaryrightcolTemplate % summary
    summaryline =  overallString.ljust(width - len(overallMBString)) \
                       + overallMBString
    if summaryline and not horizontally:
        print summaryline
else:
    print u2d

NOTE: When Majkhii gets a chance and updates the frontpage I'll remove this.

Hope this works for you. This should work with all current/future languages. It'll only go bad whenever they decide to change the format of the pacman -Qu output.

PS: Majkhii, we need to start versioning this script. Give it a version number, this way we can keep track of changes and such.

PSS: I know I mentioned before that I wanted to clean up the script, I've been busy so never got around to it :\. Really some parts of the script could use a complete rewrite.. Who knows, maybe I'll have time this weekend to do it. Another reason I haven't done a rewrite is.. it works... so.. too lazy to 'fix' something that's not broken tongue.

Last edited by sabooky (2008-06-18 22:24:56)

Offline

#39 2008-06-18 22:07:39

Majkhii
Member
Registered: 2007-07-29
Posts: 53

Re: Conky - update notifier in python

I'll update the script on frontpage when qbe and xdeusx says thats ok smile


Proud to be ArchLinux64 user.

configs: http://github.com/Mihairu/config-files/tree/master
current desktop: here

Offline

#40 2008-06-18 22:17:56

xdeusx
Member
Registered: 2007-10-15
Posts: 168

Re: Conky - update notifier in python

Thanks for your help.
But I guess it didn't work.

[deus@laptop scripts]$ ./conky-update.py 
Traceback (most recent call last):
  File "./conky-update.py", line 109, in <module>
    program.pop(0)
IndexError: pop from empty list
[deus@laptop scripts]$

Now it fails when it should say "your system is up to date"

Offline

#41 2008-06-18 22:26:13

sabooky
Member
Registered: 2006-11-02
Posts: 89

Re: Conky - update notifier in python

xdeusx wrote:

Now it fails when it should say "your system is up to date"

Horray for stupid mistakes. It should be fixed now... hopefully, thanks for the quick feedback, sorry for the bad fixes..
Kinda rushing things and not really testing them.
But NOW, it hopefully works.
Same post as above, I edited it.

Last edited by sabooky (2008-06-18 22:26:37)

Offline

#42 2008-06-18 23:27:55

qbe
Member
Registered: 2008-06-17
Posts: 8
Website

Re: Conky - update notifier in python

Hey, thanks again for your quick reply. Tried your last update, but..

[qbe@Elisa arch-updates]\$ ./conky-updates.py
Traceback (most recent call last):
  File "./conky-updates.py", line 111, in <module>
    desc_path =  glob('/var/lib/pacman/sync/*/%s'%item)[0] + '/desc'
IndexError: list index out of range

If it helps you, I'm using:
Pacman v3.1.4 - libalpm v2.3.1
Python 2.5.2

Cheers smile


Knowledge is power.
-- Francis Bacon

Offline

#43 2008-06-18 23:52:07

sabooky
Member
Registered: 2006-11-02
Posts: 89

Re: Conky - update notifier in python

Interesting..can you paste the output of

pacman -Qu

Offline

#44 2008-06-19 04:34:58

qbe
Member
Registered: 2008-06-17
Posts: 8
Website

Re: Conky - update notifier in python

Yes, sure.

[qbe@Elisa ~]\$ pacman -Qu
Verificando existencia de actualizaciones de paquetes...

Se quitará: slocate  rar  perl  

Tamaño total eliminado:   39,76 MB

Se procesará: mlocate-0.18-2  unrar-3.7.8-1  perlcpan-5.8.8-3  

Tamaño total de descarga:   12,14 MB
Tamaño total instalado:   12,33 MB

Translation follows. In english this means (more or less)...

Checking packages updates...

Following packages will be removed: slocate  rar  perl

Total size: 39,76 MB

Targets: mlocate-0.18-2  unrar-3.7.8-1  perlcpan-5.8.8-3

Total downloaded size: ....
Total installed size: ....

Thanks.

Last edited by qbe (2008-06-19 04:39:44)


Knowledge is power.
-- Francis Bacon

Offline

#45 2008-06-19 05:02:58

qbe
Member
Registered: 2008-06-17
Posts: 8
Website

Re: Conky - update notifier in python

Ok, reading the output I solved the problem by adding '#' before the perlcpan repo in pacman.conf (I added it some months ago but completely forgot about it and now I don't need cpan anymore) and by running pacman -R rar, pacman -S unrar, pacman -R slocate, then pacman -R mlocate, deleted the 'slocate' group, and finally pacman -S mlocate again. After doing this, running pacman -Qu showed "no targets to update'. Then ran your script:

[qbe@Elisa arch-updates]\$ ./conky-updates.py       
 Up to date

And now it works flawlessly.
Thank you very much for your help and time. Your script is very useful. Keep up the good work!


Cheers smile

Last edited by qbe (2008-06-19 07:02:26)


Knowledge is power.
-- Francis Bacon

Offline

#46 2008-06-19 08:01:30

xdeusx
Member
Registered: 2007-10-15
Posts: 168

Re: Conky - update notifier in python

Doesn't work for me yet.

[deus@laptop ~]$ scripts/conky-update.py 
 Your system is up-to-date
[deus@laptop ~]$ sudo pacman -Sy
Password: 
:: Synchronizing package databases...
 testing                   14.3K  182.6K/s 00:00:00 [#####################] 100%
 core is up to date
 extra                    403.1K  746.0K/s 00:00:01 [#####################] 100%
 community                346.1K  746.4K/s 00:00:00 [#####################] 100%
 unstable                   5.2K  129.8K/s 00:00:00 [#####################] 100%
 kdemod-unstable           25.1K  254.4K/s 00:00:00 [#####################] 100%
 local database is up to date
[deus@laptop ~]$ scripts/conky-update.py 
Traceback (most recent call last):
  File "scripts/conky-update.py", line 111, in <module>
    desc_path =  glob('/var/lib/pacman/sync/*/%s'%item)[0] + '/desc'
IndexError: list index out of range
[deus@laptop ~]$
[deus@laptop ~]$ pacman -Qou
Checking for package upgrades... 
warning: rar-3.7.1-3: ignoring package upgrade (to be replaced by unrar-3.7.8-1)
warning: mplayer-svn: local (26516-1) is newer than testing (25449-1)
warning: sonata: local (1.5.2-1) is newer than extra (1.5.1-2)

Targets: aalib-1.4rc5-5 [0.14 MB]  gpm-1.20.5-1 [0.13 MB]  
....

Offline

#47 2008-06-19 18:55:34

sabooky
Member
Registered: 2006-11-02
Posts: 89

Re: Conky - update notifier in python

Did you change any of the defaults?

$ pacman -Qu
Checking for package upgrades... 
warning: jdk: local (6-2) is newer than extra (6u5-1)

Targets: filesystem-2008.06-2  nmap-4.65-2  

Total Download Size:    1.69 MB
Total Installed Size:   7.34 MB

My pacman -Qu doesn't show file sizes after each pkg. Using the above output it parses it just fine.

Offline

#48 2008-06-22 12:25:39

xdeusx
Member
Registered: 2007-10-15
Posts: 168

Re: Conky - update notifier in python

Yeah, I did.
I enabled ShowSize and TotalDownload in pacman.conf
Would it be possible to add support for these options?

Offline

#49 2008-08-17 19:03:41

Boris Bolgradov
Member
From: Yambol, Bulgaria
Registered: 2008-07-27
Posts: 182
Website

Re: Conky - update notifier in python

Nice script, but I have a problem. It says that my system is always up to date (and it's not)

The script:

[boris@arch ~]$ .scripts/update-notify.py 
 Your system is up-to-date
[boris@arch ~]$

Pacman:

[boris@arch ~]$ sudo pacman -Qu
Password: 
Checking for package upgrades... 
warning: conky: local (1.5.2_pre01116-1) is newer than extra (1.5.1-1)

Targets (3): libpng-1.2.29-2  tcl-8.5.4-1  tk-8.5.4-1  

Total Download Size:    0.00 MB
Total Installed Size:   11.01 MB
[boris@arch ~]$

Using:
-- pacman v3.2.0
-- libalpm v3.0.0
-- The script from the first post; The last one posted gives me the same error as xdeusx gets.

I like this script, I need a script like this. Unfortunately, I'm not good enough with python to fix this myself.
Thanks.

Offline

#50 2008-08-18 11:19:15

kazuo
Member
From: São Paulo/Brazil
Registered: 2008-03-18
Posts: 413
Website

Re: Conky - update notifier in python

Majkhii wrote:

Is there someone, who knows how to handle with colors in conky with "exec"?

Use execpi to parse colors, but I don't know why you don't have a texecpi...

Great script!

Offline

Board footer

Powered by FluxBB