How to run Addon Manager in Headless mode?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Post by Kunda1 »

sgrogan wrote: Tue Oct 22, 2019 11:09 pm Anything accessible from freecadcmd, should not use the Gui. In your particular case, maybe the progress bar can be replaced with "chasing dots" or whatever in the console.

Having this capability available headless opens up possibilities, CRON jobs for ex.
Well git does have a progress percentage indicator, hopefully I can expose that.

Can you elaborate on what other possibilities you see can be done via headless ?
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
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: How to run Addon Manager in Headless mode?

Post by sgrogan »

Kunda1 wrote: Wed Oct 23, 2019 9:56 pm Can you elaborate on what other possibilities you see can be done via headless ?
Basically auto-updates via a CRON job.

A CRON job runs the .AppImage update then your addon-ons update, wake up and your cutting edge FreeCAD :)
Probably needs some CLI switch to automatically accept the updates while the default would require user opt in.
Also your script could add something like my post here: https://github.com/looooo/freecad.gears/issues/1 so a re-start is not necessary.
"fight the good fight"
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Post by Kunda1 »

sgrogan wrote: I think something like this, from FreeCAD python console, should work?

Code: Select all

import git
repo = git.Repo(FreeCAD.getUserAppDataDir()+'/Mod/FCGear')
repo.git.pull('origin','develop')
repo.git.checkout('develop')
import importlib
importlib.reload(pygears)
EDIT: no restart required PY3.4+
Could this be used on any of the addons ?
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
User avatar
sgrogan
Veteran
Posts: 6499
Joined: Wed Oct 22, 2014 5:02 pm

Re: How to run Addon Manager in Headless mode?

Post by sgrogan »

Kunda1 wrote: Wed Oct 23, 2019 11:12 pm Could this be used on any of the addons ?
I haven't found time to test.
pygears is a "new style" module.
We need to test an "old style" module to see.
"fight the good fight"
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Post by Kunda1 »

Joel_graff wrote::bell:
@Joel_graff do you know about this?
https://forum.freecadweb.org/viewtopic. ... 10#p342766
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
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Post by Kunda1 »

What do folks recommend the best way to prompt users for input and execute said functions based on their choices ?

Code: Select all

1 - list all installed addons
2 - list all installed addons that have updates
3 - exit
Choose: 
FYI, pdb++ is awesome. Very helpful debugger.
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
User avatar
Joel_graff
Veteran
Posts: 1949
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: How to run Addon Manager in Headless mode?

Post by Joel_graff »

Kunda1 wrote: Thu Oct 24, 2019 12:33 am @Joel_graff do you know about this?
Not really. Looks neat, though. :)
FreeCAD Trails workbench for transportation engineering: https://www.github.com/joelgraff/freecad.trails

pivy_trackers 2D coin3D library: https://www.github.com/joelgraff/pivy_trackers
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to run Addon Manager in Headless mode?

Post by vocx »

Kunda1 wrote: Thu Oct 24, 2019 2:05 am What do folks recommend the best way to prompt users for input and execute said functions based on their choices ?
...
I don't think this is a priority.

Better to make it work first by just passing the name of the workbench, and a command like "install", "update", "remove".

Code: Select all

workbenches = list_workbenches(repo)
status = install_workbench(workbenches["Something"], "install")
Once you have this, then you can create a prompt or something like that. But the basic command should not have a prompt. A prompt won't let you automate things. A prompt is already a kind of GUI interface because it requires input from the user. So make sure the basic commands work with simple inputs and outputs.

By the way, I tried your code in the gist, https://gist.github.com/luzpaz/f3bfaaef ... 941f6ed7a5, and it works without issues. I just removed the if __name__, and ran it from the macro editor. It worked fine.

Code: Select all

start
List official available Addons:

