mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
feat: ios unmount
This commit is contained in:
+17
-11
@@ -2,13 +2,14 @@ package ios
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
|
||||||
"github.com/httprunner/httprunner/v5/internal/sdk"
|
"github.com/httprunner/httprunner/v5/internal/sdk"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,6 +32,14 @@ var mountCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if unmountDeveloperDiskImage {
|
||||||
|
err := device.UnmountImage()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unmount developer disk image failed: %v", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
images, errImage := device.ListImages()
|
images, errImage := device.ListImages()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("list device images failed: %v", err)
|
return fmt.Errorf("list device images failed: %v", err)
|
||||||
@@ -47,12 +56,6 @@ var mountCmd = &cobra.Command{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Str("dir", developerDiskImageDir).Msg("start to mount ios developer image")
|
|
||||||
|
|
||||||
if !builtin.IsFolderPathExists(developerDiskImageDir) {
|
|
||||||
return fmt.Errorf("developer disk image directory not exist: %s", developerDiskImageDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = device.AutoMountImage(developerDiskImageDir); err != nil {
|
if err = device.AutoMountImage(developerDiskImageDir); err != nil {
|
||||||
return fmt.Errorf("mount developer disk image failed: %s", err)
|
return fmt.Errorf("mount developer disk image failed: %s", err)
|
||||||
}
|
}
|
||||||
@@ -62,15 +65,18 @@ var mountCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultDeveloperDiskImageDir = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/"
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
developerDiskImageDir string
|
developerDiskImageDir string
|
||||||
listDeveloperDiskImage bool
|
listDeveloperDiskImage bool
|
||||||
|
unmountDeveloperDiskImage bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
home, _ := os.UserHomeDir()
|
||||||
|
defaultDeveloperDiskImageDir := path.Join(home, ".devimages")
|
||||||
|
|
||||||
mountCmd.Flags().BoolVar(&listDeveloperDiskImage, "list", false, "list developer disk images")
|
mountCmd.Flags().BoolVar(&listDeveloperDiskImage, "list", false, "list developer disk images")
|
||||||
|
mountCmd.Flags().BoolVar(&unmountDeveloperDiskImage, "reset", false, "unmount developer disk images")
|
||||||
mountCmd.Flags().StringVarP(&developerDiskImageDir, "dir", "d", defaultDeveloperDiskImageDir, "specify developer disk image directory")
|
mountCmd.Flags().StringVarP(&developerDiskImageDir, "dir", "d", defaultDeveloperDiskImageDir, "specify developer disk image directory")
|
||||||
mountCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
|
mountCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
|
||||||
iosRootCmd.AddCommand(mountCmd)
|
iosRootCmd.AddCommand(mountCmd)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2503071209
|
v5.0.0-beta-2503072308
|
||||||
|
|||||||
+17
-7
@@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
||||||
"github.com/httprunner/httprunner/v5/code"
|
"github.com/httprunner/httprunner/v5/code"
|
||||||
|
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||||
"github.com/httprunner/httprunner/v5/uixt/option"
|
"github.com/httprunner/httprunner/v5/uixt/option"
|
||||||
"github.com/httprunner/httprunner/v5/uixt/types"
|
"github.com/httprunner/httprunner/v5/uixt/types"
|
||||||
)
|
)
|
||||||
@@ -387,13 +388,7 @@ func (dev *IOSDevice) ListImages() (images []string, err error) {
|
|||||||
|
|
||||||
func (dev *IOSDevice) MountImage(imagePath string) (err error) {
|
func (dev *IOSDevice) MountImage(imagePath string) (err error) {
|
||||||
log.Info().Str("imagePath", imagePath).Msg("mount ios developer image")
|
log.Info().Str("imagePath", imagePath).Msg("mount ios developer image")
|
||||||
conn, err := imagemounter.NewImageMounter(dev.DeviceEntry)
|
err = imagemounter.MountImage(dev.DeviceEntry, imagePath)
|
||||||
if err != nil {
|
|
||||||
return errors.Wrap(code.DeviceConnectionError, err.Error())
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
err = conn.MountImage(imagePath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(code.DeviceConnectionError,
|
return errors.Wrapf(code.DeviceConnectionError,
|
||||||
"mount ios developer image failed: %v", err)
|
"mount ios developer image failed: %v", err)
|
||||||
@@ -402,8 +397,23 @@ func (dev *IOSDevice) MountImage(imagePath string) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dev *IOSDevice) UnmountImage() (err error) {
|
||||||
|
log.Info().Msg("unmount ios developer image")
|
||||||
|
err = imagemounter.UnmountImage(dev.DeviceEntry)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(code.DeviceConnectionError,
|
||||||
|
"unmount ios developer image failed: %v", err)
|
||||||
|
}
|
||||||
|
log.Info().Msg("unmount ios developer image success")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (dev *IOSDevice) AutoMountImage(baseDir string) (err error) {
|
func (dev *IOSDevice) AutoMountImage(baseDir string) (err error) {
|
||||||
log.Info().Str("baseDir", baseDir).Msg("auto mount ios developer image")
|
log.Info().Str("baseDir", baseDir).Msg("auto mount ios developer image")
|
||||||
|
if err := builtin.EnsureFolderExists(baseDir); err != nil {
|
||||||
|
return errors.Wrap(err, "create developer disk image directory failed")
|
||||||
|
}
|
||||||
|
|
||||||
imagePath, err := imagemounter.DownloadImageFor(dev.DeviceEntry, baseDir)
|
imagePath, err := imagemounter.DownloadImageFor(dev.DeviceEntry, baseDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(code.DeviceConnectionError,
|
return errors.Wrapf(code.DeviceConnectionError,
|
||||||
|
|||||||
Reference in New Issue
Block a user