Lancer Python depuis Bash : appel de fonction + arguments

Fermé
A.b.o.91 - 30 mars 2015 à 17:42
dsy73 Messages postés 9252 Date d'inscription dimanche 22 août 2010 Statut Contributeur Dernière intervention 23 octobre 2020 - 31 mars 2015 à 20:47
Bonjour,
je veux accéder à une application python depuis bash et appeler des fonctions avec leurs arguments sans toucher le code python. comment faire SVP?
j'ai essayé python -c 'import sys,os; sys.path.append(os.getcwd()); from toto import function; function(x,y)' ça marche pas. peut-être j'ai pas su l'utiliser..
je galère depuis des jours je vous en prie de m'aider c'est très urgent! merci

1 réponse

dsy73 Messages postés 9252 Date d'inscription dimanche 22 août 2010 Statut Contributeur Dernière intervention 23 octobre 2020 2 476
31 mars 2015 à 07:55
0
Bonjour
merci dsy73 pour les pistes .. le problème c'est que j'ai une application faite avec PyQt déjà implementée que je dois lancer automatiquement et remplir ses formulaires et clicker sur ses différents boutons "automatiquement" sans toucher le code. donc pour cela il faut entrer au code de l'application fait avec python et appeler les différents fonctions "lancer_button_record" "entrer_password".... avec des arguments. j'ai pensé à créer un code bash.
Ectcequ'il y aura une autre possibilité comment faire? c'est mon projet de Fin d'etudes
0
voici un exemple du code Test.py
j'ai mon class Main:


class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_main_window()
self.ui.setupUi(self)

self.stop_running = False

self.run_icon = QtGui.QIcon(os.path.expanduser('~') + '/libexec/stbt/icons/ic_play.png')
self.rec_icon = QtGui.QIcon(os.path.expanduser('~') + '/libexec/stbt/icons/ic_record.png')
self.stop_icon = QtGui.QIcon(os.path.expanduser('~') + '/libexec/stbt/icons/ic_stop.png')
self.edit_icon = QtGui.QIcon(os.path.expanduser('~') + '/libexec/stbt/icons/ic_edit.png')
self.tv_icon = QtGui.QIcon(os.path.expanduser('~') + '/libexec/stbt/icons/ic_tv.png')

self.setWindowTitle(QtGui.QApplication.translate("main_window", "STB-Tester Manager " + MANAGER_VERSION, None,
QtGui.QApplication.UnicodeUTF8))

self.ui.run_button.setIcon(self.run_icon)
self.ui.record_button.setIcon(self.rec_icon)......


et la fonction action_record() qui lance un boutton record :


def action_record(self):
global _run_ongoing
global _rec_ongoing
global _rec_spawn

if _run_ongoing == True:
dialog = PopUp("Error", "Run in progress.\nCan't start record at the same time.")
dialog.exec_()
return

if _playlist_ongoing == True:
dialog = PopUp("Error", "Playlist mode is activated\nCan't use this feature at the same time.")...

def action_run(self):

....

comment lancer l'application et puis lancer action_record , et puis lancer d'autres fonctions qui possedent des arguments
0
dsy73 Messages postés 9252 Date d'inscription dimanche 22 août 2010 Statut Contributeur Dernière intervention 23 octobre 2020 2 476 > A.b.o.91
31 mars 2015 à 20:47
Est-ce que des tests unitaires ne suffiraient pas ?
Tu peux faire ça avec py.test
0