def main_CLI(args): Output.verbose("*" * 10 + " " + str(datetime.datetime.now()) + " " + "*" * 10) Output.verbose("ENACdrives " + CONST.FULL_VERSION) Output.verbose("Detected OS : " + CONST.OS_DISTRIB + " " + CONST.OS_SYS + " " + CONST.OS_VERSION + "\n") Output.debug("LOCAL_USERNAME:"******"LOCAL_GROUPNAME:" + CONST.LOCAL_GROUPNAME) Output.debug("LOCAL_UID:" + str(CONST.LOCAL_UID)) Output.debug("LOCAL_GID:" + str(CONST.LOCAL_GID)) Output.debug("HOME_DIR:" + CONST.HOME_DIR) Output.debug("USER_CONF_FILE:" + CONST.USER_CONF_FILE) Output.debug("RESOURCES_DIR:" + CONST.RESOURCES_DIR + "\n") Output.debug("IMAGES_DIR:" + CONST.IMAGES_DIR + "\n") Output.debug("DEFAULT_MNT_DIR:" + CONST.DEFAULT_MNT_DIR + "\n") release_number_validation = validate_release_number() if release_number_validation == 'too old': Output.warning(CONST.NEED_TO_UPDATE_MSG) elif release_number_validation == 'newer': Output.normal(CONST.NEWER_THAN_PROD_MSG) if args.version: Output.cli("ENACdrives " + CONST.FULL_VERSION) sys.exit(0) ui = CLI(args) sys.exit(ui.run())
def get_password(self, realm, password_mistyped): # For Key_Chain if password_mistyped: Output.cli( "Password mistyped. Please re-type '{}' password".format( realm)) else: Output.cli("Please type '{}' password".format(realm)) return getpass.getpass()
def set_username(self, args): if args.username is not None: validation_answer = validate_username(args.username) if validation_answer == "ok": Output.cli( "\033[01;37m*** ENACdrives username set to {} ***\033[00m". format(args.username)) conf.save_username(args.username) else: Output.error(validation_answer) self.execution_status(2)
def show_msgs(self): for msg in self.cfg["msg"]: pre = " " post = "" if self.cfg["msg"][msg]["icon"] == "info": pre = "\033[01;37m -> INFO: " post = " <-\033[00m" if self.cfg["msg"][msg]["icon"] == "warning": pre = "\033[01;33m !! WARNING: " post = " !!\033[00m" if self.cfg["msg"][msg]["icon"] == "critical": pre = "\033[01;31m !!! CRITICAL: " post = " !!!\033[00m" Output.cli(pre + self.cfg["msg"][msg]["text"] + post)
def notify_user(self, msg): # For CIFS_Mount Output.cli("Notify_user: " + msg)
def show_summary(self, expected_status=None): if expected_status is None: expected_status = {} special_chars = { "unicode": { "stared": "\u272F", "unstared": " ", # "\u274F" # "\u274d" "no_network": "\u2757", "mounted": "\u2713", "umounted": "\u2717", }, "ascii": { "stared": "*", "unstared": " ", # "\u274F" # "\u274d" "no_network": "!", "mounted": "v", "umounted": "x", }, } display_mode = "unicode" # may be switched to "ascii" if necessary def is_bookmarked(entry): if entry.settings["bookmark"]: return "\033[01;33m{}\033[00m".format( special_chars[display_mode]["stared"]) else: return "{}".format(special_chars[display_mode]["unstared"]) def is_mounted(entry): required_network = entry.settings.get("require_network") if required_network is not None: net_status, net_msg = self.networks_check.get_status( required_network) if not net_status: return "\033[01;31m{}\033[00m {}".format( special_chars[display_mode]["no_network"], net_msg) if entry.is_mounted(): return "\033[01;32m{}\033[00m on {}".format( special_chars[display_mode]["mounted"], entry.settings["local_path"]) else: return "\033[01;31m{}\033[00m".format( special_chars[display_mode]["umounted"]) if self.cfg["global"].get("username") is None: Output.cli("\033[01;37m*** ENACdrives entries summary ***\033[00m") else: Output.cli( "\033[01;37m*** ENACdrives entries summary for user {} ***\033[00m" .format(self.cfg["global"]["username"])) name_width = 1 label_width = 1 for entry in self.entries: name_width = max(name_width, len(entry.settings["name"])) label_width = max(label_width, len(entry.settings["label"])) for entry in self.entries: if expected_status.get(entry.settings["name"]) is not None: iteration_max = 3 while expected_status[ entry.settings["name"]] != entry.is_mounted(): time.sleep(0.5) entry.uncache_is_mounted() iteration_max -= 1 if iteration_max <= 0: break try: Output.cli( "{} \033[00;37m{:<{name_width}}\033[00m \033[01;37m{:<{label_width}}\033[00m {}" .format(is_bookmarked(entry), entry.settings["name"], entry.settings["label"], is_mounted(entry), name_width=name_width, label_width=label_width)) except UnicodeEncodeError: # UnicodeEncodeError: 'ascii' codec can't encode character '\u2717' in position 86: ordinal not in range(128) display_mode = "ascii" Output.cli( "{} \033[00;37m{:<{name_width}}\033[00m \033[01;37m{:<{label_width}}\033[00m {}" .format(is_bookmarked(entry), entry.settings["name"], entry.settings["label"], is_mounted(entry), name_width=name_width, label_width=label_width)) if len(self.entries) == 0: Output.cli("No entry found.") if self.cfg["global"].get("username") is None: Output.warning( "username not defined. You can set it with argument --username=username" ) self.execution_status(1)