Skip to content

Commit

Permalink
fix: fix for pyhton path and removed python SDK dependency if PDfM fr…
Browse files Browse the repository at this point in the history
…om 19.0.0
  • Loading branch information
sai-kumar-peddireddy committed Jul 26, 2023
1 parent b9dec65 commit 13e57f7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
51 changes: 43 additions & 8 deletions builder/parallels/common/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ package common
import (
"fmt"
"log"
"os"
"os/exec"
"regexp"
"runtime"
"strconv"
"strings"

"github.com/hashicorp/go-version"
)

// Driver is the interface that talks to Parallels and performs certain
Expand Down Expand Up @@ -78,23 +82,20 @@ func NewDriver() (Driver, error) {
"Parallels builder works only on \"darwin\" platform!")
}

cmd := exec.Command("/usr/bin/python3", "-c", `import prlsdkapi`)
err := cmd.Run()
if err != nil {
return nil, fmt.Errorf(
"Parallels Virtualization SDK is not installed")
}

if prlctlPath == "" {
var err error
prlctlPath, err = exec.LookPath("prlctl")
if err != nil {
return nil, err
}
}

log.Printf("prlctl path: %s", prlctlPath)

err := checkforPythonSDK(prlctlPath)
if err != nil {
return nil, err
}

if prlsrvctlPath == "" {
var err error
prlsrvctlPath, err = exec.LookPath("prlsrvctl")
Expand Down Expand Up @@ -151,3 +152,37 @@ func NewDriver() (Driver, error) {
"Unable to initialize any driver. Supported Parallels Desktop versions: "+
"%s\n", strings.Join(supportedVersions, ", "))
}

// checks for pyhton SDK if if version is less than 19.0.0

func checkforPythonSDK(prlctlPath string) error {

out, err := exec.Command(prlctlPath, "--version").Output()
if err != nil {
return err
}

versionRe := regexp.MustCompile(`prlctl version (\d+\.\d+.\d+)`)
matches := versionRe.FindStringSubmatch(string(out))
if matches == nil {
return fmt.Errorf(
"Could not find Parallels Desktop version in output:\n%s", string(out))
}

prlctlCurrVersionStr := matches[1]
prlctlCurrVersion, _ := version.NewVersion(prlctlCurrVersionStr)
v2, verErr := version.NewVersion("19.0.0")

if verErr != nil && prlctlCurrVersion.LessThan(v2) {
pyPath := os.Getenv("PYTHONPATH")
os.Setenv("PYTHONPATH", pyPath+":/Library/Frameworks/ParallelsVirtualizationSDK.framework/Versions/Current/Libraries/Python/3.7")
cmd := exec.Command("/usr/bin/python3", "-c", `import prlsdkapi`)
err = cmd.Run()
if err != nil {
return fmt.Errorf(
"Parallels Virtualization SDK is not installed")
}
}

return nil
}
2 changes: 1 addition & 1 deletion builder/parallels/common/driver_9.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (d *Parallels9Driver) SendKeyScanCodes(vmName string, codes ...string) erro
prlctlCurrVersion, _ := version.NewVersion(prlctlCurrVersionStr)
v2, _ := version.NewVersion("19.0.0")

if verErr != nil || prlctlCurrVersion.LessThan(v2) {
if verErr != nil && prlctlCurrVersion.LessThan(v2) {

f, err := tmp.File("prltype")
if err != nil {
Expand Down

0 comments on commit 13e57f7

Please sign in to comment.