Addon Manager improvements

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Addon Manager improvements

Post by Syres »

Ignore the above post, I was on the right track but it's not the length of the Github URL but the length of 'storename'. If I change the addonmanager_workers.py around line 414 from:

Code: Select all

                    storename = os.path.join(store,name)
                    if not os.path.exists(storename):
to the hack of:

Code: Select all

                    storename = os.path.join(store,name)
                    storename = storename[:259]
                    if not os.path.exists(storename):
the Reinforcement Wb images load correctly, the 2nd image full path had a length of 261 characters.


OS: Windows 7 SP 1 (6.1)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.17065 (Git)
Build type: Release
Branch: master
Hash: d890b4ec17b9030dc2933c029debb2a655a08218
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United Kingdom (en_GB)
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Addon Manager improvements

Post by Kunda1 »

Syres wrote: Tue Jun 18, 2019 10:51 am Ignore the above post, I was on the right track but it's not the length of the Github URL but the length of 'storename'.
Nice :tada:
What does

Code: Select all

storename = storename[:259]
do ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Addon Manager improvements

Post by Syres »

Kunda1 wrote: Tue Jun 18, 2019 10:54 am What does

Code: Select all

storename = storename[:259]
do ?
It's the equivalent of Vb's Left string function so only the first 259 characters are used and the rest dropped, hence the word hack!! I can look at a proper fix but I'm concerned about how much of Yorik's fine work will be altered so I'd like to wait for further feedback beforehand.
User avatar
easyw-fc
Veteran
Posts: 3630
Joined: Thu Jul 09, 2015 9:34 am

Re: Addon Manager improvements

Post by easyw-fc »

yorik wrote: Sun Jun 16, 2019 2:55 am @Kunda1 and everybody else, if any of you add new icons, please also update this file: https://github.com/FreeCAD/FreeCAD/blob ... anager.qrc
Hi @yorik @kunda
I see that I have my WB icon in the file:
https://github.com/FreeCAD/FreeCAD/blob ... anager.qrc

Code: Select all

<file>icons/Kicad-StepUp-tools-workbench_icon.svg</file>
but it seems it is not loaded... is it because there are '-' inside the icon name?
Manipulator and defeaturing wb get the icon just fine...
ksu-missing-ico.png
ksu-missing-ico.png (74.08 KiB) Viewed 1692 times
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Addon Manager improvements

Post by Kunda1 »

easyw-fc wrote: Tue Jun 18, 2019 4:41 pm is it because there are '-' inside the icon name?
I don't know the logic @yorik used, but can you quickly convert it locally and test it ? (maybe needs a restart?)
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Addon Manager improvements

Post by Syres »

In order to reduce the chances of duplicate filenames with those images greater than the Windows limit, my suggestion is to use the workbench name in conjunction with a bit of maths to arrive at a new 'storename'.

So my suggestion would be to change the section in addonmanager_workers.py at line 385 from:

Code: Select all

        l = self.loadImages( message, self.repos[self.idx][1])
        if l:
            self.info_label.emit( l )
        self.stop = True

    def loadImages(self,message,url):
        
        "checks if the given page contains images and downloads them"

        # QTextBrowser cannot display online images. So we download them
        # here, and replace the image link in the html code with the
        # downloaded version

        imagepaths = re.findall("<img.*?src=\"(.*?)\"",message)
        if imagepaths:
            storedimages = []
            store = os.path.join(FreeCAD.getUserAppDataDir(),"AddonManager","Images")
            if not os.path.exists(store):
                os.makedirs(store)
            for path in imagepaths:
                origpath = path
                if "?" in path:
                    # remove everything after the ?
                    path = path.split("?")[0]
                if not path.startswith("http"):
                    path = getserver(url) + path
                name = path.split("/")[-1]
                if name and path.startswith("http"):
                    storename = os.path.join(store,name)
                    if not os.path.exists(storename):
to:

Code: Select all

        l = self.loadImages( message, self.repos[self.idx][1], self.repos[self.idx][0])
        if l:
            self.info_label.emit( l )
        self.stop = True

    def loadImages(self,message,url,wbName):
        
        "checks if the given page contains images and downloads them"

        # QTextBrowser cannot display online images. So we download them
        # here, and replace the image link in the html code with the
        # downloaded version

        imagepaths = re.findall("<img.*?src=\"(.*?)\"",message)
        if imagepaths:
            storedimages = []
            store = os.path.join(FreeCAD.getUserAppDataDir(),"AddonManager","Images")
            if not os.path.exists(store):
                os.makedirs(store)
            for path in imagepaths:
                origpath = path
                if "?" in path:
                    # remove everything after the ?
                    path = path.split("?")[0]
                if not path.startswith("http"):
                    path = getserver(url) + path
                name = path.split("/")[-1]
                if name and path.startswith("http"):
                    storename = os.path.join(store,name)
                    if len(storename) >= 260:
                        remainChars = 259 - (len(store) + len(wbName) + 1)
                        storename = os.path.join(store,wbName+name[-remainChars:])
                    if not os.path.exists(storename):
