コード例 #1
0
    def _retrieve_macros_from_git(self):
        """Retrieve macros from FreeCAD-macros.git

        Emits a signal for each macro in
        https://github.com/FreeCAD/FreeCAD-macros.git
        """

        macro_cache_location = utils.get_cache_file_name("Macros")

        if not self.git_manager:
            message = translate(
                "AddonsInstaller",
                "Git is disabled, skipping git macros",
            )
            self.status_message.emit(message)
            FreeCAD.Console.PrintWarning(message + "\n")
            return

        update_succeeded = self._update_local_git_repo()
        if not update_succeeded:
            return

        n_files = 0
        for _, _, filenames in os.walk(macro_cache_location):
            n_files += len(filenames)
        counter = 0
        for dirpath, _, filenames in os.walk(macro_cache_location):
            counter += 1
            if self.current_thread.isInterruptionRequested():
                return
            if ".git" in dirpath:
                continue
            for filename in filenames:
                if self.current_thread.isInterruptionRequested():
                    return
                if filename.lower().endswith(".fcmacro"):
                    macro = Macro(filename[:-8])  # Remove ".FCMacro".
                    if macro.name in self.package_names:
                        FreeCAD.Console.PrintLog(
                            f"Ignoring second macro named {macro.name} (found on git)\n"
                        )
                        continue  # We already have a macro with this name
                    self.package_names.append(macro.name)
                    macro.on_git = True
                    macro.src_filename = os.path.join(dirpath, filename)
                    macro.fill_details_from_file(macro.src_filename)
                    repo = Addon.from_macro(macro)
                    FreeCAD.Console.PrintLog(f"Found macro {repo.name}\n")
                    repo.url = "https://github.com/FreeCAD/FreeCAD-macros.git"
                    utils.update_macro_installation_details(repo)
                    self.addon_repo.emit(repo)
コード例 #2
0
 def test_version_from_int(self):
     outfile = self.generate_macro_file()
     with open(outfile) as f:
         lines = f.readlines()
         output_lines = []
         for line in lines:
             if "VERSION" in line:
                 line = "__Version__ = 1"
             output_lines.append(line)
     with open(outfile, "w") as f:
         f.write("\n".join(output_lines))
     m = Macro("Unit Test Macro")
     m.fill_details_from_file(outfile)
     self.assertEqual(m.version, "1")
コード例 #3
0
 def test_version_from_date(self):
     replacements = {
         "DATE": "2022-03-09",
     }
     outfile = self.generate_macro_file(replacements)
     with open(outfile) as f:
         lines = f.readlines()
         output_lines = []
         for line in lines:
             if "VERSION" in line:
                 line = "__Version__ = __Date__"
             output_lines.append(line)
     with open(outfile, "w") as f:
         f.write("\n".join(output_lines))
     m = Macro("Unit Test Macro")
     m.fill_details_from_file(outfile)
     self.assertEqual(m.version, "2022-03-09")
コード例 #4
0
    def test_create_from_macro(self):
        macro_file = os.path.join(self.test_dir, "DoNothing.FCMacro")
        macro = Macro("DoNothing")
        macro.fill_details_from_file(macro_file)
        addon = Addon.from_macro(macro)

        self.assertEqual(addon.repo_type, Addon.Kind.MACRO)
        self.assertEqual(addon.name, "DoNothing")
        self.assertEqual(
            addon.macro.comment,
            "Do absolutely nothing. For Addon Manager unit tests.")
        self.assertEqual(addon.url, "https://github.com/FreeCAD/FreeCAD")
        self.assertEqual(addon.macro.version, "1.0")
        self.assertEqual(len(addon.macro.other_files), 3)
        self.assertEqual(addon.macro.author, "Chris Hennes")
        self.assertEqual(addon.macro.date, "2022-02-28")
        self.assertEqual(addon.macro.icon, "not_real.png")
        self.assertEqual(addon.macro.xpm, "")
コード例 #5
0
    def test_xpm(self):
        outfile = self.generate_macro_file()
        xpm_data = """/* XPM */
static char * blarg_xpm[] = {
"16 7 2 1",
"* c #000000",
". c #ffffff",
"**..*...........",
"*.*.*...........",
"**..*..**.**..**",
"*.*.*.*.*.*..*.*",
"**..*..**.*...**",
"...............*",
".............**."
};"""
        with open(outfile) as f:
            contents = f.read()
            contents += f"\n__xpm__ = \"\"\"{xpm_data}\"\"\"\n"

        with open(outfile, "w") as f:
            f.write(contents)
        m = Macro("Unit Test Macro")
        m.fill_details_from_file(outfile)
        self.assertEqual(m.xpm, xpm_data)
コード例 #6
0
 def generate_macro(self, replacements: Dict[str, str] = {}) -> Macro:
     outfile = self.generate_macro_file(replacements)
     m = Macro("Unit Test Macro")
     m.fill_details_from_file(outfile)
     os.unlink(outfile)
     return m