Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support to install package via pip #396

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/os/generic_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
53 changes: 53 additions & 0 deletions pkg/os/pip/common.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions pkg/os/pip/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package pip implements the pip integration
package pip