aboutsummaryrefslogtreecommitdiff
path: root/build/lib.linux-x86_64-2.7/lava_android_test/repository.py
diff options
context:
space:
mode:
authorYongqin Liu <yongqin.liu@linaro.org>2015-01-03 17:46:21 +0800
committerYongqin Liu <yongqin.liu@linaro.org>2015-01-03 17:46:21 +0800
commitcf7013d6e23f0a0da3bcae5fb9d8e20639b1d21f (patch)
tree4888505a53fc2070d376945391ae48bbee333166 /build/lib.linux-x86_64-2.7/lava_android_test/repository.py
downloadlava-android-test-cf7013d6e23f0a0da3bcae5fb9d8e20639b1d21f.tar.gz
first commit
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
Diffstat (limited to 'build/lib.linux-x86_64-2.7/lava_android_test/repository.py')
-rw-r--r--build/lib.linux-x86_64-2.7/lava_android_test/repository.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/build/lib.linux-x86_64-2.7/lava_android_test/repository.py b/build/lib.linux-x86_64-2.7/lava_android_test/repository.py
new file mode 100644
index 0000000..ce57470
--- /dev/null
+++ b/build/lib.linux-x86_64-2.7/lava_android_test/repository.py
@@ -0,0 +1,83 @@
+# Copyright (C) 2012 Linaro Limited
+#
+# Author: Linaro Validation Team <linaro-dev@lists.linaro.org>
+#
+# This file is part of LAVA Android Test.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import os
+import subprocess
+
+from lava_android_test import utils
+
+
+class RepositoryError(Exception):
+ """
+ Raise this for repository related errors
+ """
+
+
+class Repository(object):
+ '''
+ Base class for all repository class used to checkout files.
+ This class and sub classes are base the repository command.
+ '''
+
+ def __init__(self, url, repo_type, cmds=[]):
+ self.url = url
+ self.repo_type = repo_type
+ self.check_cmds_exist(cmds)
+
+ def checkout(self, target_dir=None):
+ """
+ Checkout this repository to the specified the target_dir directory
+ """
+ raise NotImplementedError()
+
+ def check_cmds_exist(self, cmds=[]):
+ """
+ check whether the necessary commands are existing.
+ """
+ for cmd in cmds:
+ if not utils.check_command_exist(cmd):
+ raise RepositoryError(("The necessary command(%) does not"
+ " exist, Or can't be seen from path")
+ % cmd)
+
+
+class GitRepository(Repository):
+
+ git_cmd = 'git'
+
+ def __init__(self, url):
+ super(GitRepository, self).__init__(url, 'git', [self.git_cmd])
+
+ def checkout(self, target_dir=None):
+ """
+ Checkout this git repository to the specified the target_dir directory
+ """
+ cmds = []
+ if not target_dir:
+ cmds = [self.git_cmd, 'clone', self.url]
+
+ else:
+ if not os.path.exists(target_dir):
+ os.makedirs(target_dir)
+ cmds = [self.git_cmd, 'clone', self.url, target_dir]
+
+ rc = subprocess.call(cmds)
+ if rc != 0:
+ raise RepositoryError(("Failed to clone the specified "
+ "repository() with exist staus=%d")
+ % (self.url, rc))