Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 14/03/2011, à 16:39

CKDevelop

demande d'aide sur un script python utilisant <python-aptdeamon>

Salut à tous,

J'ai adapter le script d'exemple de python-aptdeamon-gtk situer à cet adresse /usr/share/doc/python-aptdaemon-gtk/examples/
le problème est que je n'arrive pas à fermer le script.


voilà quoi dire de plus tongue

merci d'avance, pour vos retours
Le script est dispo à cette adresse:
http://framapad.org/9joU1gfhdA
ou:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Provides a graphical demo application for aptdaemon
"""
# Copyright (C) _ _ <_@_.org>
#
# Licensed under the GNU General Public License Version 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from optparse import OptionParser
import logging
import gobject
import gtk, sys
import aptdaemon.client
from aptdaemon.enums import *
from aptdaemon.enums import EXIT_SUCCESS
from aptdaemon.gtkwidgets import AptErrorDialog, \
                                 AptProgressDialog
class AptDaemon:
    """Provides a graphical test application."""
    def _run_transaction(self, transaction):
        dia = AptProgressDialog(transaction, parent=self.win)
        dia.run(close_on_finished=True, show_error=True,
                reply_handler=lambda: True, error_handler=self._on_error)
        print "transaction"
    def _on_error(self, error):
        msg = str(error)
        dia = gtk.MessageDialog(parent=self.win, type=gtk.MESSAGE_ERROR,
                                buttons=gtk.BUTTONS_CLOSE,
                                message_format=msg)
        dia.run()       
        dia.hide()
        print "error"
        
    def _on_close(self, close):
        print "close"
    def __init__(self, package):
        self.win = gtk.Window()
        
        self.package = package
        
        self.win.set_title("GApt")
        icon_theme = gtk.icon_theme_get_default()
        
        self.loop = gobject.MainLoop()
        
        self.win.connect("delete-event", lambda w, e: self.loop.quit())
        
        
        self.ac = aptdaemon.client.AptClient()
        if sys.argv[1] == 'install': 
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("aptdaemon-add",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass
            self.ac.install_packages([self.package],
                                    reply_handler=self._run_transaction,
                                    error_handler=self._on_error)
        elif sys.argv[1] == 'remove':
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("aptdaemon-delete",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass
            self.ac.remove_packages([self.package],
                                reply_handler=self._run_transaction,
                                error_handler=self._on_error)
        elif sys.argv[1] == 'update':   
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("aptdaemon-setup",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass                    
            self.ac.update_cache(reply_handler=self._run_transaction,
                             error_handler=self._on_error)
            print "update"
        elif sys.argv[1] == 'upgrade': 
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("update-manager",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass
            self.ac.upgrade_system(reply_handler=self._run_transaction,
                               error_handler=self._on_error)
        elif sys.argv[1] == 'installfile':  
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("aptdaemon-download",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass
            chooser = gtk.FileChooserDialog(parent=self.win,
                                        action=gtk.FILE_CHOOSER_ACTION_OPEN,
                                        buttons=(gtk.STOCK_CANCEL,
                                                 gtk.RESPONSE_CANCEL,
                                                 gtk.STOCK_OPEN,
                                                 gtk.RESPONSE_OK))
            chooser.set_local_only(True)
            chooser.run()
            chooser.hide()
            path = chooser.get_filename()
            self.ac.install_file(path, reply_handler=self._run_transaction,
                                error_handler=self._on_error)  
        print "end action"
    
    def run(self):
        print "loop run"
        self.loop.run()
def main():
    parser = OptionParser()
    parser.add_option("-p", "--package", default="", action="store",
                      dest="package",
                      help="Nom du paquet à installer ou désinstaller\n\tgapt install cw\n\tgapt remove cw\n\tgapt upgrade\n\tgapt update")
    options, args = parser.parse_args()
    start = AptDaemon(options.package)
    print "start run"
    start.run()
    print "end start run"
if __name__ == "__main__":
    main()

++


Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne

#2 Le 20/03/2011, à 13:52

CKDevelop

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

un petit up, personne pour m'aider ? merci d'avance


Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne

#3 Le 12/04/2011, à 10:46

CKDevelop

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

non personne ? dégouté hmm ++


Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne

#4 Le 09/05/2011, à 17:54

CKDevelop

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

petit up, j'en profite pour relever le poste, si quelqu'un aurait une idée ? ++


Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne

#5 Le 10/05/2011, à 17:37

Anium

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

Bonjour,

J'ai modifié directement sur le FramaPad wink

Ou bien ici :

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Provides a graphical demo application for aptdaemon
"""
# Copyright (C) _ _ <_@_.org>
#
# Licensed under the GNU General Public License Version 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from optparse import OptionParser
import logging
import gobject
import gtk, sys
import aptdaemon.client
from aptdaemon.enums import *
from aptdaemon.enums import EXIT_SUCCESS
from aptdaemon.gtkwidgets import AptErrorDialog, \
                                 AptProgressDialog
