def close(self, evt=None): """ Close event for the TutorialApp. The app will only be closed if the .editor indicates that it is safe to do so (this will prompt the student to save their code). """ # don't try to close more than once # this fixes errors when the user keeps hammering the close button if self._is_closing: return if self.editor.close() == tkmessagebox.YES: self._is_closing = True self.interpreter.kill() self.attempts.save() self.cfg.resolution.width = self.master.winfo_width() self.cfg.resolution.height = self.master.winfo_height() save_config(self.cfg) self.master.destroy()
def try_get_credentials(): """ Try to get the user's credentials. If the keyring module is not installed, prompt the user to install it. If the user refuses, set a flag so as not to prompt again. If the module is installed and the user has saved credentials, return them. Otherwise, prompt the user to enter credentials to save. Returns: A tuple containing the user's username and password. """ # we need access to the config file from tutorlib.config.configuration import load_config, save_config cfg = load_config() # return if the user has said not to store anything if not cfg.online.store_credentials: return None, None try: import keyring except ImportError: print() print('We can securely store your username and password using the ' 'keyring module') store = input( "Type 'yes' if you would like us to store your credentials: ") if store == 'yes': install = input( "Type 'yes' if you would like to install the keyring module: ") # if the user said no, remember their choice # we also remember if the install failed, as this is unlikely to change if store != 'yes' or install != 'yes' or not install_keyring_module(): cfg.online.store_credentials = False save_config(cfg) return None, None import keyring # should cause no problems at this point # if we have a username, return the associated password if cfg.online.username: password = keyring.get_password(MPT_SERVICE, cfg.online.username) return cfg.online.username, password # grab the user's username and password print() print('Please enter your UQ username and password') cfg.online.username = input('Username: ') password = getpass() print() save_config(cfg) keyring.set_password(MPT_SERVICE, cfg.online.username, password) return cfg.online.username, password
def reset_credentials(): import keyring from tutorlib.config.configuration import load_config, save_config cfg = load_config() try: keyring.delete_password(MPT_SERVICE, cfg.online.username) except Exception: # PasswordDeleteError isn't defined anywhere! pass cfg.online.username = '' save_config(cfg)
def reset_credentials(): import keyring from tutorlib.config.configuration import load_config, save_config cfg = load_config() try: keyring.delete_password(MPT_SERVICE, cfg.online.username) except Exception: # PasswordDeleteError isn't defined anywhere! pass cfg.online.username = '' save_config(cfg)
def close(self, evt=None): """ Close event for the TutorialApp. The app will only be closed if the .editor indicates that it is safe to do so (this will prompt the student to save their code). """ if self.editor.close() == tkmessagebox.YES: self.synchronise(suppress_popups=True) self.logout() save_config(self.cfg) self.master.destroy()
def create_config_if_needed(): """ If no configuration file exists, create the default configuration file. Note that this will not download the initial tutorial set. """ from tutorlib.config.configuration import config_exists, save_config from tutorlib.config.namespaces import Namespace if not config_exists(): print('Creating default config...', end='', flush=True) default_config = Namespace(**DEFAULT_CONFIG) save_config(default_config) print('done')
def create_config_if_needed(): """ If no configuration file exists, create the default configuration file. Note that this will not download the initial tutorial set. """ from tutorlib.config.configuration import config_exists, save_config from tutorlib.config.namespaces import Namespace if not config_exists(): print('Creating default config...', end='', flush=True) default_config = Namespace(**DEFAULT_CONFIG) save_config(default_config) print('done')
def try_get_credentials(): """ Try to get the user's credentials. If the keyring module is not installed, prompt the user to install it. If the user refuses, set a flag so as not to prompt again. If the module is installed and the user has saved credentials, return them. Otherwise, prompt the user to enter credentials to save. Returns: A tuple containing the user's username and password. """ # we need access to the config file from tutorlib.config.configuration import load_config, save_config cfg = load_config() # return if the user has said not to store anything if not cfg.online.store_credentials: return None, None try: import keyring except ImportError: print() print( 'We can securely store your username and password using the ' 'keyring module' ) store = input( "Type 'yes' if you would like us to store your credentials: " ) if store == 'yes': install = input( "Type 'yes' if you would like to install the keyring module: " ) # if the user said no, remember their choice # we also remember if the install failed, as this is unlikely to change if store != 'yes' or install != 'yes' or not install_keyring_module(): cfg.online.store_credentials = False save_config(cfg) return None, None import keyring # should cause no problems at this point # if we have a username, return the associated password if cfg.online.username: password = keyring.get_password(MPT_SERVICE, cfg.online.username) return cfg.online.username, password # grab the user's username and password print() print('Please enter your UQ username and password') cfg.online.username = input('Username: ') password = getpass() print() save_config(cfg) keyring.set_password(MPT_SERVICE, cfg.online.username, password) return cfg.online.username, password
def bootstrap_tutorials(): """ If the default tutorial path does not exist, download and extract the tutorials zipfile. If no default tutorial package is specified, CSSE1001Tutorials will be assumed (this is the default package name used by this script). """ from tutorlib.config.configuration import load_config, save_config from tutorlib.gui.app.support import safely_extract_zipfile from tutorlib.interface.problems \ import TutorialPackage, TutorialPackageError from tutorlib.interface.web_api import WebAPI, WebAPIError # grab our config file cfg = load_config() options = getattr(cfg, cfg.tutorials.default or 'CSSE1001Tutorials') def tutorials_are_installed(): if not options.tut_dir: # no entry in config at all (default) return False if not os.path.exists(options.tut_dir): # no package directory at all return False if not os.path.exists(options.ans_dir): # no answers dir return False try: _ = TutorialPackage(cfg.tutorials.default, options) except TutorialPackageError: return False return True if not tutorials_are_installed(): print('Downloading default tutorial package...', end='', flush=True) web_api = WebAPI() try: filename = web_api.get_tutorials_zipfile() except WebAPIError: print('failed') sys.exit(1) print('done') # set the default tutorial directory # our default tutorial directory is in the same directory as the script # note that this assumes we used the default config, which created the # CSSE1001Tutorials key print('Installing default tutorial package...', end='', flush=True) script_dir = get_script_dir() options.tut_dir = os.path.join(script_dir, 'CSSE1001Tutorials') options.ans_dir = os.path.join(script_dir, 'CSSE1001Answers') safely_extract_zipfile(filename, options.tut_dir) if not os.path.exists(options.ans_dir): os.mkdir(options.ans_dir) save_config(cfg) print('done')
def bootstrap_tutorials(): """ If the default tutorial path does not exist, download and extract the tutorials zipfile. If no default tutorial package is specified, CSSE1001Tutorials will be assumed (this is the default package name used by this script). """ from tutorlib.config.configuration import load_config, save_config from tutorlib.gui.app.support import safely_extract_zipfile from tutorlib.interface.problems \ import TutorialPackage, TutorialPackageError from tutorlib.interface.web_api import WebAPI, WebAPIError # grab our config file cfg = load_config() options = getattr(cfg, cfg.tutorials.default or 'CSSE1001Tutorials') def tutorials_are_installed(): if not options.tut_dir: # no entry in config at all (default) return False if not os.path.exists(options.tut_dir): # no package directory at all return False if not os.path.exists(options.ans_dir): # no answers dir return False try: _ = TutorialPackage(cfg.tutorials.default, options) except TutorialPackageError: return False return True if not tutorials_are_installed(): print('Downloading default tutorial package...', end='', flush=True) web_api = WebAPI() try: filename = web_api.get_tutorials_zipfile() except WebAPIError: print('failed') sys.exit(1) print('done') # set the default tutorial directory # our default tutorial directory is in the same directory as the script # note that this assumes we used the default config, which created the # CSSE1001Tutorials key print('Installing default tutorial package...', end='', flush=True) script_dir = get_script_dir() options.tut_dir = os.path.join(script_dir, 'CSSE1001Tutorials') options.ans_dir = os.path.join(script_dir, 'CSSE1001Answers') safely_extract_zipfile(filename, options.tut_dir) if not os.path.exists(options.ans_dir): os.mkdir(options.ans_dir) save_config(cfg) print('done')