IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

Comment passer la main a une appli exécuter avec os.system() ?


Sujet :

Python

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Décembre 2008
    Messages
    412
    Détails du profil
    Informations personnelles :
    Âge : 53
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Décembre 2008
    Messages : 412
    Points : 79
    Points
    79
    Par défaut Comment passer la main a une appli exécuter avec os.system() ?
    Bonjour,

    Je suis sur Ubuntu 14.04 x64 et python 2.7.6
    J'ai créer une mini appli pour gérer des connexions ssh /sftp et login avec mot de passe pour des postes local en fonction du Linux utilisé (Gnome/KDE/XFCE/LXDE) de la machine qui exécute mon appli.
    Cependant comme je suis débutant python, je voudrais savoir comment faire pour passer la main au application qui son exécuter par python avec os.system() ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    def Nautilus(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        print ("Nautilus")
        GESTIONAIRE_FICHIERS = "nautilus"
        cmd = GESTIONAIRE_FICHIERS+" sftp://"+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+" :"+PORT_MACHINE+" "+DOSSIER_MACHINE # AVEC MDP
        #cmd = PROG+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+":"+PORT_MACHINE+""+DOSSIER_MACHINE
        print cmd
        os.system(cmd)
     
    def Dolphin(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        GESTIONAIRE_FICHIERS = "dolphin"
        cmd = GESTIONAIRE_FICHIERS+" sftp://"+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+":"+PORT_MACHINE+""+DOSSIER_MACHINE # AVEC MDP
        #cmd = PROG+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+":"+PORT_MACHINE+""+DOSSIER_MACHINE
        print cmd
        os.system(cmd)
     
    def Thunar(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        None
     
    def Pcmanfm(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        None
     
    def Konqueror(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        GESTIONAIRE_FICHIERS = "konqueror"
        cmd = GESTIONAIRE_FICHIERS+" sftp://"+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+":"+PORT_MACHINE+""+DOSSIER_MACHINE # AVEC MDP
        #cmd = PROG+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+":"+PORT_MACHINE+""+DOSSIER_MACHINE
        print cmd
        os.system(cmd)
     
    def Caja(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        None
     
    def Peony(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        None
     
    def Nemo(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        None
     
    def Spacefm(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        None
     
    def Ssh(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        PROG = "ssh "
        #cmd2 = GESTIONAIRE_FICHIERS+" sftp://"+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+" :"+PORT_MACHINE+""+DOSSIER_MACHINE # AVEC MDP
        cmd = PROG+USER_MACHINE+"@"+IP_MACHINE+" -p "+PORT_MACHINE
        print cmd
        os.system(cmd)
     
    def Sshpro(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        PROG = "sshpro "
        #cmd2 = GESTIONAIRE_FICHIERS+" sftp://"+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+" :"+PORT_MACHINE+""+DOSSIER_MACHINE # AVEC MDP
        cmd = PROG+USER_MACHINE+":"+MDP+"@"+IP_MACHINE+":"+PORT_MACHINE+""+DOSSIER_MACHINE
        print cmd
        os.system(cmd)
     
    def Choix(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE):
        #global USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE, NOM_MACHINE, INFO_MACHINE
        PADY_LABEL = "1"
        PADY_BT = "1"
        filewin = Toplevel(master)
        Frame1 = Frame(filewin, borderwidth=1, relief=GROOVE)
        Frame1.pack(side=TOP, padx=1, pady=1)
        Label(Frame1, text="Information et type de connexion", bg=FBG, fg=FFG, font=FFT, bd=FBD, relief=FRF).pack(padx=5, pady=5)
        #Label(Frame1, text="INFO MACHINE : "+INFO_MACHINE_1, bg=FBG, fg=FFG, font=FFT, bd=FBD, relief=FRF).pack(padx=4, pady=4) 
        #Label(Frame1, text="INFO MACHINE : "+ "I7 960", bg="silver", fg="black", font="Arial 10", bd="4", relief="flat").pack(padx=1, pady=1) 
     
        # LabelFrame 1 - 1
        Frame1_Label1 = Frame(Frame1, width=380, height=310) # 280 / 200 - Largeur / Hauteur
        Frame1_Label1.pack(side=TOP, padx=5, pady=1)
        xFrame1_Label1 = Frame(Frame1_Label1, relief=GROOVE, borderwidth=2)
        Label(xFrame1_Label1, text="").pack(pady=PADY_LABEL)
        #Button(xFrame1_Label1, text="  IP locale  ", command=lambda :IP_LOCAL(0, 1)).pack(side=TOP, padx=1, pady=1)
        #Button(xFrame1_Label1, text="IP internet", command=cmd_iframe1_2_ip2).pack(side=TOP, padx=1, pady=1)
        Label(xFrame1_Label1, text="Machine : "+NOM_MACHINE).pack(pady=PADY_LABEL)
        Label(xFrame1_Label1, text="Info : "+INFO_MACHINE).pack(pady=PADY_LABEL)
        Label(xFrame1_Label1, text="Login : "+USER_MACHINE).pack(pady=PADY_LABEL)
        Label(xFrame1_Label1, text="Mot de passe : "+MDP).pack(pady=PADY_LABEL)
        Label(xFrame1_Label1, text="Adresse IP : "+IP_MACHINE).pack(pady=PADY_LABEL)
        Label(xFrame1_Label1, text="Port machine : "+PORT_MACHINE).pack(pady=PADY_LABEL)
        Label(xFrame1_Label1, text="Dossier machine : "+DOSSIER_MACHINE).pack(pady=PADY_LABEL)
        Label(xFrame1_Label1, text="").pack(pady=PADY_LABEL)
     
        xFrame1_Label1.place(relx=0.01, rely=0.125, anchor=NW)
        Label(Frame1_Label1, text="Information ").place(relx=.06, rely=0.125,anchor=W)
        Frame1_Label1.pack()
     
        # LabelFrame 1 - 2
        Frame1_Label2 = Frame(Frame1, width=480, height=540) # Largeur / Hauteur
        Frame1_Label2.pack(side=TOP, padx=5, pady=5)
        xFrame1_Label2 = Frame(Frame1_Label2, relief=GROOVE, borderwidth=2)
        Label(xFrame1_Label2, text="").pack(pady=5)
        #Button(xFrame1_Label1, text="  IP locale  ", command=lambda :IP_LOCAL(0, 1)).pack(side=TOP, padx=1, pady=1)
        #Button(xFrame1_Label1, text="IP internet", command=cmd_iframe1_2_ip2).pack(side=TOP, padx=1, pady=1)
     
        Button(xFrame1_Label2, text="Ubuntu  / Gnome / Gestionnaire de fichiers : Nautilus", command=lambda :Nautilus(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="Kubuntu /  KDE  / Gestionnaire de fichiers : Dolphin", command=lambda :Dolphin(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="Xubuntu / XFCE  / Gestionnaire de fichiers : Thunar", command=lambda :Thunar(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="Lubuntu / LXCE  / Gestionnaire de fichiers : PCManFM", command=lambda :Pcmanfm(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="", command=None, relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="Autre / KDE  / Gestionnaire de fichiers : Konqueror", command=lambda :Konqueror(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="Autre / Ubuntu Mate  / Gestionnaire de fichiers : Caja", command=lambda :Caja(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="Autre / Ukui  / Gestionnaire de fichiers : Peony", command=lambda :Peony(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="Autre / Cinnamon  / Gestionnaire de fichiers : Nemo", command=lambda :Nemo(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="Autre / fork de PCMan File Manager  / Gestionnaire de fichiers : SpaceFM", command=lambda :Spacefm(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="", command=None, relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="SSH", command=lambda :Ssh(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="SSHPRO", command=lambda :Sshpro(NOM_MACHINE, INFO_MACHINE, USER_MACHINE, MDP, IP_MACHINE, PORT_MACHINE, DOSSIER_MACHINE), relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        Button(xFrame1_Label2, text="", command=None, relief=FLAT).pack(side=TOP, padx=1, pady=PADY_BT)
        xFrame1_Label2.place(relx=0.01, rely=0.125, anchor=NW)
        Label(Frame1_Label2, text="Cliquez sur un choix ").place(relx=.06, rely=0.125,anchor=W)
        Frame1_Label2.pack()
     
        Label(filewin, text="").pack(pady=PADY_LABEL)
        Button(filewin, text="Annuler", command=filewin.destroy).pack(side=TOP, padx=1, pady=1)
        Label(filewin, text="").pack(pady=PADY_LABEL)
     
        filewin.mainloop()
    Pouvez vous m'aiguiller ?
    Merci d'avance pour votre aide .

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 292
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 292
    Points : 36 788
    Points
    36 788
    Par défaut
    Citation Envoyé par xunil2003 Voir le message
    Cependant comme je suis débutant python, je voudrais savoir comment faire pour passer la main au application qui son exécuter par python avec os.system() ?
    Ca veut dire quoi passer la main?
    note: vous n'êtes pas en train d'essayer de faire l'exo. d'un tuto. donc, vous n'êtes plus débutant et donc vous devez savoir expliquer pourquoi vous voulez utiliser os.system...

    - W

  3. #3
    Expert éminent
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    3 885
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 3 885
    Points : 7 233
    Points
    7 233
    Par défaut
    Et conceptuellement c'est une catastrophe... Vos fonctions font quasiment toutes la même chose, il n'y a que le nom qui change !

    Vue ce que font vos fonctions, leur nom n'est absolument pas explicite, mais devrait être une action représentée par un verbe.

    Puis vous utilisez sftp, si je rajoute python sur google je tombe sur un module portable dès la 1ère réponse.

    Je pense qu'effectivement la lecture d'un tutoriel doit être la priorité avant d'aller vers des problématiques plus complexes.

Discussions similaires

  1. Réponses: 1
    Dernier message: 25/02/2018, 19h53
  2. comment récupérer la fermeture d'une appli lancée avec "subprocess"
    Par ptissendier dans le forum Général Python
    Réponses: 2
    Dernier message: 11/04/2014, 07h49
  3. Réponses: 1
    Dernier message: 25/01/2009, 01h10
  4. Réponses: 1
    Dernier message: 31/07/2006, 13h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo