Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 867654 - Add ability to copy and move files to devicemanager, r=ahal
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastiaan de Haan authored and ahal-test committed Nov 20, 2013
1 parent 10d1050 commit 57a1c6d
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mozdevice/mozdevice/devicemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,24 @@ def removeDir(self, remoteDirname):
Does a recursive delete of directory on the device: rm -Rf remoteDirname.
"""

@abstractmethod
def moveTree(self, source, destination):
"""
Does a move of the file or directory on the device.
:param source: Path to the original file or directory
:param destination: Path to the destination file or directory
"""

@abstractmethod
def copyTree(self, source, destination):
"""
Does a copy of the file or directory on the device.
:param source: Path to the original file or directory
:param destination: Path to the destination file or directory
"""

@abstractmethod
def chmodDir(self, remoteDirname, mask="777"):
"""
Expand Down
6 changes: 6 additions & 0 deletions mozdevice/mozdevice/devicemanagerADB.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ def removeDir(self, remoteDir):
else:
self.removeFile(remoteDir.strip())

def moveTree(self, source, destination):
self._checkCmd(["shell", "mv", source, destination])

def copyTree(self, source, destination):
self._checkCmd(["shell", "dd", "if=%s" % source, "of=%s" % destination])

def listFiles(self, rootdir):
p = self._runCmd(["shell", "ls", "-a", rootdir])
data = p.stdout.readlines()
Expand Down
6 changes: 6 additions & 0 deletions mozdevice/mozdevice/devicemanagerSUT.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,12 @@ def removeDir(self, remoteDir):
if self.dirExists(remoteDir):
self._runCmds([{ 'cmd': 'rmdr ' + remoteDir }])

def moveTree(self, source, destination):
self._runCmds([{ 'cmd': 'mv %s %s' % (source, destination) }])

def copyTree(self, source, destination):
self._runCmds([{ 'cmd': 'dd if=%s of=%s' % (source, destination) }])

def getProcessList(self):
data = self._runCmds([{ 'cmd': 'ps' }])

Expand Down
2 changes: 2 additions & 0 deletions mozdevice/tests/manifest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ skip-if = os == 'win'
[sut_app.py]
[sut_basic.py]
[sut_chmod.py]
[sut_copytree.py]
[sut_fileExists.py]
[sut_fileMethods.py]
[sut_info.py]
Expand All @@ -12,6 +13,7 @@ skip-if = os == 'win'
[sut_list.py]
[sut_logcat.py]
[sut_mkdir.py]
[sut_movetree.py]
[sut_ps.py]
[sut_push.py]
[sut_pull.py]
Expand Down
65 changes: 65 additions & 0 deletions mozdevice/tests/sut_copytree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import mozdevice
import mozlog
import unittest
from sut import MockAgent

class CopyTreeTest(unittest.TestCase):
def test_copyFile(self):
commands = [('dd if=/mnt/sdcard/tests/test.txt of=/mnt/sdcard/tests/test2.txt', ''),
('isdir /mnt/sdcard/tests', 'TRUE'),
('cd /mnt/sdcard/tests', ''),
('ls', 'test.txt\ntest2.txt')]

m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG)

self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/test.txt',
'/mnt/sdcard/tests/test2.txt'))
expected = (commands[3][1].strip()).split('\n')
self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests'))

def test_copyDir(self):
commands = [('dd if=/mnt/sdcard/tests/foo of=/mnt/sdcard/tests/bar', ''),
('isdir /mnt/sdcard/tests', 'TRUE'),
('cd /mnt/sdcard/tests', ''),
('ls', 'foo\nbar')]

m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port,
logLevel=mozlog.DEBUG)

self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/foo',
'/mnt/sdcard/tests/bar'))
expected = (commands[3][1].strip()).split('\n')
self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests'))

def test_copyNonEmptyDir(self):
commands = [('isdir /mnt/sdcard/tests/foo/bar', 'TRUE'),
('dd if=/mnt/sdcard/tests/foo of=/mnt/sdcard/tests/foo2', ''),
('isdir /mnt/sdcard/tests', 'TRUE'),
('cd /mnt/sdcard/tests', ''),
('ls', 'foo\nfoo2'),
('isdir /mnt/sdcard/tests/foo2', 'TRUE'),
('cd /mnt/sdcard/tests/foo2', ''),
('ls', 'bar')]

m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port,
logLevel=mozlog.DEBUG)

self.assertTrue(d.dirExists('/mnt/sdcard/tests/foo/bar'))
self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/foo',
'/mnt/sdcard/tests/foo2'))
expected = (commands[4][1].strip()).split('\n')
self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests'))
self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2/bar'))

if __name__ == "__main__":
unittest.main()
63 changes: 63 additions & 0 deletions mozdevice/tests/sut_movetree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import mozdevice
import mozlog
import unittest
from sut import MockAgent

class MoveTreeTest(unittest.TestCase):
def test_moveFile(self):
commands = [('mv /mnt/sdcard/tests/test.txt /mnt/sdcard/tests/test1.txt', ''),
('isdir /mnt/sdcard/tests', 'TRUE'),
('cd /mnt/sdcard/tests', ''),
('ls', 'test1.txt'),
('isdir /mnt/sdcard/tests', 'TRUE'),
('cd /mnt/sdcard/tests', ''),
('ls', 'test1.txt')]

m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG)
self.assertEqual(None, d.moveTree('/mnt/sdcard/tests/test.txt',
'/mnt/sdcard/tests/test1.txt'))
self.assertFalse(d.fileExists('/mnt/sdcard/tests/test.txt'))
self.assertTrue(d.fileExists('/mnt/sdcard/tests/test1.txt'))

def test_moveDir(self):
commands = [("mv /mnt/sdcard/tests/foo /mnt/sdcard/tests/bar", ""),
('isdir /mnt/sdcard/tests', 'TRUE'),
('cd /mnt/sdcard/tests', ''),
('ls', 'bar')]

m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=mozlog.DEBUG)
self.assertEqual(None, d.moveTree('/mnt/sdcard/tests/foo',
'/mnt/sdcard/tests/bar'))
self.assertTrue(d.fileExists('/mnt/sdcard/tests/bar'))

def test_moveNonEmptyDir(self):
commands = [('isdir /mnt/sdcard/tests/foo/bar', 'TRUE'),
('mv /mnt/sdcard/tests/foo /mnt/sdcard/tests/foo2', ''),
('isdir /mnt/sdcard/tests', 'TRUE'),
('cd /mnt/sdcard/tests', ''),
('ls', 'foo2'),
('isdir /mnt/sdcard/tests/foo2', 'TRUE'),
('cd /mnt/sdcard/tests/foo2', ''),
('ls', 'bar')]

m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port,
logLevel=mozlog.DEBUG)

self.assertTrue(d.dirExists('/mnt/sdcard/tests/foo/bar'))
self.assertEqual(None, d.moveTree('/mnt/sdcard/tests/foo',
'/mnt/sdcard/tests/foo2'))
self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2'))
self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2/bar'))

if __name__ == "__main__":
unittest.main()

0 comments on commit 57a1c6d

Please sign in to comment.