You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ra...@apache.org on 2012/05/17 19:35:36 UTC

svn commit: r1339733 - in /incubator/ambari/branches/ambari-186: CHANGES.txt hmc/php/util/YumRepoConfigParser.php

Author: ramya
Date: Thu May 17 17:35:36 2012
New Revision: 1339733

URL: http://svn.apache.org/viewvc?rev=1339733&view=rev
Log:
AMBARI-246. Add support for parsing yum repo files to understand how to bootstrap nodes for local yum mirror

Added:
    incubator/ambari/branches/ambari-186/hmc/php/util/YumRepoConfigParser.php
Modified:
    incubator/ambari/branches/ambari-186/CHANGES.txt

Modified: incubator/ambari/branches/ambari-186/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/CHANGES.txt?rev=1339733&r1=1339732&r2=1339733&view=diff
==============================================================================
--- incubator/ambari/branches/ambari-186/CHANGES.txt (original)
+++ incubator/ambari/branches/ambari-186/CHANGES.txt Thu May 17 17:35:36 2012
@@ -2,6 +2,9 @@ Ambari Change log
 
 Release 0.x.x - unreleased
 
+  AMBARI-246. Add support for parsing yum repo files to understand how to
+  bootstrap nodes for local yum mirror (Hitesh via ramya)
+
   AMBARI-218. Install Combo-Handler On HMC Webserver To Drastically Speed Up
   Page Load Times (Varun Kapoor via ramya)
 

Added: incubator/ambari/branches/ambari-186/hmc/php/util/YumRepoConfigParser.php
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/ambari-186/hmc/php/util/YumRepoConfigParser.php?rev=1339733&view=auto
==============================================================================
--- incubator/ambari/branches/ambari-186/hmc/php/util/YumRepoConfigParser.php (added)
+++ incubator/ambari/branches/ambari-186/hmc/php/util/YumRepoConfigParser.php Thu May 17 17:35:36 2012
@@ -0,0 +1,122 @@
+<?php
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function getEnabledGpgKeyLocations($repoFile) {
+  $logger = new HMCLogger("YumRepoConfigParser");
+
+  $logger->log_info("Parsing gpg key info from " . $repoFile);
+  if (!file_exists($repoFile)) {
+    $logger->log_error("Invalid repo file provided, file=" . $repoFile);
+    return FALSE;
+  }
+
+  $fileContents = file($repoFile,
+      FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
+
+  $logger->log_debug("Repo file contents, file=" . $repoFile
+      . ", contents=" . print_r($fileContents, true));
+
+  $response = array();
+
+  $currentRepoId = "";
+  $currentRepoEnabled = 1;
+  $currentGpgCheck = -1;
+  $currentGpgLocation = "";
+  $globalGpgCheck = 0;
+
+  foreach ($fileContents as $fLine) {
+    $line = trim($fLine);
+    if (substr($line, 0, 1) == "#") {
+      continue;
+    }
+
+    $matches = array();
+    $logger->log_debug("Parsing repo file, file=" . $repoFile
+        . ", line=" . $line);
+    $logger->log_debug("Current: "
+        . ", repoId=" . $currentRepoId
+        . ", repoEnabled=" . $currentRepoEnabled
+        . ", gpgCheckEnabled=" . $currentGpgCheck
+        . ", gpgCheckLocation=" . $currentGpgLocation);
+
+    if (preg_match("/\[(.*)\]/", $line, $matches) > 0) {
+      $newRepoId = $matches[1];
+      $logger->log_debug("Found new repo id in repo file, file=" . $repoFile
+          . ", repoId=" . $newRepoId);
+      if ($currentRepoEnabled == 1
+          && (($currentGpgCheck == -1 && $globalGpgCheck == 1)
+              || ($currentGpgCheck == 1))) {
+        if ($currentGpgLocation != "") {
+          $response[$currentRepoId] = array ( "gpgkey" => $currentGpgLocation);
+        }
+      } else if ($currentRepoId != ""
+          && $currentRepoId != "main") {
+        $logger->log_debug("Skipping repo as repo/check not enabled"
+            .", id=" . $currentRepoId);
+      }
+      $currentRepoId = $newRepoId;
+      $currentGpgLocation = "";
+      $currentGpgCheck = -1;
+      $currentRepoEnabled = -1;
+      continue;
+    }
+
+    $eIdx = strpos($line, "=");
+    if ($eIdx === FALSE) {
+      $logger->log_warn("Invalid line when parsing repo file, file=" . $repoFile
+          . ", line=" . $line);
+      continue;
+    }
+
+    $key = trim(substr($line, 0, $eIdx));
+    $val = trim(substr($line, $eIdx+1));
+
+    $logger->log_debug("Parsed line, key=" . $key . ", val=" . $val);
+
+    if ($key == "gpgcheck") {
+      if ($currentRepoId == "main") {
+        $globalGpgCheck = intval($val);
+      } else {
+        $currentGpgCheck = intval($val);
+      }
+    } else if ($key == "enabled") {
+      $currentRepoEnabled = intval($val);
+    } else if ($key == "gpgkey") {
+      $currentGpgLocation = $val;
+    }
+  }
+
+  if ($currentRepoEnabled == 1
+      && (($currentGpgCheck == -1 && $globalGpgCheck == 1)
+           || ($currentGpgCheck == 1))) {
+    if ($currentGpgLocation != "") {
+      $response[$currentRepoId] = array ( "gpgkey" => $currentGpgLocation);
+    }
+  } else if ($currentRepoId != ""
+      && $currentRepoId != "main") {
+    $logger->log_debug("Skipping repo as repo/check not enabled"
+        .", id=" . $currentRepoId);
+  }
+
+  return $response;
+}
+
+
+?>