Esempio n. 1
0
    def test_load(self):
        # act
        config = addonconf.load("configs/config.json")

        # assert
        self.assertEqual(config, None,
                         "Wrong return value for not exists config")
Esempio n. 2
0
    def test_load2(self):
        # act
        config = addonconf.load("configs/config.json.1")

        # assert
        self.assertEqual(config, None,
                         "Wrong return value for unvalide config")
    def test_load3(self):
        # arrange
        correct_config = {'version': '0.1', 'xpi': {'theme': 'firefox-theme-test.xpi', 'package': 'firefox-test-@[email protected]', 'extension': 'firefox-extension-test.xpi'}, 'max-version': '31.0a1', 'directory-structure': {'shared-dir': 'chrome'}, 'min-version': '29.0'}

        # act
        config = addonconf.load("configs/config.json.2")

        # assert
        self.assertEqual(config, correct_config, "Uncorrect load config")
Esempio n. 4
0
    def test_load3(self):
        # arrange
        correct_config = {
            'version': '0.1',
            'xpi': {
                'theme': 'firefox-theme-test.xpi',
                'package': 'firefox-test-@[email protected]',
                'extension': 'firefox-extension-test.xpi'
            },
            'max-version': '31.0a1',
            'directory-structure': {
                'shared-dir': 'chrome'
            },
            'min-version': '29.0'
        }

        # act
        config = addonconf.load("configs/config.json.2")

        # assert
        self.assertEqual(config, correct_config, "Uncorrect load config")
def main():
    console.start_timer()

    config = addonconf.load("config.json")
    if not config:
        sys.exit(1)

    available_actions = []
    package_is_avaliable = True
    for t in ["theme", "extension"]:
        if t in config:
            available_actions = available_actions + [t]
        else:
            package_is_avaliable = False
    if package_is_avaliable and "package" in config:
        available_actions = available_actions + ["package"]

    parser = argparse.ArgumentParser()
    parser.add_argument("action", nargs='?', default="all",
                        choices=["all"] + available_actions + ["clean"],
                        help="build theme, extension, package or clean sources")
    parser.add_argument("--version",
                        help="override version from config.json")
    parser.add_argument("--target-version", type=int,
                        help="build for a certain version only")
    parser.add_argument("--force-rebuild", action="store_true",
                        help="regenerate all needed files")
    parser.add_argument("-v", "--verbose", action="count", default=0,
                        help="increase output verbosity")
    args = parser.parse_args()

    action = args.action

    # Override preferences from config.json
    if "VERSION" in os.environ:
        config["version"] = os.environ.get("VERSION")
        config["override-version"] = True
    if args.version:
        config["version"] = args.version
        config["override-version"] = True

    if args.target_version:
        config["target-version"] = args.target_version

    config["force-rebuild"] = args.force_rebuild
    config["verbose"] = args.verbose

    config = addonconf.validate(config)
    if not config:
        sys.exit(1)

    # Clean up
    if action == "clean":
        clean_paths = []
        if os.path.isdir(".build"):
            for base, dirs, files in os.walk(".build", topdown=False):
                for name in files:
                    clean_paths.append(os.path.join(base, name))
                for name in dirs:
                    clean_paths.append(os.path.join(base, name))
            clean_paths.append(".build")

        for base, dirs, files in os.walk("build"):
            for name in files:
                if name.endswith(".pyc"):
                    clean_paths.append(os.path.join(base, name))
        clean_paths.append("build/__pycache__")

        for i in available_actions:
            clean_paths.append(config[i]["xpi"])

        for path in clean_paths:
            path = os.path.abspath(path)
            if not os.path.exists(path):
                continue
            console.log("removing", path)
            if os.path.isfile(path):
                os.remove(path)
            else:
                os.rmdir(path)

        sys.exit(0)

    # Theme building
    if action in ["theme", "all"] and "theme" in available_actions:
        builder = ThemeBuilder(config)
        print(":: Starting build theme...")
        builder.build()

    # Extension building
    if action in ["extension", "all"] and "extension" in available_actions:
        builder = ExtensionBuilder(config)
        print(":: Starting build extension...")
        builder.build()

    # Package building
    if action in ["package", "all"] and "package" in available_actions:
        builder = PackageBuilder(config)
        print(":: Starting make package...")
        builder.build()
    def test_load(self):
        # act
        config = addonconf.load("configs/config.json")

        # assert
        self.assertEqual(config, None, "Wrong return value for not exists config")
    def test_load2(self):
        # act
        config = addonconf.load("configs/config.json.1")

        # assert
        self.assertEqual(config, None, "Wrong return value for unvalide config")
Esempio n. 8
0
def main():
    console.start_timer()

    config = addonconf.load("config.json")
    if not config:
        sys.exit(1)

    available_actions = []
    package_is_avaliable = True
    for t in ["theme", "extension"]:
        if t in config:
            available_actions = available_actions + [t]
        else:
            package_is_avaliable = False
    if package_is_avaliable and "package" in config:
        available_actions = available_actions + ["package"]

    parser = argparse.ArgumentParser()
    parser.add_argument(
        "action",
        nargs='?',
        default="all",
        choices=["all"] + available_actions + ["clean"],
        help="build theme, extension, package or clean sources")
    parser.add_argument("--version", help="override version from config.json")
    parser.add_argument("--target-version",
                        type=int,
                        help="build for a certain version only")
    parser.add_argument("--force-rebuild",
                        action="store_true",
                        help="regenerate all needed files")
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=0,
                        help="increase output verbosity")
    args = parser.parse_args()

    action = args.action

    # Override preferences from config.json
    if "VERSION" in os.environ:
        config["version"] = os.environ.get("VERSION")
        config["override-version"] = True
    if args.version:
        config["version"] = args.version
        config["override-version"] = True

    if args.target_version:
        config["target-version"] = args.target_version

    config["force-rebuild"] = args.force_rebuild
    config["verbose"] = args.verbose

    config = addonconf.validate(config)
    if not config:
        sys.exit(1)

    # Clean up
    if action == "clean":
        clean_paths = []
        if os.path.isdir(".build"):
            for base, dirs, files in os.walk(".build", topdown=False):
                for name in files:
                    clean_paths.append(os.path.join(base, name))
                for name in dirs:
                    clean_paths.append(os.path.join(base, name))
            clean_paths.append(".build")

        for base, dirs, files in os.walk("build"):
            for name in files:
                if name.endswith(".pyc"):
                    clean_paths.append(os.path.join(base, name))
        clean_paths.append("build/__pycache__")

        for i in available_actions:
            clean_paths.append(config[i]["xpi"])

        for path in clean_paths:
            path = os.path.abspath(path)
            if not os.path.exists(path):
                continue
            console.log("removing", path)
            if os.path.isfile(path):
                os.remove(path)
            else:
                os.rmdir(path)

        sys.exit(0)

    # Theme building
    if action in ["theme", "all"] and "theme" in available_actions:
        builder = ThemeBuilder(config)
        print(":: Starting build theme...")
        builder.build()

    # Extension building
    if action in ["extension", "all"] and "extension" in available_actions:
        builder = ExtensionBuilder(config)
        print(":: Starting build extension...")
        builder.build()

    # Package building
    if action in ["package", "all"] and "package" in available_actions:
        builder = PackageBuilder(config)
        print(":: Starting make package...")
        builder.build()