You are not logged in.

#51 2008-09-03 22:10:10

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Conky - update notifier in python

Boris Bolgradov wrote:

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

I'm not the author of this script but I fixed it for myself.

#!/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 = 0 
# pkg template - this is how individual pkg info is displayed ('' = disabled)
# valid keywords - %(name)s, %(repo)s, %(size).2f, %(ver)s, %(rate)s
pkgTemplate = " %(name)s"# %(ver)s"
# important pkg tempalte - same as above but for "important" pkgs
ipkgTemplate = " *!* %(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 = ""
# important summary template - same as above if "important" pkgs are found
isummaryTemplate = summaryTemplate + ""
# pkg right column template - individual pkg right column
# valid keywords - same as pkgTemplate
pkgrightcolTemplate = ""
# 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 = ""
# important summary right column template - same as above if "important" pkgs are found
isummaryrightcolTemplate = summaryrightcolTemplate
# seperator before summary ('' = disabled)
block = ''
# up to date msg
u2d = 'none'
################################################################################
 
import subprocess
import re
 
from time import sleep
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
for line in p.stdout:
    if re.match('(Cíle|Pakete|Targets|Se procesará|Cibles|Pacchetti|'
                        'Celuje|Pacotes|Цели) \(.*\):', line):
        program = line.split()[2:]  
 
        for line in p.stdout:
            if not line.strip():
                break
            program += line.split()
 
for item in program:
    pkg = {}
    desc_path = False
    desc_paths =  glob('/var/lib/pacman/sync/*/%s'%item)
 
    if not desc_path:
            desc_path = desc_paths[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 brief:
        if num_of_pkgs:
            print ',  '.join(lines[:num_of_pkgs])
        else:
            print ',  '.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:
        print summaryline
else:
    print u2d

er... I forgot I had made some other changes for myself as well, but the main part you need to change is the following block, around line 97.

#parse pacmans output
for line in p.stdout:
    if re.match('(Cíle|Pakete|Targets|Se procesará|Cibles|Pacchetti|'
                        'Celuje|Pacotes|Цели) \(.*\):', line):
        program = line.split()[2:]  
 
        for line in p.stdout:
            if not line.strip():
                break
            program += line.split()

Last edited by rson451 (2008-09-03 22:35:20)


archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#52 2008-10-19 13:20:52

jelly
Administrator
From: /dev/null
Registered: 2008-06-10
Posts: 714

Re: Conky - update notifier in python

I always get the message 'your system is up to date' even when it isnt. I think my cron rules aren't fine, what exactly do you add in cron?

Offline

#53 2008-10-19 14:22:31

Kooothor
Member
From: Paname
Registered: 2008-08-02
Posts: 228

Re: Conky - update notifier in python

jelly wrote:

I always get the message 'your system is up to date' even when it isnt. I think my cron rules aren't fine, what exactly do you add in cron?

create a file in /etc/cron.hourly/ called update.sh :

#!/bin/bash
pacman -Sy
return 0;

then make it executable :

$ chmod +x /etc/cron.hourly/update.sh

That should work smile

Last edited by Kooothor (2008-10-19 14:22:58)


ktr

Offline

#54 2008-10-19 16:36:59

BKJ
Member
Registered: 2008-09-19
Posts: 71

Re: Conky - update notifier in python

Thanks for the script.  Works great here.  Was wondering how much trouble it would be to change the script to only show the number of updates available instead of listing them.  Ex..  Currently it lists them like so: "cups, cups-lib" where in my case I would like to just see the number "2".  Being that arch is a rolling release I really don't care what packages are available I only want to know that updates are available.

Offline

#55 2009-01-18 15:07:02

na12
Member
From: /home/serbia
Registered: 2008-12-23
Posts: 752

Re: Conky - update notifier in python

When I run script in conky I get this
tMTU3bQ
and when I run in terminal I get

[15:53:56 ~]$ ./update.py
 *!* core/heimdal 1.2.1-3                    2.86 MB
 *!* core/glib2 2.18.4-1                     2.43 MB
 *!* core/pacman-mirrorlist 20090108-1       0.00 MB
 extra/gnome2-user-docs 2.24.2-1            23.79 MB
 extra/gnome-games 2.24.3-1                 19.78 MB
 extra/libgweather 2.24.3-1                 13.54 MB
 extra/gnome-applets 2.24.3.1-1             10.58 MB
                                        ------------
 42 packages (3 important 5.29 MB)         152.60 MB

width is 52 and my conkyrc

background no
#font Snap.se:size=8
#xftfont Snap.se:size=8
font Vibrocentric:size=13
use_xft yes
xftfont Vibrocentric:size=13
xftalpha 1
update_interval 3.0
total_run_times 0
own_window yes
own_window_type override
own_window_transparent yes
#own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
double_buffer yes
draw_shades no
draw_outline no
draw_borders no
draw_graph_borders no
minimum_size 700 5
maximum_width 700
default_color white
default_shade_color 000000
default_outline_color 000000
alignment top_right
gap_x 6
gap_y 6
no_buffers yes
override_utf8_locale no
uppercase no # set to yes if you want all text to be in uppercase
use_spacer no

TEXT

${font Vibrocentric:style=Bold:size=12}UPDATE NOTIFICATION${font Vibrocentric:size=10}
${texeci 6000 python ~/update.py}

what is wrong?

Last edited by na12 (2009-01-18 15:07:55)

Offline

#56 2009-01-21 20:05:47

msdark
Member
From: Chile
Registered: 2008-08-17
Posts: 49
Website

Re: Conky - update notifier in python

The scripts only show me  "Your System is up to date" .. even when is not..
I try the fix of rson451, but nothing... my system is ever up to date... wath happend?

(sorry for my english)


www.msdarkici.wordpress.com (Spanish) All what i Do in the linux world!!!
Arch User... Feel Free... Feel Speed....

Offline

#57 2009-01-21 21:04:00

na12
Member
From: /home/serbia
Registered: 2008-12-23
Posts: 752

Re: Conky - update notifier in python

try this

#!/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 = 7
#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,
        'catalyst*':7,
        }