x  3D_Printing_Tools -> https://github.com/mark1791/3D_Printing_Tools
x  A2plus -> https://github.com/kbwbe/A2plus
x  AirPlaneDesign -> https://github.com/FredsFactory/FreeCAD_AirPlaneDesign
x  animation -> https://github.com/microelly2/Animation
x  ArchTextures -> https://github.com/furti/FreeCAD-ArchTextures
x  assembly2 -> https://github.com/hamish2014/FreeCAD_assembly2
x  Assembly4 -> https://github.com/Zolko-123/FreeCAD_Assembly4
x  Autoload -> https://github.com/triplus/Autoload
x  BCFPlugin -> https://github.com/podestplatz/BCF-Plugin-FreeCAD
+  BIM -> https://github.com/yorikvanhavre/BIM_Workbench
x  BIMBots -> https://github.com/opensourceBIM/BIMbots-FreeCAD
x  BOLTSFC -> https://github.com/boltsparts/BOLTSFC
x  CADExchanger -> https://github.com/yorikvanhavre/CADExchanger
x  cadquery_module -> https://github.com/jmwright/cadquery-freecad-module
x  Cfd -> https://github.com/qingfengxia/Cfd
x  CfdOF -> https://github.com/jaheyns/CfdOF
x  CommandPanel -> https://github.com/triplus/CommandPanel
x  cura_engine -> https://github.com/cblt2l/FreeCAD-CuraEngine-Plugin
x  CurvedShapes -> https://github.com/chbergmann/CurvedShapesWorkbench
x  Curves -> https://github.com/tomate44/CurvesWB
x  Defeaturing -> https://github.com/easyw/Defeaturing_WB
x  DesignSPHysics -> https://github.com/DualSPHysics/DesignSPHysics
+  dodo -> https://github.com/oddtopus/dodo
x  drawing_dimensioning -> https://github.com/hamish2014/FreeCAD_drawing_dimensioning
x  dxf_library -> https://github.com/yorikvanhavre/Draft-dxf-importer
x  DynamicData -> https://github.com/mwganson/DynamicData
x  EM -> https://github.com/ediloren/EM-Workbench-for-FreeCAD
x  ExplodedAssembly -> https://github.com/JMG1/ExplodedAssembly
x  fasteners -> https://github.com/shaise/FreeCAD_FastenersWB
x  FCGear -> https://github.com/looooo/FCGear
x  flamingo -> https://github.com/oddtopus/flamingo
x  frame -> https://github.com/looooo/freecad_frame
x  GDT -> https://github.com/juanvanyo/FreeCAD-GDT
x  geodata -> https://github.com/microelly2/geodata
x  Geomatics -> https://github.com/HakanSeven12/FreeCAD-Geomatics-Workbench
x  Glass -> https://github.com/triplus/Glass
+  IconThemes -> https://github.com/triplus/IconThemes
x  InventorLoader -> https://github.com/jmplonka/InventorLoader
x  kerkythea -> https://github.com/marmni/FreeCAD-Kerkythea
x  kicadStepUpMod -> https://github.com/easyw/kicadStepUpMod
x  lattice2 -> https://github.com/DeepSOIC/Lattice2
x  Launcher -> https://github.com/triplus/Launcher
x  LCInterlocking -> https://github.com/execuc/LCInterlocking
x  Lithophane -> https://github.com/furti/FreeCAD-Lithophane
x  Manipulator -> https://github.com/easyw/Manipulator
x  MeshRemodel -> https://github.com/mwganson/MeshRemodel
x  MOOC -> https://github.com/wood-galaxy/mooc-workbench
x  NavigationIndicator -> https://github.com/triplus/NavigationIndicator
x  nurbs -> https://github.com/microelly2/freecad-nurbs
x  Part-o-magic -> https://github.com/DeepSOIC/Part-o-magic
x  parts_library -> https://github.com/FreeCAD/FreeCAD-library
x  pcb -> https://github.com/marmni/FreeCAD-PCB
x  persistenttoolbars -> https://github.com/triplus/PersistentToolbars
x  PieMenu -> https://github.com/triplus/PieMenu
x  Plot -> https://github.com/FreeCAD/freecad.plot
x  pluginloader -> https://github.com/microelly2/freecad-pluginloader
x  pyrate -> https://github.com/mess42/pyrate
x  reconstruction -> https://github.com/microelly2/reconstruction
+  Reinforcement -> https://github.com/amrit3701/FreeCAD-Reinforcement
x  Render -> https://github.com/FreeCAD/FreeCAD-render
x  Reporting -> https://github.com/furti/FreeCAD-Reporting
x  retr3d -> https://github.com/Maaphoo/Retr3d
x  SelectorToolbar -> https://github.com/triplus/SelectorToolbar
x  sheetmetal -> https://github.com/shaise/FreeCAD_SheetMetal
x  Ship -> https://github.com/FreeCAD/freecad.ship
x  ShortCuts -> https://github.com/triplus/ShortCuts
x  Silk -> https://github.com/edwardvmills/Silk
x  slic3r-tools -> https://github.com/limikael/freecad-slic3r-tools
x  SlopedPlanesMacro -> https://github.com/luzpaz/SlopedPlanesMacro
+  symbols_library -> https://github.com/FreeCAD/FreeCAD-symbols
x  TabBar -> https://github.com/triplus/TabBar
x  ThreadProfile -> https://github.com/mwganson/ThreadProfile
x  timber -> https://github.com/wood-galaxy/FreeCAD-Timber
x  ToolbarStyle -> https://github.com/triplus/ToolbarStyle
x  WebTools -> https://github.com/yorikvanhavre/WebTools
x  workfeature -> https://github.com/Rentlau/WorkFeature-WB
x  workfeature-macro -> https://github.com/Rentlau/WorkFeature
x  yaml-workspace -> https://github.com/Mambix/FreeCAD-yaml-workspace
	Legend:
	+ = Installed
	X = Not Installed
