summaryrefslogtreecommitdiff
blob: c9ba655be9111782265ff93572c4d16b8622a931 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?

	class PortageTree {
	
		// Strings
		protected $tree;
		
		// Arrays
		protected $arr_licenses;
	
		function __construct($tree = "/usr/portage") {
			if($tree)
				$this->setTree($tree);
		}
		
		function getTree() {
			return $this->tree;
		}
		
		function setTree($x) {
			if(is_string($x) && is_dir($x))
				$this->tree = $x;
		}
		
		function getArches($prefix = false) {
		
			$filename = $this->getTree().'/profiles/arch.list';
			$arr = file($filename, FILE_IGNORE_NEW_LINES);
			
			$barrier = key(preg_grep("/^\s*$/", $arr));
			
			if($prefix) {
				$arr = array_slice($arr, $barrier);
			} else {
				$arr = array_slice($arr, 0, $barrier);
			}
			
			$arr = preg_grep('/^[a-z]/', $arr);
			sort($arr);
			
			foreach($arr as $value) {
				$arches[] = $value;
			}
			
			return $arches;
		
		}
		
		public function getCategories() {
			
			$filename = $this->getTree().'/profiles/categories';
			$arr = file($filename, FILE_IGNORE_NEW_LINES);
			
			$arr = preg_grep('/^[a-z]/', $arr);
			sort($arr);
			
			foreach($arr as $value) {
				$categories[] = $value;
			}
			
			return $categories;
			
		}
		
		public function getEclasses() {
		
			$scandir = scandir($this->getTree().'/eclass/');
			
			$scandir = preg_grep('/\.eclass$/', $scandir);
			sort($scandir);
			foreach($scandir as $filename) {
				$filename = preg_replace("/\.eclass$/", "", $filename);
				$arr[] = $filename;
			}
			
			$this->arr_eclasses = $arr;
			
			return $arr;
		
		}
		
		function getLicenses() {
		
			$scandir = scandir($this->getTree().'/licenses/');
			$scandir = preg_grep('/^\.{1,2}$/', $scandir, PREG_GREP_INVERT);
			sort($scandir);
			foreach($scandir as $filename) {
				$arr[] = $filename;
			}
			
			$this->arr_licenses = $arr;
			
			return $arr;
		
		}
		
		/** Use Flags **/
		
		/**
		 * Get the use flags for any file w/use flags
		 *
		 * @param filename filename of use flags
		 * @return array
		 */
		public function arrUseFlags($filename) {
			
			$arr_file = file($filename, FILE_IGNORE_NEW_LINES);

			$arr_file = preg_grep('/^.+\s+\-\s+/', $arr_file);
			
			sort($arr_file);
			
			foreach($arr_file as $str) {
				$arr = explode(' - ', $str);
				$desc = str_replace($arr[0].' - ', '', $str);
				$arr_use_flags[$arr[0]] = $desc;
			}
			
			return $arr_use_flags;
		}
		
		/**
		 * Get the global use flags
		 *
		 */
		public function getUseFlags() {
			return array_keys($this->arrUseFlags($this->getTree()."/profiles/use.desc"));
		}
		
		/**
		 * Create an array of the current list of herds
		 *
		 * @return array
		 */
		function getHerds() {
		
			$arr = array();
			
			$filename = $this->getTree().'/metadata/herds.xml';
			
			if(file_exists($filename)) {
				$obj_xml = simplexml_load_file($filename);
				
				foreach($obj_xml->herd as $obj) {
					$herd = (string)$obj->name;
					$arr[] = $herd;
				}
				sort($arr);
			}
			return $arr;
		}
	
	}
?>