# 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
import re

from time import sleep
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
for line in p.stdout:
    if re.match('(CÃ|Pakete|Targets|Se procesará|Cibles|Pacchetti|'
                        'Celuje|Pacotes|Цели) \(.*\):', line):
        program = line.split()[2:]  
               
        for line in p.stdout:
            if not line.strip():
                break
            program += line.split()

for item in program:
    pkg = {}
    desc_path = False
    desc_paths =  glob('/var/lib/pacman/sync/*/%s'%item)

    if not desc_path:
            desc_path = desc_paths[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

and you have to add bash script to /etc/cron.hourly

#!/bin/bash
pacman -Sy

and do chmod +x

Offline

#58 2009-01-22 18:13:36

ilovefridge
Member
Registered: 2007-04-18
Posts: 22

Re: Conky - update notifier in python

na12 wrote:

When I run script in conky I get this
http://omploader.org/tMTU3bQ
and when I run in terminal I get

stuff

what is wrong?

Try adding "text_buffer_size 512" to your conkyrc. Conky has a textbuffer which the script is overrunning, so just make it larger (I -think- the default is 128).

Btw nice program, I think will add it to my conky.

Offline

#59 2009-01-29 12:46:01

userlander
Member
Registered: 2008-08-23
Posts: 413

Re: Conky - update notifier in python

rson451 wrote:
Boris Bolgradov wrote:

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

I'm not the author of this script but I fixed it for myself.

#!/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 = 0 
# pkg template - this is how individual pkg info is displayed ('' = disabled)
# valid keywords - %(name)s, %(repo)s, %(size).2f, %(ver)s, %(rate)s
pkgTemplate = " %(name)s"# %(ver)s"
# important pkg tempalte - same as above but for "important" pkgs
ipkgTemplate = " *!* %(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 = ""
# important summary template - same as above if "important" pkgs are found
isummaryTemplate = summaryTemplate + ""
# pkg right column template - individual pkg right column
# valid keywords - same as pkgTemplate
pkgrightcolTemplate = ""
# 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 = ""
# important summary right column template - same as above if "important" pkgs are found
isummaryrightcolTemplate = summaryrightcolTemplate
# seperator before summary ('' = disabled)
block = ''
# up to date msg
u2d = 'none'
################################################################################
 
import subprocess
import re
 
from time import sleep
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
for line in p.stdout:
    if re.match('(Cíle|Pakete|Targets|Se procesará|Cibles|Pacchetti|'
                        'Celuje|Pacotes|Цели) \(.*\):', line):
        program = line.split()[2:]  
 
        for line in p.stdout:
            if not line.strip():
                break
            program += line.split()
 
for item in program:
    pkg = {}
    desc_path = False
    desc_paths =  glob('/var/lib/pacman/sync/*/%s'%item)
 
    if not desc_path:
            desc_path = desc_paths[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 brief:
        if num_of_pkgs:
            print ',  '.join(lines[:num_of_pkgs])
        else:
            print ',  '.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:
        print summaryline
else:
    print u2d

er... I forgot I had made some other changes for myself as well, but the main part you need to change is the following block, around line 97.

#parse pacmans output
for line in p.stdout:
    if re.match('(Cíle|Pakete|Targets|Se procesará|Cibles|Pacchetti|'
                        'Celuje|Pacotes|Цели) \(.*\):', line):
        program = line.split()[2:]  
 
        for line in p.stdout:
            if not line.strip():
                break
            program += line.split()

I had to use your script, too. the other one just says the system is up-to-date even when it isn't. I have pacman -Sy set to run every hour in crontab.

The problem here, though is that I get only a single line of output, with just the file names and *!* in front of them, like this:

*!* gcc, *!* man-pages, *!* gcc-libs, *!* reiserfsprogs, *!* fakeroot

I guess it has something to do with the language settings like you mentioned in line 97? but the original one doesn't give any output except "Your system is up to date," so I don't know if that's the whole problem.

Offline

#60 2009-03-16 02:54:28

John Karahalis
Member
Registered: 2009-01-27
Posts: 17

Re: Conky - update notifier in python

Hey everybody. I thought this was a great script and was very disappointed that it was not working anymore. I saw that rson451 fixed it, but he also introduced his own changes.

For anybody who is interested, here is the original (with original formatting, etc) in a working state:

#!/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
import re

from time import sleep
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
for line in p.stdout:
    if re.match('(Cíle|Pakete|Targets|Se procesará|Cibles|Pacchetti|'
                        'Celuje|Pacotes|Цели) \(.*\):', line):
        program = line.split()[2:]  
 
        for line in p.stdout:
            if not line.strip():
                break
            program += line.split()
 
for item in program:
    pkg = {}
    desc_path = False
    desc_paths =  glob('/var/lib/pacman/sync/*/%s'%item)

    if not desc_path:
            desc_path = desc_paths[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

I was able to determine the lines that needed to be changed by diffing the original with rson451's version. I don't know any python, but it seemed the problem was in lines 103-110. Feedback would be appreciated. If this works for people, maybe we could put it somewhere in a more permanent form.

Offline

#61 2009-04-29 12:15:26

ichigo
Member
Registered: 2009-03-27
Posts: 7

Re: Conky - update notifier in python

I add a color on repository (section mise à jour) wink

http://www.monsterup.com/upload/1241006163999.png

#!/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>
import re

################################################################################
# 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 = 37

# 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 + " (${color yellow}/!\ %(isize).2f Mo${color white})"
# pkg right column template - individual pkg right column
# valid keywords - same as pkgTemplate
pkgrightcolTemplate = "$alignr %(size).2f Mo"
# 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 = "$alignr${color white} Total: %(size).2f Mo${font}"
# 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 = ''
################################################################################

import subprocess
import re

from time import sleep
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
for line in p.stdout:
    if re.match('(CÃ-le|Pakete|Targets|Se procesará|Cibles|Pacchetti|'
                        'Celuje|Pacotes|Цели) \(.*\):', line):
        program = line.split()[2:]  
 
        for line in p.stdout:
            if not line.strip():
                break
            program += line.split()
 
for item in program:
    pkg = {}
    desc_path = False
    desc_paths =  glob('/var/lib/pacman/sync/*/%s'%item)

    if not desc_path:
            desc_path = desc_paths[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'] = 'Maj'
    else:
        summary['pkgstring'] = 'Majs'
    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:
                pkgString = pkgString[:width-len(sizeValueString)-1]+'...'

        line = pkgString.ljust(width - len(sizeValueString)) + sizeValueString
        line = re.sub("core/", "${color red}[Core]${color white}", line)
        line = re.sub("extra/", "${color green}[Extra]${color white}", line)
        line = re.sub("community/", "${color violet}[Community]${color white}", line)
        line = re.sub("archlinuxfr/", "${color blue}[ArchFr]${color white}", line)
        line = re.sub("testing/", "${color yellow}[Testing]${color white}", line)
        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-2000)


    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

but i have a bug. i can't display more 5 update because i have a bug of a variable

Last edited by ichigo (2009-04-29 12:16:29)

Offline

#62 2009-05-27 17:33:32

Southie75
Member
Registered: 2009-01-29
Posts: 7

Re: Conky - update notifier in python

ichigo wrote:

but i have a bug. i can't display more 5 update because i have a bug of a variable

Did you try changing this to 0 on line 14?

num_of_pkgs = 5
BKJ wrote:

Was wondering how much trouble it would be to change the script to only show the number of updates available instead of listing them.  Ex..  Currently it lists them like so: "cups, cups-lib" where in my case I would like to just see the number "2".

Did you try changing this to True on line 11?

brief = False

Offline

#63 2009-09-14 15:59:02

mitzekotze
Member
Registered: 2009-09-14
Posts: 5

Re: Conky - update notifier in python

The script isn't working right anymore. If I'm calling it, it only show me the message that my system is up to date. But there are pakages to update. I tried the last version of ichigo but it only gave me a blank line. Has somebody an idea?


Try walking in my shoes.

Offline

#64 2009-12-18 21:34:17

Szycha
Member
From: Poland, WLKP
Registered: 2008-07-03
Posts: 22

Re: Conky - update notifier in python

Refreshing this thread, i'd really like this script, but it isn't working anymore, so maybe some good samritan can repair it ? Or maybe i can find some similiar script ?

Offline

#65 2009-12-19 21:49:02

marxav
Member
From: Gatineau, PQ, Canada
Registered: 2006-09-24
Posts: 386

Re: Conky - update notifier in python

Try this. 

#!/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>
import re

################################################################################
# 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 = 37

# 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 + " (${color yellow}/!\ %(isize).2f Mo${color white})"
# pkg right column template - individual pkg right column
# valid keywords - same as pkgTemplate
pkgrightcolTemplate = "$alignr %(size).2f Mo"
# 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 = "$alignr${color white} Total: %(size).2f Mo${font}"
# 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 = ''
################################################################################

import subprocess
import re

from time import sleep
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()
 
for line in p.stdout:
    if not line.strip():
        break

    program += line.split()[0::2]
    
for item in program:
    pkg = {}
    desc_path = False
    desc_paths =  glob('/var/lib/pacman/sync/*/%s-*'%item)

    if not desc_path:
        desc_path = desc_paths[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'] = 'Maj'
    else:
        summary['pkgstring'] = 'Majs'
    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:
                pkgString = pkgString[:width-len(sizeValueString)-1]+'...'

        line = pkgString.ljust(width - len(sizeValueString)) + sizeValueString
        line = re.sub("core/", "${color red}[Core]${color white}", line)
        line = re.sub("extra/", "${color green}[Extra]${color white}", line)
        line = re.sub("community/", "${color violet}[Community]${color white}", line)
        line = re.sub("archlinuxfr/", "${color blue}[ArchFr]${color white}", line)
        line = re.sub("testing/", "${color yellow}[Testing]${color white}", line)
        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-2000)


    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

Offline

#66 2010-01-03 22:42:20

Edricson
Member
Registered: 2010-01-03
Posts: 3

Re: Conky - update notifier in python

For anyone who stumbles on this thread, marxav's script must be called with ${execpi} in conky, otherwse you just get the raw output (this is because (t)execi doesn't parse the color variables). Otherwise, thanks!

Offline

#67 2010-01-25 09:37:01

samuele.mattiuzzo
Member
From: Treviso, IT
Registered: 2009-10-12
Posts: 307
Website

Re: Conky - update notifier in python

is there a way to tell the script to print only the last line (n° of updates available, total size of download)?

Offline

#68 2010-01-25 12:17:47

vik_k
Member
From: Pune, India
Registered: 2009-07-12
Posts: 227
Website

Re: Conky - update notifier in python

just checkout the "brief" variable at the start of script.
if it's "True" then only last line is shown


"First learn computer science and all the theory. Next develop a programming style. Then forget all that and just hack." ~ George Carrette

Offline

#69 2010-01-26 16:25:10

davidm
Member
Registered: 2009-04-25
Posts: 371

Re: Conky - update notifier in python

BKJ wrote:

Thanks for the script.  Works great here.  Was wondering how much trouble it would be to change the script to only show the number of updates available instead of listing them.  Ex..  Currently it lists them like so: "cups, cups-lib" where in my case I would like to just see the number "2".  Being that arch is a rolling release I really don't care what packages are available I only want to know that updates are available.

I simply use this (not related to the script in this thread) :

#!/bin/sh

sudo pacman -Sy > /dev/null
pacman -Qu | wc -l

Make sure to allow sudo to run without a password for the given user.

It works great for me and prints 0 when there are no updates or the number when updates are available.

Offline

#70 2010-01-26 17:40:47

rson451
Member
From: Annapolis, MD USA
Registered: 2007-04-15
Posts: 1,233
Website

Re: Conky - update notifier in python

I use a simlar solution, but ignore updates for packages in IgnorePkg in pacman.conf

#!/bin/bash                   
#
# check_updates.sh
#
# CREATED:  2008-11-03 13:32
# MODIFIED: 2009-12-01 16:32
#
ignore=$(sed -r 's/^\s*IgnorePkg\s*=\s*//;tx;d;:x;s/\s+/|/g' /etc/pacman.conf)
updates=$(pacman -Qqu | grep -Ev "^$ignore$" | wc -l)

[ $updates -gt 0 ] && echo -n "  $updates update"
[ $updates -gt 1 ] && echo "s" || exit 0

archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson

Offline

#71 2010-05-04 20:08:09

clutch
Member
Registered: 2010-05-01
Posts: 48

Re: Conky - update notifier in python

Having an issue with marxav's version of the script (only one that's worked for me).

output from running conky in terminal:

[clutch@archb0x ~]$ conky
Conky: desktop window (100) is root window
Conky: window type - desktop
Conky: drawing to created window (0x600001)
Conky: drawing to double buffer
Conky: unknown variable align
Conky: unknown variable align
Conky: unknown variable align

in conky's display the last package to update says [Extra]alsa-utils 1.0....${align} and then there's nothing else after that.  I just directly copy/pasted the script, haven't made any alterations.

Anyone know what the problem might be?  I only know very very basic python.

thanks in advance

/edit  Also, I'm calling the script in .conkyrc with execpi as recommended if that makes a difference

/edit again for the benefit of future visitors to this thread:

Fixed by adding text_buffer_size 2048 to .conkyrc

Last edited by clutch (2010-05-05 13:18:59)

Offline

#72 2010-09-09 18:48:25

koral
Member
Registered: 2010-08-05
Posts: 26

Re: Conky - update notifier in python

Very nice script, works perfectly here smile , thank you !

Offline

#73 2010-11-01 15:48:51

linuxdork
Member
Registered: 2008-02-23
Posts: 3

Re: Conky - update notifier in python

I'm getting the following output when running the script:

File "./scripts/notify.py", line 186
    print separator.join(lines[:num_of_pkgs])
                  ^
SyntaxError: invalid syntax

I've tried a few versions of the script.  I get the same output.  I'm currently using the last version posted here on page 3.

Last edited by linuxdork (2010-11-01 15:49:33)

Offline

#74 2010-11-01 15:52:36

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,576

Re: Conky - update notifier in python

Did you try changing the first line of the script from

#!/usr/bin/env python

to

#!/usr/bin/env python2

Offline

#75 2010-11-01 22:22:24

linuxdork
Member
Registered: 2008-02-23
Posts: 3

Re: Conky - update notifier in python

That worked perfectly!  Thanks!  I need to learn python.  It seems very cool.

Offline

Board footer

Powered by FluxBB