def checkout_code(zoomdb, opts): """ Checkout code from opts["SRC_URL"] into opts["CO_DIR"]. """ dest_dir = opts["CO_DIR"] source_code_url = opts["SRC_URL"] repo_type = opts.get("SRC_REPO_TYPE", "git") vcs_handler = vcs_handlers.get_handler(repo_type) vcs_handler.checkout_latest_matching_version(source_code_url, dest_dir, zoomdb.log)
def _test_with_remote(self, repo_type, repo_url): handler = vcs_handlers.get_handler(repo_type) logs = [] def logger(msg): print "VCS HANDLER LOGGED: %s" % msg logs.append(msg) self.assertEqual(handler.canonicalize_url( handler.get_current_checkout_source_url()), None) handler.fresh_clone(repo_url, logger) self.assertEqual(handler.canonicalize_url( handler.get_current_checkout_source_url()), handler.canonicalize_url(repo_url)) handler.update_checkout(logger) revision_info = handler.get_revision_info(".") self.assertTrue(revision_info, "Revision info expected; got %r" % revision_info)
def bundle_app(app_id, force_bundle_name=None, return_ue=False, src_repo_type="git"): """ Task: Bundle an app with ``app_id`` found in ``custdir`` :param custdir: Absolute path to the base customer directory :param app_id: A path such that ``os.path.join(custdir, app_id)`` is a valid directory. :param force_bundle_name: Optional name for the bundle. If absent, name will be auto-generated based on the app name and current date/time. :param return_ue: If true, returns the UserEnv object used to build the bundle. :returns: (bundle_name, code_revision, userenv) if ``return_ue`` is True otherwise returns (bundle_name, code_revision) """ appdir = os.path.join(taskconfig.NR_CUSTOMER_DIR, app_id) appsrcdir = os.path.join(appdir, "src") buildconfig = os.path.join(appdir, "zoombuild.cfg") assert os.path.isdir(taskconfig.NR_CUSTOMER_DIR),\ "Expected custdir %r to be a directory, but it isn't." % ( taskconfig.NR_CUSTOMER_DIR) err_msg = ("Expected to find customer source in directory %r," % appsrcdir, "but that isn't a directory.") assert os.path.isdir(appdir), err_msg assert os.path.isfile(buildconfig),\ "Expected zoombuild.cfg file in %r, but no dice." % buildconfig # parse the zoombuild.cfg file buildconfig_info = utils.parse_zoombuild(buildconfig) err_msg = ("File %r doesn't look like a valid" % buildconfig, "zoombuild.cfg format file.") assert buildconfig_info, err_msg # generate a bundle name and directory if force_bundle_name: bundle_name = force_bundle_name else: bundle_name = "bundle_%s_%s" % ( app_id, datetime.datetime.utcnow().strftime("%Y-%m-%d-%H.%M.%S")) bundle_dir = os.path.join(appdir, bundle_name) # make virtualenv utils.make_virtualenv(bundle_dir) # archive a copy of the build parameters shutil.copyfile(buildconfig, os.path.join(bundle_dir, "zoombuild.cfg")) # Check what version of the code we've got vcs_h = vcs_handlers.get_handler(src_repo_type) code_revision = unicode(vcs_h.get_revision_info(appsrcdir), "utf8") # Copy in user code and add to pth to_src = os.path.join(bundle_dir, 'user-src') # if there is a base python package, copy user's code under there. if buildconfig_info["base_python_package"]: bpp_as_path = buildconfig_info["base_python_package"].replace( ".", "/") to_src = os.path.join(to_src, bpp_as_path) else: bpp_as_path = None # Add in a symlink pointing to the actual repo, so that we can # find static files later repo_link = os.path.join(bundle_dir, 'user-repo') if bpp_as_path: repo_link_src = os.path.join('user-src', bpp_as_path) else: repo_link_src = 'user-src' os.symlink(repo_link_src, repo_link) # Do the shutil.copytree inside a try/except block so that we can # identify bad symlinks. According to http://bugs.python.org/issue6547, # bad symlinks will cause an shutil.Error to be raised only at the # end of the copy process, so other files are copied correctly. # Therefore it is OK to simply warn about any bad links but otherwise # assume that things were copied over OK. try: shutil.copytree(appsrcdir, to_src, ignore=_ignore_vcs_files) except shutil.Error, e: for src, dst, error in e.args[0]: if not os.path.islink(src): raise else: linkto = os.readlink(src) if os.path.exists(linkto): raise else: ### TODO: communicate this warning to end-user via ### zoomdb.log print("*** Warning: invalid symlink found in " + "project: %s -> %s, but %s doesn't exist." % ( src, linkto, linkto))