middle
end
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Post by Kunda1 »

vocx wrote: Thu Oct 24, 2019 3:13 am Better to make it work first by just passing the name of the workbench, and a command like "install", "update", "remove".
Code: Select all

Code: Select all

workbenches = list_workbenches(repo)
status = install_workbench(workbenches["Something"], "install")
Once you have this, then you can create a prompt or something like that. But the basic command should not have a prompt. A prompt won't let you automate things. A prompt is already a kind of GUI interface because it requires input from the user. So make sure the basic commands work with simple inputs and outputs.
So I should test for command line parameters

Code: Select all

argv
instead of waiting for any user input from within the script?

so something like

Code: Select all

$ ./freecadcmd AddonManagerHeadless.py -h
list - list official workbenches (both installed and non-installed, if installed then which have updates)
update-all - update all workbenches that have updates
update <wb-name> - update specific workbench
add <wb-name> - add a workbench
remove <wb-name> - remove a workbench
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
vocx
Veteran
Posts: 5197
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to run Addon Manager in Headless mode?

Post by vocx »

Kunda1 wrote: Thu Oct 24, 2019 11:23 am ...
So I should test for command line parameters

Code: Select all

argv
...
Yes, that's a better approach. As I said, think of a way that it can do something by itself, just with the provided input. That will allow you to truly perform automatic tasks without user input.

Ideally, it should be a Python library, which can be used by a Python-based command.

In a Python-based command you are assuming that you will run the AddonManagerHeadless.py module by itself.

Code: Select all

# This is a Python-based command
AddonManagerHeadless --repo https://something --install A2plus
What I prefer is that you develop it into an importable library.

Code: Select all

# This is a Python library
import AddonManagerHeadless as AM
repo = AM.set_repo("https://something")
AM.install(repo, "A2plus")
Obviously, you can develop the library first, and then use it inside a Python-based command.

Code: Select all

import sys
import AddonManagerHeadless as AM

if sys.argv[1] == "--repo":
    repo = AM.set_repo(argv[2])
if sys.argv[3] == "--install":
    installed = AM.install(argv[4])
Something like that.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Post Reply