示例#1
0
def get_warnings(pack=None):
    result = None
    pack_path = get_pack_base_path(pack)
    try:
        pack_metadata = get_pack_metadata(pack_dir=pack_path)
        result = get_pack_warnings(pack_metadata)
    except Exception:
        print("Could not open pack.yaml at location %s" % pack_path)
    finally:
        return result
示例#2
0
def move_pack(
    abs_repo_base,
    pack_name,
    abs_local_path,
    pack_metadata,
    force_owner_group=True,
    force_permissions=True,
    logger=LOG,
):
    """
    Move pack directory into the final location.
    """
    desired, message = is_desired_pack(abs_local_path, pack_name)

    if desired:
        to = abs_repo_base
        dest_pack_path = os.path.join(abs_repo_base, pack_name)
        if os.path.exists(dest_pack_path):
            logger.debug(
                "Removing existing pack %s in %s to replace.", pack_name, dest_pack_path
            )

            # Ensure to preserve any existing configuration
            old_config_file = os.path.join(dest_pack_path, CONFIG_FILE)
            new_config_file = os.path.join(abs_local_path, CONFIG_FILE)

            if os.path.isfile(old_config_file):
                shutil.move(old_config_file, new_config_file)

            shutil.rmtree(dest_pack_path)

        logger.debug("Moving pack from %s to %s.", abs_local_path, to)
        shutil.move(abs_local_path, dest_pack_path)

        # post move fix all permissions
        if force_owner_group:
            # 1. switch owner group to configured group
            apply_pack_owner_group(pack_path=dest_pack_path)

        if force_permissions:
            # 2. Setup the right permissions and group ownership
            apply_pack_permissions(pack_path=dest_pack_path)

        # Log warning if python2 only supported
        warning = get_pack_warnings(pack_metadata)
        if warning:
            logger.warning(warning)

        message = "Success."
    elif message:
        message = "Failure : %s" % message

    return (desired, message)
示例#3
0
 def test_get_pack_warnings_no_python(self):
     pack_metadata = {'name': 'PackNone'}
     warning = get_pack_warnings(pack_metadata)
     self.assertEqual(None, warning)
示例#4
0
 def test_get_pack_warnings_python2_and_3(self):
     pack_metadata = {'python_versions': ['2', '3'], 'name': 'Pack23'}
     warning = get_pack_warnings(pack_metadata)
     self.assertEqual(None, warning)
示例#5
0
 def test_get_pack_warnings_python3_only(self):
     pack_metadata = {'python_versions': ['3'], 'name': 'Pack3'}
     warning = get_pack_warnings(pack_metadata)
     self.assertEqual(None, warning)
示例#6
0
 def test_get_pack_warnings_python2_only(self):
     pack_metadata = {'python_versions': ['2'], 'name': 'Pack2'}
     warning = get_pack_warnings(pack_metadata)
     self.assertTrue("DEPRECATION WARNING" in warning)
示例#7
0
 def test_get_pack_warnings_python2_and_3(self):
     pack_metadata = {"python_versions": ["2", "3"], "name": "Pack23"}
     warning = get_pack_warnings(pack_metadata)
     self.assertEqual(None, warning)
示例#8
0
 def test_get_pack_warnings_python3_only(self):
     pack_metadata = {"python_versions": ["3"], "name": "Pack3"}
     warning = get_pack_warnings(pack_metadata)
     self.assertEqual(None, warning)
示例#9
0
 def test_get_pack_warnings_python2_only(self):
     pack_metadata = {"python_versions": ["2"], "name": "Pack2"}
     warning = get_pack_warnings(pack_metadata)
     self.assertTrue("DEPRECATION WARNING" in warning)