#!/usr/bin/python
##
# Project: uextras - A simple tool to manage Debian systems
# Author: Francesco Muriana <f.muriana@hotmail.it>
# Copyright: 2010-2011 Francesco Muriana
# License: GPL-2+
# 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; either version 2 of the License, or (at your option)
# any later version.
#
# 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.
#
# On Debian GNU/Linux systems, the full text of the GNU General Public License
# can be found in the file /usr/share/common-licenses/GPL-2.
##
import os, os.path, sys, gzip
import gtk, gtk.glade, pygtk, gettext
from gettext import gettext as _
class ChangelogViewer():
def __init__(self):
# Signals Handler
signals = {
'on_winMain_delete_event': self.on_winMain_delete_event,
'on_winMain_destroy_event': self.on_winMain_destroy_event,
'on_entrySearch_changed': self.on_entrySearch_changed,
'on_cmbData_changed' : self.on_cmbData_changed,
'on_cmbPackage_changed' : self.on_cmbPackage_changed,
}
for module in (gettext, gtk.glade):
module.bindtextdomain('uextras', '/usr/share/locale')
module.textdomain('uextras')
gladeUI = 'changelogViewer.glade'
gladeFile = gtk.glade.XML(fname=gladeUI)
gladeFile.signal_autoconnect(signals)
gw = gladeFile.get_widget
# Main Window
self.winMain = gw('winMain')
self.lblPackage = gw('lblPackage')
self.cmbPackage = gw('cmbPackage')
self.cmbData = gw('cmbData')
self.entryView = gw('entryView')
# Combo Box Results
self.cmbModelPackage = gtk.ListStore(str)
self.cmbModelData = gtk.ListStore(str)
cellPackage = gtk.CellRendererText()
cellData = gtk.CellRendererText()
self.cmbPackage.pack_start(cellPackage, True)
self.cmbPackage.add_attribute(cellPackage, 'text',0)
self.cmbData.pack_start(cellData, True)
self.cmbData.add_attribute(cellData, 'text',0)
# Set Stats and Variables
self.winMain.set_title(_('Changelog Viewer'))
self.docPath = '/usr/share/doc'
self.listInfo = []
# Text View
self.bufferText = gtk.TextBuffer()
self.entryView.set_buffer(self.bufferText)
# Start
self.winMain.show()
gtk.main()
def on_winMain_delete_event(self, widget, event = None):
self.exit()
def on_winMain_destroy_event(self, widget, event = None):
self.exit()
def exit(self):
self.winMain.destroy()
gtk.main_quit()
def on_entrySearch_changed (self, widget):
tempText = widget.get_text()
if tempText:
lastChar = tempText[-1]
if not lastChar in map(chr, range(97, 123)) and not lastChar in range(1,0) and not lastChar == '-' and not lastChar == '_' and not lastChar == ' ':
widget.set_text(tempText.replace(tempText[-1], ''))
else:
self.cmbModelPackage.clear()
if len(tempText) >= 3:
self.search (tempText)
else:
self.clearFields()
def search (self, text):
text = text.replace(' ', '-').lower()
listDir = []
for file in os.listdir(self.docPath):
if text in file:
if os.path.isfile(self.docPath+'/'+file+'/changelog.Debian.gz') or os.path.isfile(self.docPath+'/'+file+'/changelog.gz'):
listDir.append(file)
if len(listDir) == 0:
self.clearFields()
else:
self.lblPackage.set_text(_('Result(s)')+' ['+str(len(listDir))+']: ')
for value in listDir:
iter = self.cmbModelPackage.append()
self.cmbModelPackage.set_value(iter, 0, value)
self.cmbPackage.set_model(self.cmbModelPackage)
self.cmbPackage.set_active(0)
def clearFields(self):
self.lblPackage.set_text(_('Result(s) [0]: '))
self.cmbModelData.clear()
self.cmbModelPackage.clear()
self.bufferText.set_text('')
def on_cmbPackage_changed (self, widget):
selection = self.cmbPackage.get_active_text()
if selection:
if os.path.isfile(self.docPath+'/'+selection+'/changelog.Debian.gz'):
tempFile = gzip.open(self.docPath+'/'+selection+'/changelog.Debian.gz')
else:
tempFile = gzip.open(self.docPath+'/'+selection+'/changelog.gz')
print selection+ 'has not a changelog.Debian.gz'
line = tempFile.readline()
key = line.split(' ')[0]
listData = []
self.listInfo = []
listChanges = ''
while line:
while not line.startswith(key) and line:
if '--' in line and '>' in line:
username = line.split('-- ')[1].split(' <')[0]
mail = line.split('<')[1].split('>')[0]
emailInfo = {'username':username, 'mail':mail}
username = ''
mail = ''
tempData = line.replace(' ', ' ').split('> ')[1].split(' ')
count = 0
for item in tempData:
if not item:
tempData.pop(count)
count += 1
fuse = tempData[5]
if '0000' in fuse:
time = tempData[4]
else:
tempTime = tempData[4].split(':')
if fuse[0] == '-':
tempTimeHour = (int(tempTime[0]) - (int(fuse[1])*10 + int(fuse[2]))) % 24
else:
tempTimeHour = (int(tempTime[0]) + (int(fuse[1])*10 + int(fuse[2]))) % 24
time = str(tempTimeHour)+':'+tempTime[1]+':'+tempTime[2]
data = tempData[1]+' '+tempData[2]+' '+tempData[3]+' '+time
listData.append(data+' ('+header['version']+')')
self.listInfo.append({'data':data, 'changes':listChanges, 'header':header, 'emailInfo':emailInfo})
else:
listChanges = listChanges+'\t'+line
line = tempFile.readline()
if '(' in line and '(' in line:
version = line.split('(')[1].split(')')[0]
else:
version = None
if ')' in line and ';' in line:
distribution = line.split(') ')[1].split(';')[0]
else:
distribution = None
if 'urgency=' in line:
urgency = line.split('=')[1].replace('\n', '')
else:
urgency = None
header = {'version':version, 'distribution':distribution, 'urgency':urgency}
version = ''
distribution = ''
urgency = ''
listChanges = ''
line = tempFile.readline()
if len(listData) > 0:
self.cmbModelData.clear()
for value in listData:
iter = self.cmbModelData.append()
self.cmbModelData.set_value(iter, 0, value)
self.cmbData.set_model(self.cmbModelData)
self.cmbData.set_active(0)
def on_cmbData_changed (self, widget):
selectedData = self.cmbData.get_active_text()
if selected