How to run Addon Manager in Headless mode?

Need help, or want to share a macro? Post here!
User avatar
Kunda1
Posts: 5927
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Postby Kunda1 » Wed Oct 23, 2019 9:56 pm

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 ?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
sgrogan
Posts: 5469
Joined: Wed Oct 22, 2014 5:02 pm

Re: How to run Addon Manager in Headless mode?

Postby sgrogan » Wed Oct 23, 2019 10:22 pm

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.
User avatar
Kunda1
Posts: 5927
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Postby Kunda1 » Wed Oct 23, 2019 11:12 pm

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 ?
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
sgrogan
Posts: 5469
Joined: Wed Oct 22, 2014 5:02 pm

Re: How to run Addon Manager in Headless mode?

Postby sgrogan » Wed Oct 23, 2019 11:25 pm

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.
User avatar
Kunda1
Posts: 5927
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Postby Kunda1 » Thu Oct 24, 2019 12:33 am

Joel_graff wrote::bell:
@Joel_graff do you know about this?
https://forum.freecadweb.org/viewtopic. ... 10#p342766
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
Kunda1
Posts: 5927
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Postby Kunda1 » 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 ?

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.
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
Joel_graff
Posts: 1578
Joined: Fri Apr 28, 2017 4:23 pm
Contact:

Re: How to run Addon Manager in Headless mode?

Postby Joel_graff » Thu Oct 24, 2019 2:51 am

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
Posts: 1871
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to run Addon Manager in Headless mode?

Postby vocx » Thu Oct 24, 2019 3:13 am

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
User avatar
Kunda1
Posts: 5927
Joined: Thu Jan 05, 2017 9:03 pm

Re: How to run Addon Manager in Headless mode?

Postby Kunda1 » Thu Oct 24, 2019 11:23 am

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
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
vocx
Posts: 1871
Joined: Thu Oct 18, 2018 9:18 pm

Re: How to run Addon Manager in Headless mode?

Postby vocx » Thu Oct 24, 2019 3:32 pm

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.