def clone_repository(window, source, destination): cloning_timeout = 5 command = 'git clone %s %s' % (source, destination) child = pexpect.spawn(command) try: child.expect("Username*", timeout=cloning_timeout) dialog = AuthorizationWrapper(window) dialog.exec_() child.sendline(dialog.username) child.expect("Password*", timeout=cloning_timeout) child.sendline(dialog.password) child.expect(pexpect.EOF) info = child.before except (pexpect.TIMEOUT, pexpect.EOF): rm_command = 'rm -rf ' + destination system(rm_command) try: child.expect("Password*", timeout=cloning_timeout) dialog = AuthorizationWrapper(window) dialog.ui.Username_lineEdit.setText("Not needed") dialog.ui.Username_lineEdit.setReadOnly(True) dialog.exec_() child.sendline(dialog.password) child.expect(pexpect.EOF) info = child.before except (pexpect.TIMEOUT, pexpect.EOF): system(rm_command) if source.startswith('https://') and '@' in source: return (False, 'Timeout error!') else: info = getoutput(command) save_log(command, info) return (True, info)
def push(window, additional_args=None): child = pexpect.spawn('git push') try: child.expect("Username*", timeout=2) dialog = AuthorizationWrapper(window) dialog.exec_() child.sendline(dialog.username) child.expect("Password*", timeout=2) child.sendline(dialog.password) child.expect(pexpect.EOF) info = child.before except (pexpect.TIMEOUT, pexpect.EOF): try: child.expect("Password*", timeout=2) dialog = AuthorizationWrapper(window) dialog.ui.Username_lineEdit.setText("Not needed") dialog.ui.Username_lineEdit.setReadOnly(True) dialog.exec_() child.sendline(dialog.password) child.expect(pexpect.EOF) info = child.before except (pexpect.TIMEOUT, pexpect.EOF): if get_url().startswith('https://'): info = 'Timeout error!' else: info = getoutput('git push') save_log('git push', info) return info
class SettingsDialogWrapper(QDialog): def __init__(self, parent=None): QDialog.__init__(self) self.dialog = AuthorizationWrapper(self) self.parent = parent self.ui = Ui_SettingsDialog() self.ui.setupUi(self) settings = get_settings() self.ui.usernameEdit.setText(settings[0]) self.ui.emailEdit.setText(settings[1]) self.ssh_key() QObject.connect(self, SIGNAL('accepted()'), self.update_settings) QObject.connect(self.ui.generateButton, SIGNAL('clicked()'), self.check_key_existence) QObject.connect(self.dialog, SIGNAL('accepted()'), self.generate) def ssh_key(self): self.ui.sshTextEdit.setText(get_ssh_key()) def update_settings(self): set_settings(self.ui.usernameEdit.text(), self.ui.emailEdit.text()) def generate(self): QMessageBox.information(self, 'Generated new key', generate_new_ssh_key(self.dialog.username, self.dialog.password), QMessageBox.Ok) self.ssh_key() def ask_for_auth(self): self.dialog.ui.label.setText('Email:') self.dialog.exec_() QObject.connect(self.dialog, SIGNAL('accepted()'), self.generate) def check_key_existence(self): if exists((expanduser('~/.ssh/id_rsa.pub'))) or exists((expanduser('~/.ssh/id_rsa.pub'))): reply = QMessageBox.question(self, 'Existing key', 'Do you want to override the existing SSH key?', QMessageBox.Yes, QMessageBox.No) if reply == QMessageBox.Yes: backup() self.ask_for_auth() else: self.ask_for_auth()