def change_adjust_amount(): global config value = IntegerAdjustInput(config['adjust_amount'], i, o, message="Adjust amount", interval=1).activate() if value is None: return False config["adjust_amount"] = value write_config(config, config_path)
def unpin_unit(name): global config if name in config["pinned_units"]: config["pinned_units"].remove(name) write_config(config, config_path) PrettyPrinter("Unpinned unit {}".format(name), i, o, 1) else: PrettyPrinter("Error: unit {} not pinned!".format(name), i, o, 1)
def select_adjust_type(): global config contents = [["Percent", '%'], ["Decibels", 'dB'], ["HW value", '']] adjust_type = Listbox(contents, i, o, "Adjust selection listbox").activate() if adjust_type is None: return False config["adjust_type"] = adjust_type write_config(config, config_path)
def select_channel(): global config contents = [] channels = amixer_get_channels() for channel in channels: contents.append([ellipsize(channel, o.cols), channel]) channel = Listbox(contents, i, o, "Channel selection listbox").activate() if channel is None: return False config["channel"] = channel write_config(config, config_path)
def cmd_login(db, args): hostname = args.hostname token = args.token protocol = "https://" if hostname.startswith(protocol): hostname = hostname[len(protocol):] if hostname.endswith("/"): hostname = hostname[:len(hostname) - 1] helpers.write_config(hostname, token)
def adjust_timeout(): global config timeout = IntegerAdjustInput(config["timeout"], i, o, message="Socket timeout:").activate() if timeout is not None and timeout > 0: config["timeout"] = timeout write_config(config, config_path) elif not timeout > 0: Printer(ffs("Timeout has to be larger than 0!", o.cols), i, o)
def select_adjust_type(): global config contents = [ ["Percent", '%'], ["Decibels", 'dB'], ["HW value", '']] adjust_type = Listbox(contents, i, o, "Adjust selection listbox").activate() if adjust_type is None: return False config["adjust_type"] = adjust_type write_config(config, config_path)
def select_card(): #TODO get a list of all cards global config contents = [] cards = [] for card in cards: contents.append([ellipsize(card["name"], o.cols), card["id"]]) card_id = Listbox(contents, i, o, "Card selection listbox").activate() if card_id is None: return False config["card"] = card_id write_config(config, config_path)
def logout(): try: session = load_config('session.ini') current_user = session.get('DEFAULT', 'active_user') session.set('DEFAULT', 'active_user', '') session.set('DEFAULT', 'logged_in', 'False') write_config(session, 'session.ini') if current_user is not '': print (('\n >> %s%s%s has been logged out.\n' % ( Color.LT_BLUE, current_user, Color.RESET))) else: print (('\n >> No active session found.\n')) except Exception as error: profile_error(error)
def change_filters(): global config all_types = [["Slices", 'slice'], ["Sockets", 'socket'], ["Services", 'service'], ["Automounts", 'automount'], ["Mounts", 'mount'], ["Timers", 'timer'], ["Paths", 'path'], ["Devices", 'device'], ["Scopes", 'scope'], ["Targets", 'target']] checkbox_contents = [] for type in all_types: checkbox_contents.append( [type[0], type[1], type[1] in config["allowed_types"]]) states = Checkbox(checkbox_contents, i, o).activate() config["allowed_types"] = [state for state in states if states[state]] write_config(config, config_path)
def new_account(): try: userName = raw_input( 'Enter Google account email: ') user_passwd = raw_input( 'Enter Google account password: '******'user_tokens.ini') saved_accounts.add_section(userName) saved_accounts.set(userName, 'password', user_passwd) write_config(saved_accounts, 'user_tokens.ini') print('\n\nAccount authorization saved.\n') login(userName) except Exception as error: profile_error(error)
def change_filters(): global config all_types = [ ["Slices", 'slice'], ["Sockets", 'socket'], ["Services", 'service'], ["Automounts", 'automount'], ["Mounts", 'mount'], ["Timers", 'timer'], ["Paths", 'path'], ["Devices", 'device'], ["Scopes", 'scope'], ["Targets", 'target']] checkbox_contents = [] for type in all_types: checkbox_contents.append([type[0], type[1], type[1] in config["allowed_types"]]) states = Checkbox(checkbox_contents, i, o).activate() config["allowed_types"] = [state for state in states if states[state]] write_config(config, config_path)
def login(user_email): try: saved_accounts = load_config('user_tokens.ini') users = saved_accounts.sections() session = load_config('session.ini') if user_email in users: session.set('DEFAULT', 'active_user', user_email) session.set('DEFAULT', 'logged_in', 'True') write_config(session, 'session.ini') else: session.set('DEFAULT', 'active_user', '') session.set('DEFAULT', 'logged_in', 'False') write_config(session, 'session.ini') print (('\n%sGoogle DJ does not recognize that email. Verify command or\n' 'execute py_drop without arguments to add new accounts.%s' % ( Color.YELLOW, Color.RESET))) return session except Exception as error: profile_error(error)
def create_user(self, username): helpers.write_config(Constants.CONFIG_USERNAME_PREFIX + username)
def set_active_mode(self, mode): helpers.write_config(Constants.CONFIG_SECTION_GLOBAL, Constants.CONFIG_OPTION_ACTIVE_MODE, mode.value)
def update_config_yaml(self): config = yaml.safe_dump(Config().generate(self.ci()), default_flow_style=False) write_config(self.remote(), "/root/config.yaml", config)
def pin_unit(name): global config config["pinned_units"].append(name) write_config(config, config_path) Printer(["Pinned unit", name], i, o, 1)
def save_config(config): write_config(config, config_path)
from helpers import read_config, write_config from ui import Menu, Printer, Checkbox, MenuExitException import systemctl import os, sys current_module_path = os.path.dirname(sys.modules[__name__].__file__) config_path = os.path.join(current_module_path, config_filename) try: config = read_config(config_path) if "pinned_values" not in config: config["pinned_values"] = [] write_config(config, config_path) except (ValueError, IOError): print("Systemctl app: broken config, restoring with defaults...") with open(config_path, "w") as f: f.write(default_config) config = read_config(config_path) def change_filters(): global config all_types = [["Slices", 'slice'], ["Sockets", 'socket'], ["Services", 'service'], ["Automounts", 'automount'], ["Mounts", 'mount'], ["Timers", 'timer'], ["Paths", 'path'], ["Devices", 'device'], ["Scopes", 'scope'], ["Targets", 'target']] checkbox_contents = []
def write_password(self, username, password, mode): helpers.write_config( Constants.CONFIG_USERNAME_PREFIX + username, Constants.CONFIG_OPTION_PASSWORD_PREFIX + str(mode), password) print("Wrote password for user: {0}.".format(username))
def pin_unit(name): global config config["pinned_units"].append(name) write_config(config, config_path) PrettyPrinter("Pinned unit {}".format(name), i, o, 1)
def set_active_user(self, username): helpers.write_config(Constants.CONFIG_SECTION_GLOBAL, Constants.CONFIG_OPTION_ACTIVE_USER, username)