I've done quite a bit of testing but if anyone else wants to give it a try (modified file attached) or if there's a much more slick solution to try then I can test.
Attachments
addonmanager_workers.py
(29.13 KiB) Downloaded 53 times
Last edited by Syres on Wed Jun 19, 2019 10:22 am, edited 1 time in total.
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: Addon Manager improvements

Post by sgrogan »

Syres wrote: Tue Jun 18, 2019 5:46 pm I've done quite a bit of testing but if anyone else wants to give it a try (modified file attached) or if there's a much more slick solution to try then I can test.
Thanks, this work for Reinforcement.
This leaves me with only 2 WB's with problems;

SlopedPlanesMacro
Report View error

Code: Select all

AddonManager: Debug: Error retrieving image from https://github.com/caceres/SlopedPlanesMacro/raw/master/SlopedPlanes.png
github repo link from FreeCAD/addons repo https://github.com/luzpaz/SlopedPlanesM ... 65b662961f
Notice luzpav vs. caceres
Link to the only image in the README.md https://user-images.githubusercontent.c ... c10626.png

WebTools
Report View error

Code: Select all

AddonManager: Debug: Error retrieving image from https://camo.githubusercontent.com/9028281cd466416a12cac844af789d1e7c193dc3/68747470733a2f2f7777772e667265656361647765622e6f72672f77696b692f696d616765732f662f66382f5765625f536b657463686661622e706e67
github repo link from FreeCAD/addons repo https://github.com/yorikvanhavre/WebToo ... 4c21fefed5
Notice camo

TIA to all testing.
Link to first image in the README.md https://camo.githubusercontent.com/ba8a ... 742e706e67
"fight the good fight"
nic
Posts: 135
Joined: Thu Apr 18, 2019 1:14 pm
Location: France

Re: Addon Manager improvements

Post by nic »

Today's upgrade for FC0.19 (ubuntu 18.10 PPA) disables addon manager :

Code: Select all

During initialization the error No module named 'AddonManager_rc' occurred in /usr/share/freecad-daily/Mod/AddonManager/InitGui.py
Please look into the log file for further information
It indeed misses AddonManager_rc.py and I cannot find this module from github.

Code: Select all

OS: Ubuntu 18.10 (i3/i3)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Python version: 3.6.8
Qt version: 5.11.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/Switzerland (fr_CH)

% apt-cache policy freecad-daily                                                                         
freecad-daily:
  Installé : 0.19~pre1~201906182121~ubuntu18.10.1
  Candidat : 0.19~pre1~201906182121~ubuntu18.10.1
 Table de version :
 *** 0.19~pre1~201906182121~ubuntu18.10.1 500
        500 http://ppa.launchpad.net/freecad-maintainers/freecad-daily/ubuntu cosmic/main amd64 Packages
        500 http://ppa.launchpad.net/freecad-maintainers/freecad-daily/ubuntu cosmic/main i386 Packages
        100 /var/lib/dpkg/status

Syres
Veteran
Posts: 2893
Joined: Thu Aug 09, 2018 11:14 am

Re: Addon Manager improvements

Post by Syres »

sgrogan wrote: Tue Jun 18, 2019 9:35 pm This leaves me with only 2 WB's with problems;
To allow the other images with correct target URLs to load I removed the 'return None' around line 426 (obviously the incorrectly targeted images still need to created the Debug Error) so from:

Code: Select all

                        except:
                            print("AddonManager: Debug: Error retrieving image from",path)
                            return None
                        else:
to:

Code: Select all

                        except:
                            print("AddonManager: Debug: Error retrieving image from",path)
                        else:
I also added an attempt to open Readme.md as well as README.md.

Edit: I've updated the post from yesterday evening with the latest addonmanager_workers.py to include the above changes.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Addon Manager improvements

Post by Kunda1 »

Syres wrote: Wed Jun 19, 2019 10:21 am Edit: I've updated the post from yesterday evening with the latest addonmanager_workers.py to include the above changes.
Awesome, do you have these edits in a git branch that we can easily make a Pull Request from ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Locked