Exemple #1
0
    def __init__(self):
        self.builder = PydoraConfigFileBuilder()

        self.cfg = ConfigParser()

        if self.builder.file_exists:
            self.read_config()
        else:
            self.cfg.add_section("user")
            self.cfg.add_section("api")
Exemple #2
0
    def parse_config(self):
        cfg = ConfigParser()

        with open(self.path) as fp:
            cfg.read_file(fp)

        settings = PancakeFileBuilder.cfg_to_dict(cfg, "api")
        settings["user"] = PancakeFileBuilder.cfg_to_dict(
            cfg, "user", dict)

        return settings
Exemple #3
0
class Configurator(object):
    """Interactive Configuration Builder

    Allows a user to configure pydora interactively. Ultimately writes the
    pydora config file.
    """

    def __init__(self):
        self.builder = PydoraConfigFileBuilder()

        self.cfg = ConfigParser()
        self.cfg.add_section("user")
        self.cfg.add_section("api")

    def fail(self, message):
        print(Screen.print_error(message))
        sys.exit(1)

    def finished(self, message):
        Screen.print_success(message)
        sys.exit(0)

    def print_message(self, message):
        print(Colors.cyan(message))

    def get_partner_config(self):
        try:
            return PandoraKeysConfigParser().load()["ios"]
        except:
            self.fail("Error loading config file. Unable to continue.")

    def get_value(self, section, key, prompt):
        self.cfg.set(section, key, Screen.get_string(prompt))

    def get_password(self, section, key, prompt):
        self.cfg.set(section, key, Screen.get_password(prompt))

    def set_static_value(self, section, key, value):
        self.cfg.set(section, key, value)

    def add_partner_config(self, config):
        for key, value in config.items():
            self.cfg.set("api", key, value)

    def write_config(self):
        with Umask(0o077), open(self.builder.path, "w") as file:
            self.cfg.write(file)

    def configure(self):
        if self.builder.file_exists:
            self.finished("You already have a pydora config!")

        self.print_message("Welcome to Pydora, let's configure a few things")
        self.add_partner_config(self.get_partner_config())
        self.get_value("user", "username", "Pandora Username: "******"user", "password", "Pandora Password: "******"api", "default_audio_quality",
                              APIClient.HIGH_AUDIO_QUALITY)

        self.write_config()
Exemple #4
0
    def __init__(self):
        self.builder = PydoraConfigFileBuilder()

        self.cfg = ConfigParser()
        self.cfg.add_section("user")
        self.cfg.add_section("api")
Exemple #5
0
class Configurator(object):

    """Interactive Configuration Builder
    Allows a user to configure pydora interactively. Ultimately writes the
    pydora config file.
    """

    def __init__(self):
        self.builder = PancakeFileBuilder()

        self.cfg = ConfigParser()
        self.cfg.add_section("user")
        self.cfg.add_section("api")

    def get_partner_config(self):
        try:
            return PandoraKeysConfigParser().load()["ios"]
        except:
            self.fail("Error loading config file. Unable to continue.")

    def get_value(self, section, key, prompt):
        self.cfg.set(section, key, input(prompt))

    def get_password(self, section, key, prompt):
        self.cfg.set(section, key, getpass.getpass(prompt))

    def set_static_value(self, section, key, value):
        self.cfg.set(section, key, value)

    def add_partner_config(self, config):
        for key, value in config.items():
            self.cfg.set("api", key, value)

    def write_config(self):
        if not os.path.exists(os.path.dirname(self.builder.path)):
            os.makedirs(os.path.dirname(self.builder.path))

        with umask(0o077), open(self.builder.path, "w") as fp:
            self.cfg.write(fp)

    def configure(self):
        if self.builder.file_exists:
            print("You already have a pancake config!")
        else:
            print("Hey there new pancake user! Give me your personal info!")
            print("Sorry this part looks so lame, i'm too lazy to make a nice "
                  "fancy login screen :P")
            self.add_partner_config(self.get_partner_config())
            self.get_value("user", "username", "Pandora E-Mail: ")
            self.get_password("user", "password", "Pandora Password: "******"api", "default_audio_quality",
                APIClient.HIGH_AUDIO_QUALITY
                )
            self.write_config()
Exemple #6
0
class Configurator(object):
    """Interactive Configuration Builder

    Allows a user to configure pydora interactively. Ultimately writes the
    pydora config file.
    """
    def __init__(self):
        self.builder = PydoraConfigFileBuilder()

        self.cfg = ConfigParser()
        self.cfg.add_section("user")
        self.cfg.add_section("api")

    def fail(self, message):
        print(Screen.print_error(message))
        sys.exit(1)

    def finished(self, message):
        Screen.print_success(message)
        sys.exit(0)

    def print_message(self, message):
        print(Colors.cyan(message))

    def get_partner_config(self):
        try:
            return PandoraKeysConfigParser().load()["ios"]
        except:
            self.fail("Error loading config file. Unable to continue.")

    def get_value(self, section, key, prompt):
        self.cfg.set(section, key, Screen.get_string(prompt))

    def get_password(self, section, key, prompt):
        self.cfg.set(section, key, Screen.get_password(prompt))

    def set_static_value(self, section, key, value):
        self.cfg.set(section, key, value)

    def add_partner_config(self, config):
        for key, value in config.items():
            self.cfg.set("api", key, value)

    def write_config(self):
        with Umask(0o077), open(self.builder.path, "w") as file:
            self.cfg.write(file)

    def configure(self):
        if self.builder.file_exists:
            self.finished("You already have a pydora config!")

        self.print_message("Welcome to Pydora, let's configure a few things")
        self.add_partner_config(self.get_partner_config())
        self.get_value("user", "username", "Pandora Username: "******"user", "password", "Pandora Password: "******"api", "default_audio_quality",
                              APIClient.HIGH_AUDIO_QUALITY)

        self.write_config()
Exemple #7
0
    def __init__(self):
        self.builder = PydoraConfigFileBuilder()

        self.cfg = ConfigParser()
        self.cfg.add_section("user")
        self.cfg.add_section("api")