Beispiel #1
0
    def process(self):
        self.args = vars(self.parse_args())

        if self.args["debug"]:
            logger.setLevel(logging.DEBUG)
            yowlogger.setLevel(level=logging.DEBUG)
        else:
            logger.setLevel(logging.INFO)
            yowlogger.setLevel(level=logging.INFO)

        YowsupEnv.setEnv("android")

        config_manager = ConfigManager()
        profile_name = None
        config_loaded_from_profile = True
        if self.args["config"]:
            config = config_manager.load(self.args["config"])
            if not os.path.isfile(self.args["config"]):
                profile_name = self.args["config"]
            elif not self.args["config"].startswith(
                    StorageTools.getStorageForProfile(config.phone)):
                config_loaded_from_profile = False
        else:
            raise ValueError("Must specify --config")

        if config is None:
            config = Config()

        if not config_loaded_from_profile:
            # config file was explicitly specified and is not that of profile,
            # load profile config and override values
            internal_config = config_manager.load(config.phone,
                                                  profile_only=True)
            if internal_config is not None:
                for property in config.keys():
                    if property != "version" and config[property] is not None:
                        internal_config[property] = config[property]
                config = internal_config

        if self._profile is None or self._profile.config is None:
            self._profile = YowProfile(profile_name or config.phone, config)

        if self._profile.config.phone is None:
            print("Invalid config")
            sys.exit(1)
Beispiel #2
0
    def load(self, path_or_profile_name, profile_only=False):
        # type: (str, bool) -> Config
        """
        Will first try to interpret path_or_profile_name as direct path to a config file and load from there. If
        this fails will interpret it as profile name and load from profile dir.
        :param path_or_profile_name:
        :param profile_only
        :return Config instance, or None if no config could be found
        """
        logger.debug("load(path_or_profile_name=%s, profile_only=%s)" %
                     (path_or_profile_name, profile_only))

        exhausted = []
        if not profile_only:
            config = self._load_path(path_or_profile_name)
        else:
            config = None
        if config is not None:
            return config
        else:
            logger.debug(
                "path_or_profile_name is not a path, using it as profile name")
            if not profile_only:
                exhausted.append(path_or_profile_name)
            profile_name = path_or_profile_name
            config_dir = StorageTools.getStorageForProfile(profile_name)
            logger.debug("Detecting config for profile=%s, dir=%s" %
                         (profile_name, config_dir))
            for ftype in self.MAP_EXT:
                if len(ftype):
                    fname = (self.NAME_FILE_CONFIG + "." + ftype)
                else:
                    fname = self.NAME_FILE_CONFIG

                fpath = os.path.join(config_dir, fname)
                logger.debug("Trying %s" % fpath)
                if os.path.isfile(fpath):
                    return self._load_path(fpath)

                exhausted.append(fpath)

            logger.error(
                "Could not find a config for profile=%s, paths checked: %s" %
                (profile_name, ":".join(exhausted)))
Beispiel #3
0
    def load(self, profile_name):
        # type: (str) -> Config

        config_dir = StorageTools.getStorageForProfile(profile_name)
        logger.debug("Detecting config for profile=%s, dir=%s" % (profile_name, config_dir))
        exhausted = []
        for ftype in self.MAP_EXT:
            if len(ftype):
                fname = (self.NAME_FILE_CONFIG + "." + ftype)
            else:
                fname = self.NAME_FILE_CONFIG

            fpath = os.path.join(config_dir, fname)
            logger.debug("Trying %s" % fpath)
            if os.path.isfile(fpath):
                return self.load_path(fpath)

            exhausted.append(fpath)

        logger.error("Could not find a config for profile=%s, paths checked: %s" % (profile_name, ":".join(exhausted)))