user@linuxtrack:~ $ python -c 'print("Soyez les bienvenus !")'

Vous n'êtes pas identifié(e).

#1 14-06-2015 02:10:19

IceF0x
#! Gourou Linux

[script]myhandylinux.py

pour ceux qui ont suivi la discussion suivante http://forum.handylinux.org/viewtopic.php?pid=6186

On parlait de modifier/mettre à jour le script myhandylinux pour distro handylinux V2, j'ai proposé une version bash ici: http://linuxtrack.net/viewtopic.php?pid=8474 et thuban une version python que j'ai modifié.

Version python

1434237481.png

#!/usr/bin/python 
# -*- coding:Utf-8 -*- 
# Under licence GPLv3 http://www.gnu.org/licenses/gpl.txt

"""
Myhandylinux : description de la handylinxu installée
            HandyLinux <http://handylinux.org>

Auteurs :
        thuban (thuban@yeuxdelibad.net)  
        coyotus (http://coyotus.com)

licence :       GNU General Public Licence v3
Dépendances :   python-gtk2, python-apt

"""

import os
import pygtk
pygtk.require('2.0')
import gtk
import apt

global green
green  = '\033[32m'

handyicon = "/usr/share/pixmaps/handymenu_icon.png"
authors = """- arpinux alias Arnault Perret : <a href='arpinux@member.fsf.org' >arpinux@member.fsf.org</a>
- guantas : grand initiateur
- fibi : <a href='contact@handylinux.org' >contact@handylinux.org</a>
- wiscot : <a href='http://shovel-crew.org' >http://shovel-crew.org</a>
- dyp -- Yaën Dubois Pujol
- Starsheep :
- bruno-legrand :
- coyotus : <a href='http://coyotus.com' >http://coyotus.com</a>
- ideefixe :
- Tiberias81 :
- thuban : <a href="http://yeuxdelibad.net">yeuxdelibad.net</a>
- Trefix :
- rouzigalos :
"""

handytools = ["handymenu", "handy-menu", "handytri", "handylinuxlook", "redshift-config", "mpartage", "btshare-hweb"]

general = """- basée sur <a href='https://www.debian.org/' >Debian stable</a>
- licence : <a href='http://www.gnu.org/licenses/gpl.txt' >2013-2015©GPLv3</a>
- homepage : <a href='http://handylinux.org' >http://handylinux.org</a>
- documentation : <a href='http://wiki.handylinux.org' >http://wiki.handylinux.org</a>
- sources : <a href='http://src.handylinux.org' >http://src.handylinux.org</a>
- contact : <a href='contact@handylinux.org' >contact@handylinux.org</a>
"""

def expose(widget, ev):
    pixbuf = gtk.gdk.pixbuf_new_from_file(handyicon)
    widget.window.draw_pixbuf(widget.style.bg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 750, 30)
    if widget.get_child() != None:
        widget.propagate_expose(widget.get_child(), ev)
    return True

