Advertisement
Guest User

pdi 2.1beta

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