showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | |
| 3 | """ |
| 4 | Utility to upload or remove the packages from the packages repository. |
| 5 | """ |
| 6 | |
Dale Curtis | 6ad3319 | 2011-07-06 18:04:50 -0700 | [diff] [blame] | 7 | import logging, optparse, os, shutil, sys, tempfile |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 8 | import common |
| 9 | from autotest_lib.client.common_lib import utils as client_utils |
jadmanski | c27c231 | 2009-08-05 20:58:51 +0000 | [diff] [blame] | 10 | from autotest_lib.client.common_lib import global_config, error |
Allen Li | bf0c441 | 2017-02-03 16:49:53 -0800 | [diff] [blame] | 11 | from autotest_lib.client.common_lib import packages |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 12 | from autotest_lib.server import utils as server_utils |
| 13 | |
| 14 | c = global_config.global_config |
showard | f6547fe | 2009-07-08 22:58:53 +0000 | [diff] [blame] | 15 | logging.basicConfig(level=logging.DEBUG) |
mbligh | dbfc4e3 | 2008-08-22 18:08:07 +0000 | [diff] [blame] | 16 | |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 17 | ACTION_REMOVE = 'remove' |
| 18 | ACTION_UPLOAD = 'upload' |
| 19 | ACTION_TAR_ONLY = 'tar_only' |
| 20 | |
mbligh | dbfc4e3 | 2008-08-22 18:08:07 +0000 | [diff] [blame] | 21 | def get_exclude_string(client_dir): |
| 22 | ''' |
| 23 | Get the exclude string for the tar command to exclude specific |
| 24 | subdirectories inside client_dir. |
Christopher Wiley | 8d357f1 | 2013-11-06 15:14:37 -0800 | [diff] [blame] | 25 | For profilers we need to exclude everything except the __init__.py |
mbligh | dbfc4e3 | 2008-08-22 18:08:07 +0000 | [diff] [blame] | 26 | file so that the profilers can be imported. |
| 27 | ''' |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 28 | exclude_string = ('--exclude="deps/*" --exclude="tests/*" ' |
| 29 | '--exclude="site_tests/*" --exclude="**.pyc"') |
mbligh | dbfc4e3 | 2008-08-22 18:08:07 +0000 | [diff] [blame] | 30 | |
| 31 | # Get the profilers directory |
| 32 | prof_dir = os.path.join(client_dir, 'profilers') |
| 33 | |
| 34 | # Include the __init__.py file for the profilers and exclude all its |
| 35 | # subdirectories |
| 36 | for f in os.listdir(prof_dir): |
| 37 | if os.path.isdir(os.path.join(prof_dir, f)): |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 38 | exclude_string += ' --exclude="profilers/%s"' % f |
mbligh | dbfc4e3 | 2008-08-22 18:08:07 +0000 | [diff] [blame] | 39 | |
| 40 | # The '.' here is needed to zip the files in the current |
| 41 | # directory. We use '-C' for tar to change to the required |
| 42 | # directory i.e. src_dir and then zip up the files in that |
| 43 | # directory(which is '.') excluding the ones in the exclude_dirs |
| 44 | exclude_string += " ." |
| 45 | |
Christopher Wiley | ef62ed4 | 2013-11-21 13:49:02 -0800 | [diff] [blame] | 46 | # TODO(milleral): This is sad and ugly. http://crbug.com/258161 |
| 47 | # Surprisingly, |exclude_string| actually means argument list, and |
| 48 | # we'd like to package up the current global_config.ini also, so let's |
| 49 | # just tack it on here. |
| 50 | # Also note that this only works because tar prevents us from un-tarring |
| 51 | # files into parent directories. |
| 52 | exclude_string += " ../global_config.ini" |
| 53 | |
mbligh | dbfc4e3 | 2008-08-22 18:08:07 +0000 | [diff] [blame] | 54 | return exclude_string |
| 55 | |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 56 | |
| 57 | def parse_args(): |
| 58 | parser = optparse.OptionParser() |
| 59 | parser.add_option("-d", "--dependency", help="package the dependency" |
| 60 | " from client/deps directory and upload to the repo", |
| 61 | dest="dep") |
| 62 | parser.add_option("-p", "--profiler", help="package the profiler " |
| 63 | "from client/profilers directory and upload to the repo", |
| 64 | dest="prof") |
| 65 | parser.add_option("-t", "--test", help="package the test from client/tests" |
| 66 | " or client/site_tests and upload to the repo.", |
| 67 | dest="test") |
| 68 | parser.add_option("-c", "--client", help="package the client " |
| 69 | "directory alone without the tests, deps and profilers", |
| 70 | dest="client", action="store_true", default=False) |
| 71 | parser.add_option("-f", "--file", help="simply uploads the specified" |
| 72 | "file on to the repo", dest="file") |
| 73 | parser.add_option("-r", "--repository", help="the URL of the packages" |
| 74 | "repository location to upload the packages to.", |
| 75 | dest="repo", default=None) |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 76 | parser.add_option("-o", "--output_dir", help="the output directory" |
| 77 | "to place tarballs and md5sum files in.", |
| 78 | dest="output_dir", default=None) |
| 79 | parser.add_option("-a", "--action", help="the action to perform", |
| 80 | dest="action", choices=(ACTION_UPLOAD, ACTION_REMOVE, |
| 81 | ACTION_TAR_ONLY), default=None) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 82 | parser.add_option("--all", help="Upload all the files locally " |
| 83 | "to all the repos specified in global_config.ini. " |
| 84 | "(includes the client, tests, deps and profilers)", |
| 85 | dest="all", action="store_true", default=False) |
| 86 | |
| 87 | options, args = parser.parse_args() |
| 88 | return options, args |
| 89 | |
Prashant Malani | f7b2f99 | 2017-04-05 11:08:08 -0700 | [diff] [blame] | 90 | def get_build_dir(name, dest_dir, pkg_type): |
| 91 | """Method to generate the build directory where the tarball and checksum |
| 92 | is stored. The following package types are handled: test, dep, profiler. |
| 93 | Package type 'client' is not handled. |
| 94 | """ |
| 95 | if pkg_type == 'client': |
| 96 | # NOTE: The "tar_only" action for pkg_type "client" has no use |
| 97 | # case yet. No known invocations of packager.py with |
| 98 | # --action=tar_only send in clients in the command line. Please |
| 99 | # confirm the behaviour is expected before this type is enabled for |
| 100 | # "tar_only" actions. |
| 101 | print ('Tar action not supported for pkg_type= %s, name = %s' % |
| 102 | pkg_type, name) |
| 103 | return None |
| 104 | # For all packages, the work-dir should have 'client' appended to it. |
| 105 | base_build_dir = os.path.join(dest_dir, 'client') |
| 106 | if pkg_type == 'test': |
| 107 | build_dir = os.path.join(get_test_dir(name, base_build_dir), name) |
| 108 | else: |
| 109 | # For profiler and dep, we append 's', and then append the name. |
| 110 | # TODO(pmalani): Make this less fiddly? |
| 111 | build_dir = os.path.join(base_build_dir, pkg_type + 's', name) |
| 112 | return build_dir |
| 113 | |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 114 | def process_packages(pkgmgr, pkg_type, pkg_names, src_dir, |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 115 | action, dest_dir=None): |
| 116 | """Method to upload or remove package depending on the flag passed to it. |
| 117 | |
| 118 | If tar_only is set to True, this routine is solely used to generate a |
| 119 | tarball and compute the md5sum from that tarball. |
| 120 | If the tar_only flag is True, then the remove flag is ignored. |
| 121 | """ |
mbligh | dbfc4e3 | 2008-08-22 18:08:07 +0000 | [diff] [blame] | 122 | exclude_string = ' .' |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 123 | names = [p.strip() for p in pkg_names.split(',')] |
| 124 | for name in names: |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 125 | print "process_packages: Processing %s ... " % name |
Dale Curtis | 6ad3319 | 2011-07-06 18:04:50 -0700 | [diff] [blame] | 126 | if pkg_type == 'client': |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 127 | pkg_dir = src_dir |
Dale Curtis | 6ad3319 | 2011-07-06 18:04:50 -0700 | [diff] [blame] | 128 | exclude_string = get_exclude_string(pkg_dir) |
| 129 | elif pkg_type == 'test': |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 130 | # if the package is a test then look whether it is in client/tests |
| 131 | # or client/site_tests |
| 132 | pkg_dir = os.path.join(get_test_dir(name, src_dir), name) |
| 133 | else: |
| 134 | # for the profilers and deps |
| 135 | pkg_dir = os.path.join(src_dir, name) |
| 136 | |
| 137 | pkg_name = pkgmgr.get_tarball_name(name, pkg_type) |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 138 | |
Prashant Malani | 7c580f1 | 2017-08-24 19:38:08 -0700 | [diff] [blame] | 139 | exclude_string_tar = (( |
| 140 | ' --exclude="**%s" --exclude="**%s.checksum" ' % |
| 141 | (pkg_name, pkg_name)) + exclude_string) |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 142 | if action == ACTION_TAR_ONLY: |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 143 | # We don't want any pre-existing tarballs and checksums to |
| 144 | # be repackaged, so we should purge these. |
Prashant Malani | f7b2f99 | 2017-04-05 11:08:08 -0700 | [diff] [blame] | 145 | build_dir = get_build_dir(name, dest_dir, pkg_type) |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 146 | try: |
| 147 | packages.check_diskspace(build_dir) |
| 148 | except error.RepoDiskFullError as e: |
| 149 | msg = ("Work_dir directory for packages %s does not have " |
| 150 | "enough space available: %s" % (build_dir, e)) |
| 151 | raise error.RepoDiskFullError(msg) |
| 152 | tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir, |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 153 | build_dir, exclude_string_tar) |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 154 | |
| 155 | # Create the md5 hash too. |
| 156 | md5sum = pkgmgr.compute_checksum(tarball_path) |
Prashant Malani | 101485c | 2017-03-14 23:16:01 -0700 | [diff] [blame] | 157 | md5sum_filepath = os.path.join(build_dir, pkg_name + '.checksum') |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 158 | with open(md5sum_filepath, "w") as f: |
| 159 | f.write(md5sum) |
| 160 | |
| 161 | elif action == ACTION_UPLOAD: |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 162 | # Tar the source and upload |
mbligh | 982d13f | 2009-09-03 20:46:00 +0000 | [diff] [blame] | 163 | temp_dir = tempfile.mkdtemp() |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 164 | try: |
mbligh | e183681 | 2009-04-17 18:25:14 +0000 | [diff] [blame] | 165 | try: |
Allen Li | bf0c441 | 2017-02-03 16:49:53 -0800 | [diff] [blame] | 166 | packages.check_diskspace(temp_dir) |
mbligh | 6d7c565 | 2009-11-06 03:00:55 +0000 | [diff] [blame] | 167 | except error.RepoDiskFullError, e: |
| 168 | msg = ("Temporary directory for packages %s does not have " |
| 169 | "enough space available: %s" % (temp_dir, e)) |
jadmanski | c27c231 | 2009-08-05 20:58:51 +0000 | [diff] [blame] | 170 | raise error.RepoDiskFullError(msg) |
Prashant Malani | 101485c | 2017-03-14 23:16:01 -0700 | [diff] [blame] | 171 | |
Prashant Malani | 7c580f1 | 2017-08-24 19:38:08 -0700 | [diff] [blame] | 172 | # Check if tarball already exists. If it does, then don't |
Prashant Malani | e0e4d55 | 2017-05-16 15:18:46 -0700 | [diff] [blame] | 173 | # create a tarball again. |
Prashant Malani | 101485c | 2017-03-14 23:16:01 -0700 | [diff] [blame] | 174 | tarball_path = os.path.join(pkg_dir, pkg_name); |
Prashant Malani | 7c580f1 | 2017-08-24 19:38:08 -0700 | [diff] [blame] | 175 | if os.path.exists(tarball_path): |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 176 | print("process_packages: Tarball %s already exists" % |
| 177 | tarball_path) |
Prashant Malani | 101485c | 2017-03-14 23:16:01 -0700 | [diff] [blame] | 178 | else: |
| 179 | tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir, |
Prashant Malani | 7c580f1 | 2017-08-24 19:38:08 -0700 | [diff] [blame] | 180 | temp_dir, |
| 181 | exclude_string_tar) |
| 182 | # Compare the checksum with what packages.checksum has. If they |
| 183 | # match then we don't need to perform the upload. |
| 184 | if not pkgmgr.compare_checksum(tarball_path): |
| 185 | pkgmgr.upload_pkg(tarball_path, update_checksum=True) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 186 | finally: |
| 187 | # remove the temporary directory |
| 188 | shutil.rmtree(temp_dir) |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 189 | elif action == ACTION_REMOVE: |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 190 | pkgmgr.remove_pkg(pkg_name, remove_checksum=True) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 191 | print "Done." |
| 192 | |
| 193 | |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 194 | def tar_packages(pkgmgr, pkg_type, pkg_names, src_dir, temp_dir): |
| 195 | """Tar all packages up and return a list of each tar created""" |
| 196 | tarballs = [] |
| 197 | exclude_string = ' .' |
| 198 | names = [p.strip() for p in pkg_names.split(',')] |
| 199 | for name in names: |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 200 | print "tar_packages: Processing %s ... " % name |
Dale Curtis | 6ad3319 | 2011-07-06 18:04:50 -0700 | [diff] [blame] | 201 | if pkg_type == 'client': |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 202 | pkg_dir = src_dir |
Dale Curtis | 6ad3319 | 2011-07-06 18:04:50 -0700 | [diff] [blame] | 203 | exclude_string = get_exclude_string(pkg_dir) |
| 204 | elif pkg_type == 'test': |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 205 | # if the package is a test then look whether it is in client/tests |
| 206 | # or client/site_tests |
| 207 | pkg_dir = os.path.join(get_test_dir(name, src_dir), name) |
| 208 | else: |
| 209 | # for the profilers and deps |
| 210 | pkg_dir = os.path.join(src_dir, name) |
| 211 | |
| 212 | pkg_name = pkgmgr.get_tarball_name(name, pkg_type) |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 213 | |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 214 | # We don't want any pre-existing tarballs and checksums to |
| 215 | # be repackaged, so we should purge these. |
| 216 | exclude_string_tar = (( |
| 217 | ' --exclude="**%s" --exclude="**%s.checksum" ' % |
| 218 | (pkg_name, pkg_name)) + exclude_string) |
Prashant Malani | 101485c | 2017-03-14 23:16:01 -0700 | [diff] [blame] | 219 | # Check if tarball already exists. If it does, don't duplicate |
| 220 | # the effort. |
| 221 | tarball_path = os.path.join(pkg_dir, pkg_name); |
| 222 | if os.path.exists(tarball_path): |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 223 | print("tar_packages: Tarball %s already exists" % tarball_path); |
Prashant Malani | 101485c | 2017-03-14 23:16:01 -0700 | [diff] [blame] | 224 | else: |
| 225 | tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir, |
Prashant Malani | ad5e10f | 2017-05-05 16:23:54 -0700 | [diff] [blame] | 226 | temp_dir, exclude_string_tar) |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 227 | tarballs.append(tarball_path) |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 228 | return tarballs |
| 229 | |
| 230 | |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 231 | def process_all_packages(pkgmgr, client_dir, action): |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 232 | """Process a full upload of packages as a directory upload.""" |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 233 | dep_dir = os.path.join(client_dir, "deps") |
| 234 | prof_dir = os.path.join(client_dir, "profilers") |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 235 | # Directory where all are kept |
| 236 | temp_dir = tempfile.mkdtemp() |
mbligh | e183681 | 2009-04-17 18:25:14 +0000 | [diff] [blame] | 237 | try: |
Allen Li | bf0c441 | 2017-02-03 16:49:53 -0800 | [diff] [blame] | 238 | packages.check_diskspace(temp_dir) |
mbligh | 6d7c565 | 2009-11-06 03:00:55 +0000 | [diff] [blame] | 239 | except error.RepoDiskFullError, e: |
| 240 | print ("Temp destination for packages is full %s, aborting upload: %s" |
| 241 | % (temp_dir, e)) |
mbligh | e183681 | 2009-04-17 18:25:14 +0000 | [diff] [blame] | 242 | os.rmdir(temp_dir) |
| 243 | sys.exit(1) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 244 | |
| 245 | # process tests |
| 246 | tests_list = get_subdir_list('tests', client_dir) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 247 | tests = ','.join(tests_list) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 248 | |
| 249 | # process site_tests |
| 250 | site_tests_list = get_subdir_list('site_tests', client_dir) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 251 | site_tests = ','.join(site_tests_list) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 252 | |
| 253 | # process deps |
| 254 | deps_list = get_subdir_list('deps', client_dir) |
| 255 | deps = ','.join(deps_list) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 256 | |
| 257 | # process profilers |
| 258 | profilers_list = get_subdir_list('profilers', client_dir) |
| 259 | profilers = ','.join(profilers_list) |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 260 | |
| 261 | # Update md5sum |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 262 | if action == ACTION_UPLOAD: |
Dan Shi | 52d7889 | 2013-08-14 16:31:48 -0700 | [diff] [blame] | 263 | all_packages = [] |
| 264 | all_packages.extend(tar_packages(pkgmgr, 'profiler', profilers, |
| 265 | prof_dir, temp_dir)) |
| 266 | all_packages.extend(tar_packages(pkgmgr, 'dep', deps, dep_dir, |
| 267 | temp_dir)) |
| 268 | all_packages.extend(tar_packages(pkgmgr, 'test', site_tests, |
| 269 | client_dir, temp_dir)) |
| 270 | all_packages.extend(tar_packages(pkgmgr, 'test', tests, client_dir, |
| 271 | temp_dir)) |
| 272 | all_packages.extend(tar_packages(pkgmgr, 'client', 'autotest', |
| 273 | client_dir, temp_dir)) |
Dan Shi | 52d7889 | 2013-08-14 16:31:48 -0700 | [diff] [blame] | 274 | for package in all_packages: |
| 275 | pkgmgr.upload_pkg(package, update_checksum=True) |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 276 | client_utils.run('rm -rf ' + temp_dir) |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 277 | elif action == ACTION_REMOVE: |
| 278 | process_packages(pkgmgr, 'test', tests, client_dir, action=action) |
| 279 | process_packages(pkgmgr, 'test', site_tests, client_dir, action=action) |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 280 | process_packages(pkgmgr, 'client', 'autotest', client_dir, |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 281 | action=action) |
| 282 | process_packages(pkgmgr, 'dep', deps, dep_dir, action=action) |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 283 | process_packages(pkgmgr, 'profiler', profilers, prof_dir, |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 284 | action=action) |
mbligh | 9fc7797 | 2008-10-02 20:32:09 +0000 | [diff] [blame] | 285 | |
| 286 | |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 287 | # Get the list of sub directories present in a directory |
| 288 | def get_subdir_list(name, client_dir): |
| 289 | dir_name = os.path.join(client_dir, name) |
| 290 | return [f for f in |
| 291 | os.listdir(dir_name) |
| 292 | if os.path.isdir(os.path.join(dir_name, f)) ] |
| 293 | |
| 294 | |
| 295 | # Look whether the test is present in client/tests and client/site_tests dirs |
| 296 | def get_test_dir(name, client_dir): |
| 297 | names_test = os.listdir(os.path.join(client_dir, 'tests')) |
| 298 | names_site_test = os.listdir(os.path.join(client_dir, 'site_tests')) |
| 299 | if name in names_test: |
| 300 | src_dir = os.path.join(client_dir, 'tests') |
| 301 | elif name in names_site_test: |
| 302 | src_dir = os.path.join(client_dir, 'site_tests') |
| 303 | else: |
| 304 | print "Test %s not found" % name |
| 305 | sys.exit(0) |
| 306 | return src_dir |
| 307 | |
| 308 | |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 309 | def main(): |
mbligh | de613a9 | 2009-02-03 21:55:34 +0000 | [diff] [blame] | 310 | # get options and args |
| 311 | options, args = parse_args() |
| 312 | |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 313 | server_dir = server_utils.get_server_dir() |
| 314 | autotest_dir = os.path.abspath(os.path.join(server_dir, '..')) |
| 315 | |
| 316 | # extract the pkg locations from global config |
| 317 | repo_urls = c.get_config_value('PACKAGES', 'fetch_location', |
| 318 | type=list, default=[]) |
| 319 | upload_paths = c.get_config_value('PACKAGES', 'upload_location', |
| 320 | type=list, default=[]) |
Dale Curtis | 6ad3319 | 2011-07-06 18:04:50 -0700 | [diff] [blame] | 321 | |
| 322 | if options.repo: |
| 323 | upload_paths.append(options.repo) |
| 324 | |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 325 | # Having no upload paths basically means you're not using packaging. |
Dale Curtis | 6ad3319 | 2011-07-06 18:04:50 -0700 | [diff] [blame] | 326 | if not upload_paths: |
| 327 | print("No upload locations found. Please set upload_location under" |
| 328 | " PACKAGES in the global_config.ini or provide a location using" |
| 329 | " the --repository option.") |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 330 | return |
| 331 | |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 332 | client_dir = os.path.join(autotest_dir, "client") |
| 333 | |
| 334 | # Bail out if the client directory does not exist |
| 335 | if not os.path.exists(client_dir): |
| 336 | sys.exit(0) |
| 337 | |
| 338 | dep_dir = os.path.join(client_dir, "deps") |
| 339 | prof_dir = os.path.join(client_dir, "profilers") |
| 340 | |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 341 | # Due to the delayed uprev-ing of certain ebuilds, we need to support |
| 342 | # both the legacy command line and the new one. |
| 343 | # So, if the new "action" option isn't specified, try looking for the |
| 344 | # old style remove/upload argument |
| 345 | if options.action is None: |
| 346 | if len(args) == 0 or args[0] not in ['upload', 'remove']: |
| 347 | print("Either 'upload' or 'remove' needs to be specified " |
| 348 | "for the package") |
| 349 | sys.exit(0) |
| 350 | cur_action = args[0] |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 351 | else: |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 352 | cur_action = options.action |
| 353 | |
| 354 | if cur_action == ACTION_TAR_ONLY and options.output_dir is None: |
| 355 | print("An output dir has to be specified") |
| 356 | sys.exit(0) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 357 | |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 358 | pkgmgr = packages.PackageManager(autotest_dir, repo_urls=repo_urls, |
Dale Curtis | 6ad3319 | 2011-07-06 18:04:50 -0700 | [diff] [blame] | 359 | upload_paths=upload_paths, |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 360 | run_function_dargs={'timeout':600}) |
| 361 | |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 362 | if options.all: |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 363 | process_all_packages(pkgmgr, client_dir, action=cur_action) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 364 | |
| 365 | if options.client: |
| 366 | process_packages(pkgmgr, 'client', 'autotest', client_dir, |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 367 | action=cur_action) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 368 | |
| 369 | if options.dep: |
| 370 | process_packages(pkgmgr, 'dep', options.dep, dep_dir, |
Prashant Malani | f7b2f99 | 2017-04-05 11:08:08 -0700 | [diff] [blame] | 371 | action=cur_action, dest_dir=options.output_dir) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 372 | |
| 373 | if options.test: |
| 374 | process_packages(pkgmgr, 'test', options.test, client_dir, |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 375 | action=cur_action, dest_dir=options.output_dir) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 376 | |
| 377 | if options.prof: |
| 378 | process_packages(pkgmgr, 'profiler', options.prof, prof_dir, |
Prashant Malani | f7b2f99 | 2017-04-05 11:08:08 -0700 | [diff] [blame] | 379 | action=cur_action, dest_dir=options.output_dir) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 380 | |
| 381 | if options.file: |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 382 | if cur_action == ACTION_REMOVE: |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 383 | pkgmgr.remove_pkg(options.file, remove_checksum=True) |
Prashant Malani | 50287f9 | 2017-02-21 11:20:27 -0800 | [diff] [blame] | 384 | elif cur_action == ACTION_UPLOAD: |
Eric Li | d656d56 | 2011-04-20 11:48:29 -0700 | [diff] [blame] | 385 | pkgmgr.upload_pkg(options.file, update_checksum=True) |
showard | 9d02fb5 | 2008-08-08 18:20:37 +0000 | [diff] [blame] | 386 | |
| 387 | |
| 388 | if __name__ == "__main__": |
| 389 | main() |