class MyHandylinux():
    def close_application(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def donate(self, widget, event):
        os.system("exo-open --launch WebBrowser http://donate.handylinux.org/ &")

    def prep_apt_cache(self):
        self.cache=apt.Cache()
        self.cache.open(None)

    def get_pkg_version(self,pkgname):
        try:
            pkg = self.cache[pkgname]
            if pkg.installed:
                return(pkg.installed.version)
            else:
                return("")
        except KeyError:
            return("")

    def handytools_version(self):
        for tool in handytools:
            version = self.get_pkg_version(tool)
            if version:
                self.htools += "{} : {}, ".format(tool,version)
    
    def build_gui(self):
        # interface graphique
        mainbox = gtk.VBox(False, 2)
        
        # info sur l'ordinateur
        infolabel = gtk.Label("<span color=\"green\">Cet ordinateur</span>\n\
- Install : {},\n\
- Version : {},\n\
- Outils : {}".format(self.handyinst,self.handyvs, self.htools))
        infolabel.set_use_markup(True)
        infolabel.set_alignment(-0.9,0)

        # info sur les outils HL
        hltoolslbl = gtk.Label("<span color=\"green\">Général</span>\n{}".format(general))
        hltoolslbl.set_use_markup(True)
        hltoolslbl.set_alignment(-0.9,0)
        hltoolslbl.connect('expose_event', expose)

        # auteurs de HL
        authorslbl = gtk.Label("<span color=\"green\">Credits</span>\n{}".format(authors))
        authorslbl.set_use_markup(True)
        authorslbl.set_alignment(-0.9,0)

        # bouton contributions
        contribbtn = gtk.LinkButton(uri = "http://wiki.handylinux.org/doku.php/fr/contribution", label = "Contribuer")

        # on met tout en place
        mainbox.pack_start(hltoolslbl, True, True, 0)
        mainbox.pack_start(infolabel, True, True, 0)
        mainbox.pack_start(authorslbl, True, True, 10)
        mainbox.pack_start(contribbtn, True, True, 0)

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_default_size(900, 500)
        self.window.connect("delete_event", self.close_application)
        self.window.set_title("About Handylinux")
        self.window.set_border_width(10)
        self.window.set_icon_from_file(handyicon)
        self.window.set_position(gtk.WIN_POS_CENTER)

        self.window.add(mainbox)
        self.window.show_all()


    def __init__(self):
        self.htools = ""
        self.cache = None
        self.prep_apt_cache()

        if os.path.isfile('/etc/handylinux_installation'):
            with open('/etc/handylinux_installation', 'r') as hi:
                self.handyinst = hi.read().strip()
        else:
            self.handyinst = " ante HandyLinux-1.5.1"
        with open('/etc/handylinux_version', 'r') as hv:
            self.handyvs = hv.read().strip()

        self.handytools_version()

        self.build_gui()

def main():
    info = MyHandylinux()
    gtk.main()
    return 0        

if __name__ == "__main__":
    main()

Version bash

1434215317.png

#!/bin/bash
# à propos de mon handylinux
# Under licence GPLv3 http://www.gnu.org/licenses/gpl.txt
# require "zenity"

red='\e[0;31m'
green='\e[0;32m'

if [ -f /etc/handylinux_installation ]; then
    HANDYINST=$(cat /etc/handylinux_installation)
else
    HANDYINST=" ante HandyLinux-1.5.1"
fi
HANDYVS=$(cat /etc/handylinux_version)

handymenu_ver=$(apt-cache show handy-menu | grep "Version: 3" | awk '{print $2}')
handytri_ver=$(apt-cache show handytri | grep Version | awk '{print $2}')
handytheme_ver=$(apt-cache show handylinuxlook | grep Version | awk '{print $2}')
redshift_config_ver=$(apt-cache show redshift-config | grep Version | awk '{print $2}')
mpartage_ver=$(apt-cache show mpartage | grep Version | awk '{print $2}')
btshare_ver=$(apt-cache show btshare-hweb | grep Version | awk '{print $2}')

# affiche les infos
zenity --info --no-wrap --text "HandyLinux

<span color=\"green\">cet ordi</span> :
- install : $HANDYINST
- version : $HANDYVS
- outils : handymenu $handymenu_ver, handytri $handytri_ver, handylinuxlook/handytheme $handytheme_ver, redshift-config $redshift_config_ver, mpartage $mpartage_ver, btshare $btshare_ver

<span color=\"green\">général</span> :
- basée sur <a href='https://www.debian.org/' >Debian stable</a>
- licence : <a href='http://www.gnu.org/licenses/gpl.txt' >2013-2015©GPLv3</a>
- homepage : <a href='http://handylinux.org' >http://handylinux.org</a>
- documentation : <a href='http://wiki.handylinux.org' >http://wiki.handylinux.org</a>
- sources : <a href='http://src.handylinux.org' >http://src.handylinux.org</a>
- contact : <a href='contact@handylinux.org' >contact@handylinux.org</a>

<span color=\"green\">team v2</span> : 
- arpinux aka arnault perret : <a href='arpinux@member.fsf.org' >arpinux@member.fsf.org</a>
- guantas : grand initiateur
- fibi : <a href='contact@handylinux.org' >contact@handylinux.org</a>
- wiscot : <a href='http://shovel-crew.org' >http://shovel-crew.org</a>
- dyp :
- Starsheep :
- bruno-legrand :
- coyotus : <a href='http://coyotus.com' >http://coyotus.com</a>
- ideefixe :
- Tiberias81 :
- thuban :
- Trefix :
- rouzigalos :"

exit 0

La version python est plus rapide mais il y a toujours un lag pour la récupération des version, du coup arpinux à voulu virer la section outil et j'ai proposé ceci

Sans les outils ça donne ceci:

1434239421.png

#!/usr/bin/python 
# -*- coding:Utf-8 -*- 
# Under licence GPLv3 http://www.gnu.org/licenses/gpl.txt

"""
Myhandylinux : description de la handylinxu installée
            HandyLinux <http://handylinux.org>

Auteurs :
        thuban (thuban@yeuxdelibad.net)  
        coyotus (http://coyotus.com)

licence :       GNU General Public Licence v3
Dépendances :   python-gtk2, python-apt

"""

import os
import pygtk
pygtk.require('2.0')
import gtk

global green
green  = '\033[32m'

handyicon = "/usr/share/pixmaps/handymenu_icon.png"
authors = """- arpinux alias Arnault Perret : <a href='arpinux@member.fsf.org' >arpinux@member.fsf.org</a>
- guantas : grand initiateur
- fibi : <a href='contact@handylinux.org' >contact@handylinux.org</a>
- wiscot : <a href='http://shovel-crew.org' >http://shovel-crew.org</a>
- dyp -- Yaën Dubois Pujol
- Starsheep :
- bruno-legrand :
- coyotus : <a href='http://coyotus.com' >http://coyotus.com</a>
- ideefixe :
- Tiberias81 :
- thuban : <a href="http://yeuxdelibad.net">yeuxdelibad.net</a>
- Trefix :
- rouzigalos :
"""

general = """- basée sur <a href='https://www.debian.org/' >Debian stable</a>
- licence : <a href='http://www.gnu.org/licenses/gpl.txt' >2013-2015©GPLv3</a>
- homepage : <a href='http://handylinux.org' >http://handylinux.org</a>
- documentation : <a href='http://wiki.handylinux.org' >http://wiki.handylinux.org</a>
- sources : <a href='http://src.handylinux.org' >http://src.handylinux.org</a>
- contact : <a href='contact@handylinux.org' >contact@handylinux.org</a>
"""

def expose(widget, ev):
    pixbuf = gtk.gdk.pixbuf_new_from_file(handyicon)
    widget.window.draw_pixbuf(widget.style.bg_gc[gtk.STATE_NORMAL], pixbuf, 0, 0, 400, 25)
    if widget.get_child() != None:
        widget.propagate_expose(widget.get_child(), ev)
    return True

class MyHandylinux():
    def close_application(self, widget, event, data=None):
        gtk.main_quit()
        return False

    def donate(self, widget, event):
        os.system("exo-open --launch WebBrowser http://donate.handylinux.org/ &")

    def get_pkg_version(self,pkgname):
        try:
            pkg = self.cache[pkgname]
            if pkg.installed:
                return(pkg.installed.version)
            else:
                return("")
        except KeyError:
            return("")

    def build_gui(self):
        # interface graphique
        mainbox = gtk.VBox(False, 2)
        
        # info sur l'ordinateur
        infolabel = gtk.Label("<span color=\"green\">Cet ordinateur</span>\n\
- Install : {},\n\
- Version : {},".format(self.handyinst,self.handyvs))
        infolabel.set_use_markup(True)
        infolabel.set_alignment(-0.9,0)

        # info sur les outils HL
        hltoolslbl = gtk.Label("<span color=\"green\">Général</span>\n{}".format(general))
        hltoolslbl.set_use_markup(True)
        hltoolslbl.set_alignment(-0.9,0)
        hltoolslbl.connect('expose_event', expose)

        # auteurs de HL
        authorslbl = gtk.Label("<span color=\"green\">Credits</span>\n{}".format(authors))
        authorslbl.set_use_markup(True)
        authorslbl.set_alignment(-0.9,0)

        # bouton contributions
        contribbtn = gtk.LinkButton(uri = "http://wiki.handylinux.org/doku.php/fr/contribution", label = "Contribuer")

        # on met tout en place
        mainbox.pack_start(hltoolslbl, True, True, 0)
        mainbox.pack_start(infolabel, True, True, 0)
        mainbox.pack_start(authorslbl, True, True, 10)
        mainbox.pack_start(contribbtn, True, True, 0)

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event", self.close_application)
        self.window.set_title("About Handylinux")
        self.window.set_border_width(10)
        self.window.set_icon_from_file(handyicon)
        self.window.set_position(gtk.WIN_POS_CENTER)

        self.window.add(mainbox)
        self.window.show_all()


    def __init__(self):
        self.htools = ""
        self.cache = None

        if os.path.isfile('/etc/handylinux_installation'):
            with open('/etc/handylinux_installation', 'r') as hi:
                self.handyinst = hi.read().strip()
        else:
            self.handyinst = " ante HandyLinux-1.5.1"
        with open('/etc/handylinux_version', 'r') as hv:
            self.handyvs = hv.read().strip()

        self.build_gui()

def main():
    info = MyHandylinux()
    gtk.main()
    return 0        

if __name__ == "__main__":
    main()

Sur la version 2.0 c'est plus rapide avec outils mais y'a quand même une légère latence, tandis que sans la version des outils, pas de lag du tout

1434239917.png

1434239937.png


Utiliser des logiciels propriétaires, c'est comme les plats préparés, on est incapable de dire les conservateurs qu'ils contiennent, on dira toujours que c'est bon, mais ça ne remplacera jamais le repas fait maison par sa maman.
]:D #! Crunchbang & Archlinux GNU/Linux User ]:D

Hors ligne

#2 14-06-2015 12:14:09

ZeR0-@bSoLu
Membre

Re : [script]myhandylinux.py

Beau travail les gens big_smile


Mess With The Bests
Die Like The Rest

Hors ligne

Pied de page des forums