feat: Improved the python installer, added an example
This commit is contained in:
@@ -2,27 +2,31 @@ module python
|
||||
|
||||
import freeflowuniverse.herolib.osal
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
import freeflowuniverse.herolib.installers.base
|
||||
import freeflowuniverse.herolib.core.texttools
|
||||
import freeflowuniverse.herolib.installers.ulist
|
||||
import os
|
||||
|
||||
|
||||
//////////////////// following actions are not specific to instance of the object
|
||||
|
||||
// checks if a certain version or above is installed
|
||||
fn installed_() !bool {
|
||||
fn installed() !bool {
|
||||
res := os.execute('python3 --version')
|
||||
if res.exit_code != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
r := res.output.split_into_lines().filter(it.trim_space().len > 0)
|
||||
if r.len != 1 {
|
||||
return error("couldn't parse pnpm version.\n${res.output}")
|
||||
}
|
||||
|
||||
if texttools.version(r[0].all_after_first('ython')) >= texttools.version(version) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -32,10 +36,15 @@ fn ulist_get() !ulist.UList {
|
||||
return ulist.UList{}
|
||||
}
|
||||
|
||||
fn upload_() ! {
|
||||
// uploads to S3 server if configured
|
||||
fn upload() ! {
|
||||
// installers.upload(
|
||||
// cmdname: 'python'
|
||||
// source: '${gitpath}/target/x86_64-unknown-linux-musl/release/python'
|
||||
// )!
|
||||
}
|
||||
|
||||
fn install_() ! {
|
||||
fn install() ! {
|
||||
console.print_header('install python')
|
||||
base.install()!
|
||||
|
||||
@@ -44,7 +53,7 @@ fn install_() ! {
|
||||
if pl == .arch {
|
||||
osal.package_install('python-pipx,sqlite')!
|
||||
} else if pl == .ubuntu {
|
||||
osal.package_install('python-pipx,sqlite')!
|
||||
osal.package_install('pipx,sqlite')!
|
||||
} else if pl == .osx {
|
||||
osal.package_install('pipx,sqlite')!
|
||||
} else {
|
||||
@@ -53,36 +62,17 @@ fn install_() ! {
|
||||
osal.execute_silent('pipx install uv')!
|
||||
}
|
||||
|
||||
fn destroy_() ! {
|
||||
panic('implement')
|
||||
|
||||
// mut systemdfactory := systemd.new()!
|
||||
// systemdfactory.destroy("zinit")!
|
||||
|
||||
// osal.process_kill_recursive(name:'zinit')!
|
||||
// osal.cmd_delete('zinit')!
|
||||
|
||||
// osal.package_remove('
|
||||
// podman
|
||||
// conmon
|
||||
// buildah
|
||||
// skopeo
|
||||
// runc
|
||||
// ')!
|
||||
|
||||
// //will remove all paths where go/bin is found
|
||||
// osal.profile_path_add_remove(paths2delete:"go/bin")!
|
||||
|
||||
// osal.rm("
|
||||
// podman
|
||||
// conmon
|
||||
// buildah
|
||||
// skopeo
|
||||
// runc
|
||||
// /var/lib/containers
|
||||
// /var/lib/podman
|
||||
// /var/lib/buildah
|
||||
// /tmp/podman
|
||||
// /tmp/conmon
|
||||
// ")!
|
||||
fn destroy() ! {
|
||||
console.print_header('destroy python')
|
||||
osal.package_remove('python3')!
|
||||
pl := core.platform()!
|
||||
if pl == .arch {
|
||||
osal.package_remove('pipx,sqlite')!
|
||||
} else if pl == .ubuntu {
|
||||
osal.package_remove('pipx,sqlite')!
|
||||
} else if pl == .osx {
|
||||
osal.package_remove('pipx,sqlite')!
|
||||
} else {
|
||||
return error('only support osx, arch & ubuntu.')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
module python
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.sysadmin.startupmanager
|
||||
import freeflowuniverse.herolib.osal.zinit
|
||||
import time
|
||||
|
||||
__global (
|
||||
python_global map[string]&Python
|
||||
@@ -45,11 +42,11 @@ pub fn play(args_ PlayArgs) ! {
|
||||
reset := p.get_default_false('reset')
|
||||
if other_action.name == 'destroy' || reset {
|
||||
console.print_debug('install action python.destroy')
|
||||
// destroy()!
|
||||
destroy()!
|
||||
}
|
||||
if other_action.name == 'install' {
|
||||
console.print_debug('install action python.install')
|
||||
// install()!
|
||||
install()!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,14 +86,14 @@ pub mut:
|
||||
|
||||
pub fn (mut self Python) install(args InstallArgs) ! {
|
||||
switch(self.name)
|
||||
// if args.reset || (!installed()!) {
|
||||
// install()!
|
||||
// }
|
||||
if args.reset || (!installed()!) {
|
||||
install()!
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (mut self Python) destroy() ! {
|
||||
switch(self.name)
|
||||
// destroy()!
|
||||
destroy()!
|
||||
}
|
||||
|
||||
// switch instance to be used for python
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
module python
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import os
|
||||
|
||||
pub const version = '3.12.0'
|
||||
@@ -14,14 +15,24 @@ pub mut:
|
||||
name string = 'default'
|
||||
}
|
||||
|
||||
fn obj_init(obj_ Python) !Python {
|
||||
// never call get here, only thing we can do here is work on object itself
|
||||
mut obj := obj_
|
||||
panic('implement')
|
||||
return obj
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ Python) !Python {
|
||||
mut mycfg := mycfg_
|
||||
return mycfg
|
||||
}
|
||||
|
||||
// called before start if done
|
||||
fn configure() ! {
|
||||
// mut installer := get()!
|
||||
}
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj Python) !string {
|
||||
return encoderhero.encode[Python](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !Python {
|
||||
mut obj := encoderhero.decode[Python](heroscript)!
|
||||
return obj
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user