From bc0467abf8072e412d624461b98a23e2dd7765e1 Mon Sep 17 00:00:00 2001 From: rick Date: Tue, 23 May 2023 18:51:13 +0800 Subject: [PATCH] feat: support to install package via pip --- pkg/os/generic_installer.go | 6 +++++ pkg/os/pip/common.go | 53 +++++++++++++++++++++++++++++++++++++ pkg/os/pip/doc.go | 2 ++ 3 files changed, 61 insertions(+) create mode 100755 pkg/os/pip/common.go create mode 100755 pkg/os/pip/doc.go diff --git a/pkg/os/generic_installer.go b/pkg/os/generic_installer.go index 07afc4c..5a5fd2c 100644 --- a/pkg/os/generic_installer.go +++ b/pkg/os/generic_installer.go @@ -17,6 +17,7 @@ import ( "github.com/linuxsuren/http-downloader/pkg/os/apk" "github.com/linuxsuren/http-downloader/pkg/os/dnf" "github.com/linuxsuren/http-downloader/pkg/os/npm" + "github.com/linuxsuren/http-downloader/pkg/os/pip" "github.com/linuxsuren/http-downloader/pkg/os/scoop" "github.com/linuxsuren/http-downloader/pkg/os/snap" "github.com/linuxsuren/http-downloader/pkg/os/winget" @@ -205,6 +206,11 @@ func GenericInstallerRegistry(configFile string, registry core.InstallerRegistry Name: genericPackage.Name, Execer: defaultExecer, } + case pip.Tool: + genericPackage.CommonInstaller = &pip.CommonInstaller{ + Name: genericPackage.Name, + Execer: defaultExecer, + } default: genericPackage.CommonInstaller = &generic.CommonInstaller{ Name: genericPackage.Name, diff --git a/pkg/os/pip/common.go b/pkg/os/pip/common.go new file mode 100755 index 0000000..303c25b --- /dev/null +++ b/pkg/os/pip/common.go @@ -0,0 +1,53 @@ +package pip + +import ( + "fmt" + + fakeruntime "github.com/linuxsuren/go-fake-runtime" +) + +// Tool is the tool name of this intergration +const Tool = "pip" + +// CommonInstaller is the installer of Conntrack in CentOS +type CommonInstaller struct { + Name string + Execer fakeruntime.Execer +} + +// Available check if support current platform +func (d *CommonInstaller) Available() (ok bool) { + _, err := d.Execer.LookPath(Tool) + ok = err == nil + return +} + +// Install installs the Conntrack +func (d *CommonInstaller) Install() (err error) { + err = d.Execer.RunCommand(Tool, "install", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple", d.Name) + return +} + +// Uninstall uninstalls the Conntrack +func (d *CommonInstaller) Uninstall() (err error) { + err = d.Execer.RunCommand(Tool, "uninstall", d.Name) + return +} + +// WaitForStart waits for the service be started +func (d *CommonInstaller) WaitForStart() (ok bool, err error) { + ok = true + return +} + +// Start starts the Conntrack service +func (d *CommonInstaller) Start() error { + fmt.Println("not supported yet") + return nil +} + +// Stop stops the Conntrack service +func (d *CommonInstaller) Stop() error { + fmt.Println("not supported yet") + return nil +} diff --git a/pkg/os/pip/doc.go b/pkg/os/pip/doc.go new file mode 100755 index 0000000..f416104 --- /dev/null +++ b/pkg/os/pip/doc.go @@ -0,0 +1,2 @@ +// Package pip implements the pip integration +package pip