class AptDaemon:
    """Provides a graphical test application."""
    def _run_transaction(self, transaction):
        dia = AptProgressDialog(transaction, parent=self.win)
        dia.run(close_on_finished=True, show_error=True,
                reply_handler=lambda: True, error_handler=self._on_error)
        print "transaction"
    def _on_error(self, error):
        msg = str(error)
        dia = gtk.MessageDialog(parent=self.win, type=gtk.MESSAGE_ERROR,
                                buttons=gtk.BUTTONS_CLOSE,
                                message_format=msg)
        dia.run()       
        dia.hide()
        print "error"
        
    def _on_close(self, close):
        print "close"
    def __init__(self, package):
        self.win = gtk.Window()
        
        self.package = package
        
        self.win.set_title("GApt")
        icon_theme = gtk.icon_theme_get_default()
        
        #self.loop = gobject.MainLoop()
        
        #self.win.connect("delete-event", lambda w, e: self.loop.quit())
        self.win.connect("delete_event", lambda w, e: gtk.main_quit())
        
        
        self.ac = aptdaemon.client.AptClient()
        if sys.argv[1] == 'install': 
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("aptdaemon-add",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass
            self.ac.install_packages([self.package],
                                    reply_handler=self._run_transaction,
                                    error_handler=self._on_error)
        elif sys.argv[1] == 'remove':
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("aptdaemon-delete",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass
            self.ac.remove_packages([self.package],
                                reply_handler=self._run_transaction,
                                error_handler=self._on_error)
        elif sys.argv[1] == 'update':   
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("aptdaemon-setup",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass                    
            self.ac.update_cache(reply_handler=self._run_transaction,
                             error_handler=self._on_error)
            print "update"
        elif sys.argv[1] == 'upgrade': 
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("update-manager",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass
            self.ac.upgrade_system(reply_handler=self._run_transaction,
                               error_handler=self._on_error)
        elif sys.argv[1] == 'installfile':  
            try:
                gtk.window_set_default_icon(icon_theme.load_icon("aptdaemon-download",
                                                                32, 0))
            except (gobject.GError, AttributeError):
                pass
            chooser = gtk.FileChooserDialog(parent=self.win,
                                        action=gtk.FILE_CHOOSER_ACTION_OPEN,
                                        buttons=(gtk.STOCK_CANCEL,
                                                 gtk.RESPONSE_CANCEL,
                                                 gtk.STOCK_OPEN,
                                                 gtk.RESPONSE_OK))
            chooser.set_local_only(True)
            chooser.run()
            chooser.hide()
            path = chooser.get_filename()
            self.ac.install_file(path, reply_handler=self._run_transaction,
                                error_handler=self._on_error)  
        print "end action"
    
    #def run(self):
    #    print "loop run"
    #    self.loop.run()
def main():
    parser = OptionParser()
    parser.add_option("-p", "--package", default="", action="store",
                      dest="package",
                      help="Nom du paquet à installer ou désinstaller\n\tgapt install cw\n\tgapt remove cw\n\tgapt upgrade\n\tgapt update")
    options, args = parser.parse_args()
    start = AptDaemon(options.package)
    print "start run"
    #start.run()
    gtk.main()
    print "end start run"
if __name__ == "__main__":
    main()

Hors ligne

#6 Le 10/05/2011, à 17:59

CKDevelop

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

coo;l un retour big_smile

mais le script ne ce ferme pas il reste ouvert hmm j'ai aps regarder tes modif, j'y vais de ce pas sur framapad, en tous cas merci.

en faite je voulais faire un script en ligne de commande pour gérer APT grapghiquement et surtout pour pouvoir l'intégrer ensuite dans divers applications


Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne

#7 Le 11/05/2011, à 16:44

Anium

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

Tiens moi au courant si cela fonctionne, je regarderai plus en détail.

Hors ligne

#8 Le 16/05/2011, à 19:05

CKDevelop

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

le problème vient du faite que je narrive pas a fermer le script correctement à la fin d'une commande. J'ai pu constater t'es amélioration, cependant cela ne resout pas le problème.

smile ++


Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne

#9 Le 18/05/2011, à 14:13

Anium

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

D'accord, je regarderai plus en détail quand j'aurai le temps.

Hors ligne

#10 Le 12/07/2011, à 02:49

yalyess

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

Bonjour,
j'ai renconté un petit probléme en éxecutant ce programme Python

voici l'erreur qui s'affiche:

reponse = raw_input(quest.split(':')[0]
                                          ^
IndentationError: unindent does not match any outer indentation level



et le voilà mon programme:


#-*- coding: cp1252 -*-
from random import choice
from string import maketrans
accents="éàèçeaouu"
ascii="eaeceaouu"
conversion=maketrans(accents,ascii)
questions=['Allemagne:Berlin',
          'Autriche:Vienne',
          'Slovanie:Ljubljana',
          'Suede:Stickholm']

adieux=['fin','stop','bye','ciao']
reponse='X'

print 'donner la capitale du pays'
print 'Répondre "fin","bye" ou "ciao" pour arrêtrer'
while reponse not in adieux :
     quest=choice(questions)
    reponse = raw_input(quest.split(':')[0]+'? ').lower()
   
     if reponse not in adieux :
    if reponse.translate(conversion)==
            quest.split(':')[1].lower():
        print ':)'
    else:
       
        print "Faux, c'est", quest.split(':')[1]
       
print 'Bye!'

Dernière modification par yalyess (Le 12/07/2011, à 02:50)

Hors ligne

#11 Le 13/07/2011, à 10:55

CKDevelop

Re : demande d'aide sur un script python utilisant <python-aptdeamon>

salut, en faite il y a plein de souci dans ton script smile
erreur d'indentation, et variable non assigner, ainsi qu'un encodage à la walegen tongue
voilà une petite correction de ton script

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from random import choice
questions=['Allemagne:Berlin',
        'Autriche:Vienne',
        'Slovanie:Ljubljana',
        'Suede:Stickholm']

adieux=['fin','stop','bye','ciao']
reponse='X'

print 'donner la capitale du pays'
print 'Répondre "fin","bye" ou "ciao" pour arrêter'
while reponse not in adieux :
    quest=choice(questions)
    reponse = raw_input(quest.split(':')[0]+'? ').lower()
    if reponse not in adieux :
        if reponse == quest.split(':')[1].lower():
            print ':)'
        else:
            print "Faux, c'est", quest.split(':')[1]
       
print 'Bye!'

en espérant que cela t'aille ++

Dernière modification par CKDevelop (Le 13/07/2011, à 10:56)


Home -> Debian Jessie & Home server -> Debian Wheezy
Office -> Ubuntu 14.04 & Office server -> Ubuntu 12.04
Embedded -> Raspbian / Debian Wheezy

Hors ligne