Advertisement
Guest User

pdi 2.1beta

a guest
Oct 25th, 2010
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.06 KB | None | 0 0
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3.  
  4. ### Pacman database informer 2.1
  5. ### by mangus
  6. ### mangus@deprecated.it
  7. ###The ARCHLINUX name and logo are recognized trademarks
  8. ###See http://www.archlinux.org for acceptable use and restrictions.
  9.  
  10. import sys
  11. import subprocess
  12. from PyQt4 import QtGui, QtCore
  13. from mainform import Ui_MainWindow
  14.  
  15. class MainWindow(QtGui.QMainWindow,Ui_MainWindow):
  16.     def __init__(self,parent=None):
  17.         super(MainWindow, self).__init__(parent)
  18.         self.setupUi(self)
  19.         self.statusbar.showMessage('Pacman database Informer')
  20.         self.lineEdit.backspace()
  21.         self.lineEdit.setPlaceholderText('Insert complete PATH - pacman -Qo')
  22.         self.clearAll()
  23.         #signals
  24.         self.pushButton_5.clicked.connect(self.clearAll)
  25.         self.pushButton.clicked.connect(self.searchPkg)
  26.         self.actionRefresh.triggered.connect(self.clearAll)
  27.         self.comboBox.activated[str].connect(self.listRepo)
  28.         self.connect(self.actionExit, QtCore.SIGNAL("triggered()"), self.quit)
  29.         self.connect(self.lineEdit,QtCore.SIGNAL("returnPressed ()"),self.searchPkg)
  30.  
  31.     def quit(self):
  32.         QtGui.QApplication.quit()
  33.  
  34.     def closeEvent(self, event):  ##reimplemented qt function
  35.         self.hide()  ##always hide the mainwindow
  36.         event.ignore()
  37.  
  38.     def style(self):
  39.         self.textEdit.setStyleSheet ("background-image:url('pixmaps/sticker-arch2.png'); \
  40.                                      background-repeat: no repeat; background-position:center; \
  41.                                     ")
  42.         self.textEdit_2.setStyleSheet ("background-image:url('pixmaps/sticker-arch2.png'); \
  43.                                        background-repeat: no repeat; background-position:center; \
  44.                                       ")
  45.         self.textEdit_3.setStyleSheet ("background-image:url('pixmaps/sticker-arch2.png'); \
  46.                                        background-repeat: no repeat; background-position:center; \
  47.                                               ")
  48.         self.textEdit_4.setStyleSheet ("background-image:url('pixmaps/sticker-arch2.png'); \
  49.                                        background-repeat: no repeat; background-position:center; \
  50.                                       ")
  51.  
  52.     def removeStyle(self):
  53.         self.textEdit.setStyleSheet ("background-image:url('');")
  54.         self.textEdit_2.setStyleSheet ("background-image:url('');")
  55.         self.textEdit_3.setStyleSheet ("background-image:url('');")
  56.         self.textEdit_4.setStyleSheet ("background-image:url('');")
  57.  
  58.     def clearAll(self):
  59.         list=self.findRepos()
  60.         self.comboBox.addItems(list)
  61.         self.comboBox.insertSeparator((self.comboBox.count())-3)
  62.         self.listWidget.clear()
  63.         self.textEdit.clear()
  64.         self.textEdit_2.clear()
  65.         self.textEdit_3.clear()
  66.         self.textEdit_4.clear()
  67.         self.lineEdit.clear()
  68.         self.comboBox.setCurrentIndex(0)
  69.         self.tabWidget.setCurrentWidget(self.tab_3)
  70.         self.style()
  71.         self.listRepo('All')
  72.  
  73.     def listRepo(self,repo):
  74.         self.listWidget.clear()
  75.         self.textEdit.clear()
  76.         self.style()
  77.         self.textEdit_2.clear()
  78.         self.textEdit_3.clear()
  79.         self.textEdit_4.clear()
  80.         if repo == 'Orphans - pacman -Qdt':
  81.             cmd='pacman -Qdt'
  82.             barstring=' orphans packages'
  83.             self.listPackages(cmd,barstring)
  84.         elif repo == 'Foreign - pacman -Qm':
  85.             cmd='pacman -Qm'
  86.             barstring=' foreign packages'
  87.             self.listPackages(cmd,barstring)
  88.         else:
  89.             if repo == 'Stable - All But Testing':
  90.                 repos = [i for i in self.findRepos()[1:-3] if 'testing' not in i and 'unstable' not in i]
  91.             elif repo == 'All':
  92.                 repos = self.findRepos()[1:-3]
  93.             else:
  94.                 repos = [repo]
  95.             for repo in repos:
  96.                 cmd='paclist '+ str(repo)
  97.               # barstring=str(repo) +' packages'
  98.                 barstring=' packages'
  99.                 self.listPackages(cmd,barstring)
  100.  
  101.     def listPackages(self,cmd,barstring):
  102.         for i in subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout:
  103.             item = QtGui.QListWidgetItem(i.strip())
  104.             item.setIcon(QtGui.QIcon('pixmaps/tgz.png'))
  105.             self.listWidget.addItem(item)
  106.         c=self.listWidget.count()
  107.         self.statusbar.showMessage(str(c) + ' ' + barstring)
  108.  
  109.     def findRepos(self):
  110.         list= ['All']
  111.         f = open('/etc/pacman.conf','r')
  112.         for line in f.readlines():
  113.             if line[0] == '[':  ## this may be ugly....
  114.                 a=line.split(' ')[0].rstrip("\n")[1:-1]
  115.                 list.append(a)
  116.         f.close()
  117.         del list[1]  ###removes '[options]' from pacman.conf parsed with the repos
  118.         list.append('Orphans - pacman -Qdt')
  119.         list.append('Foreign - pacman -Qm')
  120.         list.append('Stable - All But Testing')
  121.         return list
  122.  
  123.     def on_listWidget_itemClicked(self, item):
  124.         ### first tab info
  125.         # clean and set first tab
  126.         self.removeStyle()
  127.         self.textEdit.clear()
  128.         self.textEdit_2.clear()
  129.         self.textEdit_3.clear()
  130.         self.textEdit_4.clear()
  131.         self.tabWidget.setCurrentWidget(self.tab_3)
  132.         p=str(item.text()).split(" ")[0]
  133.         cmd="pacman -Qi " + p
  134.         a=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout.read().decode("utf-8")
  135.         self.textEdit.setText(a)
  136.  
  137.         ### second tab files
  138.         self.textEdit_2.clear()
  139.         a=self.listWidget.selectedItems()[0]
  140.         p=str(a.text()).split(" ")[0]
  141.         cmd="pacman -Ql " + p
  142.         l=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout.read()
  143.         self.textEdit_2.setText(l)
  144.  
  145.         ### third tab scripts
  146.         self.textEdit_3.clear()
  147.         a=self.listWidget.selectedItems()[0]
  148.         p=str(a.text()).split(" ")[0]
  149.         cmd="pacscripts " + p
  150.         r = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout.read().decode( "utf-8")
  151.         e = subprocess.Popen(cmd,shell=True,stderr=subprocess.PIPE).stderr.read().decode( "utf-8")
  152.         self.textEdit_3.setText(str(r)+str(e))
  153.  
  154.         ### fourth tab deps tree
  155.         self.textEdit_4.clear()
  156.         a=self.listWidget.selectedItems()[0]
  157.         p=str(a.text()).split(" ")[0]
  158.         app.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
  159.         self.statusbar.showMessage('Loading deps tree')
  160.         cmd="pactree " + p
  161.         l=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout.read()
  162.         self.textEdit_4.setText(l)
  163.         self.statusbar.showMessage('Done')
  164.         app.restoreOverrideCursor()
  165.  
  166.     def searchPkg(self):
  167.         self.listWidget.clear()
  168.         self.tabWidget.setCurrentWidget(self.tab_3)
  169.         self.textEdit.clear()
  170.         a=self.lineEdit.displayText().toUtf8()
  171.         b=str(a)
  172.         if not b:
  173.             self.textEdit.clear()
  174.             self.removeStyle()
  175.             self.textEdit.setText('No file specified.')
  176.             return
  177.         cmd="pacman -Qo " + str(a)
  178.         app.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
  179.         a=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout.readlines()
  180.         if not a:
  181.             self.textEdit.clear()
  182.             self.removeStyle()
  183.             self.textEdit.setText('No such file or directory.')
  184.             app.restoreOverrideCursor()
  185.             return
  186.  
  187.         for l in subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).stdout.readlines():
  188.             r=l.decode( "utf-8")
  189.             print r
  190.             item = QtGui.QListWidgetItem(r.strip().split(" ")[4] + ' ' +r.strip().split(" ")[5])
  191.             item.setIcon(QtGui.QIcon('pixmaps/tgz.png'))
  192.             self.listWidget.addItem(item)
  193.         self.statusbar.showMessage('Done.')
  194.         app.restoreOverrideCursor()
  195.  
  196.     @QtCore.pyqtSlot()
  197.     def on_actionAbout_triggered(self):
  198.         QtGui.QMessageBox.about(self ,"Pacman database Informer" , 'Pacman database Informer 2.1 by mangus \n \n'
  199.                                       'A little tool for little queries to the pacman database \n'
  200.                                       'mangus@deprecated.it \n \n The ARCHLINUX name and'
  201.                                       'logo are recognized trademarks \n'
  202.                                       'See http://www.archlinux.org/ for acceptable use and restrictions.')
  203.  
  204.     @QtCore.pyqtSlot()
  205.     def on_actionAbout_Qt_triggered(self):
  206.         QtGui.QMessageBox.aboutQt(self)
  207.  
  208.     def on_actionArchlinux_org_triggered(self):
  209.         QtGui.QDesktopServices().openUrl(QtCore.QUrl('http://www.archlinux.org'))
  210.  
  211.  
  212. class SystemTrayIcon(QtGui.QSystemTrayIcon):
  213.     def __init__(self, icon, parent=None):
  214.         QtGui.QSystemTrayIcon.__init__(self, icon, parent)
  215.         menu = QtGui.QMenu(parent)
  216.         # Actions
  217.         self.actionQuit= QtGui.QAction(QtGui.QIcon('pixmaps/application-exit.png'),"Exit", self)
  218.         menu.addAction(self.actionQuit)
  219.         # Connect menu with signals
  220.         self.connect(self.actionQuit, QtCore.SIGNAL("triggered()"), self.quit)
  221.         # Other signals
  222.         traySignal = "activated(QSystemTrayIcon::ActivationReason)"
  223.         QtCore.QObject.connect(self, QtCore.SIGNAL(traySignal), self.icon_activated)
  224.         # Create Menu
  225.         self.setContextMenu(menu)
  226.  
  227.     def quit(self):
  228.         QtGui.QApplication.quit()
  229.  
  230.     def icon_activated(self, reason):
  231.         if reason == QtGui.QSystemTrayIcon.Trigger:
  232.             mainwindow.show()
  233.  
  234. def main():
  235.     global app
  236.     app = QtGui.QApplication(sys.argv)
  237.     # TrayIcon
  238.     if QtGui.QSystemTrayIcon.isSystemTrayAvailable():
  239.         w = QtGui.QWidget()
  240.         icon = QtGui.QIcon("pixmaps/archlinux-icon-crystal-64.svg")
  241.         trayIcon = SystemTrayIcon(icon, w)
  242.         trayIcon.show()
  243.         trayIcon.setToolTip("pdi - pacman database informer")
  244.     # Main Window
  245.     global mainwindow
  246.     mainwindow=MainWindow()
  247.     mainwindow.show()
  248.     sys.exit(app.exec_())
  249.  
  250. if __name__ == "__main__":
  251.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement