• R/O
  • SSH
  • HTTPS

ethna: Commit


Commit MetaInfo

Revision883 (tree)
Zeit2009-06-21 02:06:56
Autormumumu-org

Log Message

- re-implemented "ethna make-plugin-package" command.

Ändern Zusammenfassung

Diff

--- ethna/trunk/class/Plugin/Handle/MakePluginPackage.php (revision 882)
+++ ethna/trunk/class/Plugin/Handle/MakePluginPackage.php (revision 883)
@@ -24,6 +24,71 @@
2424 */
2525 class Ethna_Plugin_Handle_MakePluginPackage extends Ethna_Plugin_Handle
2626 {
27+ // {{{ _parseArgList()
28+ /**
29+ * @access private
30+ */
31+ function &_parseArgList()
32+ {
33+ $r =& $this->_getopt(
34+ array(
35+ 'basedir=',
36+ 'workdir=',
37+ 'ini-file-path='
38+ )
39+ );
40+ if (Ethna::isError($r)) {
41+ return $r;
42+ }
43+ list($opt_list, $arg_list) = $r;
44+
45+ // plugin directory path
46+ $plugin_dir = array_shift($arg_list);
47+ if (empty($plugin_dir)) {
48+ return Ethna::raiseError('plugin directory path is not set.', 'usage');
49+ }
50+
51+ // basedir
52+ if (isset($opt_list['basedir'])) {
53+ $basedir = realpath(end($opt_list['basedir']));
54+ } else {
55+ $basedir = getcwd();
56+ }
57+ $plugin_dir = "$basedir/${plugin_dir}";
58+
59+ // inifile
60+ $inifile = end($opt_list['ini-file_path']);
61+ if (empty($inifile)) {
62+ $inifiles = glob("${plugin_dir}/*.ini");
63+ if (empty($inifiles)) {
64+ return Ethna::raiseError(
65+ "ERROR: no inifile found on ${plugin_dir}\n"
66+ . ' please specify ini file path with [-i|--ini-file-path] option',
67+ 'usage'
68+ );
69+ }
70+ if (count($inifile) > 1) {
71+ return Ethna::raiseError(
72+ 'more than 2 .ini file found.'
73+ . ' please specify [-i|--ini-file-path] option',
74+ 'usage'
75+ );
76+ }
77+
78+ $inifile = array_shift($inifiles);
79+ $ini = parse_ini_file($inifile, true);
80+ if (empty($ini)) {
81+ return Ethna::raiseError(
82+ "invalid ini file: $inifile"
83+ );
84+ }
85+ }
86+
87+ return array($ini, $plugin_dir);
88+ }
89+ // }}}
90+
91+
2792 // {{{ perform()
2893 /**
2994 * @access public
@@ -30,7 +95,15 @@
3095 */
3196 function perform()
3297 {
33- require_once 'PEAR/PackageFileManager.php';
98+ // required package check.
99+ if (!file_exists_ex('PEAR/PackageFileManager2.php')
100+ || !file_exists_ex('PEAR/PackageFileManager/File.php')) {
101+ return Ethna::raiseError(
102+ "ERROR: PEAR_PackageFileManager2 is not installed! please install it.\n"
103+ . "usage: pear install -a pear/PackageFileManager2 "
104+ );
105+ }
106+
34107 require_once 'PEAR/PackageFileManager2.php';
35108 require_once 'PEAR/PackageFileManager/File.php';
36109
@@ -39,24 +112,13 @@
39112 if (Ethna::isError($args)) {
40113 return $args;
41114 }
42- list($ini, $skelfile, $workdir) = $args;
115+ list($ini, $plugin_dir) = $args;
43116
44- // パッケージを作るプラグインの target
45- $targets = array();
46- if ($ini['plugin']['master'] == true) {
47- $targets[] = 'master';
48- }
49- if ($ini['plugin']['local'] == true) {
50- $targets[] = 'local';
51- }
52-
53117 // 設定用の配列を用意
54118 $setting = array();
55119
56- // {{{ master と local で共通の設定
57120 // プラグイン名
58- $ptype = $ini['plugin']['type'];
59- $pname = $ini['plugin']['name'];
121+ $setting['pkgname'] = $ini['plugin']['name'];
60122
61123 // パッケージの説明
62124 $setting['channel'] = $ini['package']['channel'];
@@ -90,57 +152,22 @@
90152 if (isset($ini['license']['uri'])) {
91153 $setting['license']['uri'] = $ini['license']['uri'];
92154 }
93- // }}}
94155
95- // まるまるコピー :-p
96- $setting = array('master' => $setting, 'local' => $setting);
97-
98- // {{{ master と local で異なる部分
99- // パッケージ名
100- $setting['master']['pkgname'] = "Ethna_Plugin_{$ptype}_{$pname}";
101- $setting['local'] ['pkgname'] = "App_Plugin_{$ptype}_{$pname}";
102-
103- // プラグインのファイル名
104- $setting['master']['filename'] = "Ethna_Plugin_{$ptype}_{$pname}.php";
105- $setting['local'] ['filename'] = "skel.plugin.{$ptype}_{$pname}.php";
106-
107- // 入力ファイルの置換マクロ
108- $setting['master']['macro'] = array(
109- // package 時に置換
110- 'application_id' => 'Ethna',
111- 'project_id' => 'Ethna',
156+ // インストールディレクトリ
157+ $setting['config'] = array(
158+ 'baseinstalldir' => 'Plugin',
112159 );
113- $setting['local']['macro'] = array(
114- // install 時に置換
115- );
116160
117- // setOptins($config) 時に merge する設定
118- $setting['master']['config'] = array(
119- 'baseinstalldir' => "Ethna/class/Plugin/{$ptype}",
120- );
121- $setting['local']['config'] = array(
122- 'baseinstalldir' => '.',
123- );
124-
125161 // 任意に $packagexml->doSomething() するための callback
126- $setting['master']['callback'] = array(
162+ $setting['callback'] = array(
127163 'addPackageDepWithChannel'
128- => array('optional', 'ethna', 'pear.ethna.jp', '2.3.0'),
164+ => array('required', 'ethna', 'pear.ethna.jp', '2.4.0'),
129165 );
130- $setting['local']['callback'] = array(
131- // local 用のパッケージを master にインストールさせないための conflict
132- 'addConflictingPackageDepWithChannel'
133- => array('pear', 'pear.php.net'),
134- );
135- // }}}
136166
137-
138167 // パッケージ作成
139168 $this->pear =& new Ethna_PearWrapper();
140- $this->pear->init('master');
141- foreach ($targets as $target) {
142- $this->_makePackage($skelfile, $setting[$target], "$workdir/$target");
143- }
169+ $this->pear->init('local');
170+ $this->_makePackage($setting, $plugin_dir);
144171 }
145172 // }}}
146173
@@ -148,42 +175,14 @@
148175 /**
149176 * @access private
150177 */
151- function &_makePackage($skelfile, $setting, $workdir)
178+ function &_makePackage($setting, $workdir)
152179 {
153- if (Ethna_Util::mkdir($workdir, 0755) === false) {
154- return Ethna::raiseError("failed making working dir: $workdir.");
155- }
156-
157- // プラグインの元ファイルを作成
158- $rfp = fopen($skelfile, "r");
159- if ($rfp == false) {
160- return Ethna::raiseError("failed open skelton file: $skelfile.");
161- }
162- $outputfile = $setting['filename'];
163- $wfp = fopen("$workdir/$outputfile", "w");
164- if ($rfp == false) {
165- fclose($rfp);
166- return Ethna::raiseError("failed creating working file: $outputfile.");
167- }
168- for (;;) {
169- $s = fread($rfp, 4096);
170- if (strlen($s) == 0) {
171- break;
172- }
173- foreach ($setting['macro'] as $k => $v) {
174- $s = preg_replace("/{\\\$$k}/", $v, $s);
175- }
176- fwrite($wfp, $s);
177- }
178- fclose($wfp);
179- fclose($rfp);
180-
181180 // package.xml を作る
182181 $pkgconfig = array(
183182 'packagedirectory' => $workdir,
184183 'outputdirectory' => $workdir,
185184 'ignore' => array('CVS/', '.cvsignore', '.svn/',
186- 'package.xml', 'package.ini', $setting['pkgname'].'-*.tgz'),
185+ 'package.xml', '*.ini', $setting['pkgname'].'-*.tgz'),
187186 'filelistgenerator' => 'file',
188187 'changelogoldtonew' => false,
189188 );
@@ -216,7 +215,7 @@
216215 $packagexml->addRole('sh', 'script');
217216 $packagexml->addRole('bat', 'script');
218217
219- $packagexml->setPhpDep('4.1.0');
218+ $packagexml->setPhpDep('4.3.0');
220219 $packagexml->setPearinstallerDep('1.3.5');
221220
222221 $packagexml->generateContents();
@@ -230,54 +229,32 @@
230229 return Ethna::raiseError($r->getMessage, $r->getCode());
231230 }
232231
233- // package を作る
234- $r = $this->pear->_run('package', array(), array("$workdir/package.xml"));
232+ // finally make package
233+ PEAR_Command::setFrontendType('CLI');
234+ $ui =& PEAR_Command::getFrontendObject();
235+ $config =& PEAR_Config::singleton();
236+ $ui->setConfig($config);
237+ PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$ui, 'displayFatalError'));
238+ $cmd =& PEAR_Command::factory('package', $config);
239+ if (PEAR::isError($cmd)) {
240+ return Ethna::raiseError($cmd->getMessage, $cmd->getCode());
241+ }
242+ $r = $cmd->run('package', array(), array("$workdir/package.xml"));
235243 if (PEAR::isError($r)) {
236244 return Ethna::raiseError($r->getMessage, $r->getCode());
237245 }
238-
239- if (Ethna_Util::purgeDir($workdir) === false) {
240- return Ethna::raiseError("failed cleaning up working dir: $workdir.");
241- }
242246 }
243247 // }}}
244248
245- // {{{ _parseArgList()
249+ // {{{ getUsage()
246250 /**
247- * @access private
251+ * @access public
248252 */
249- function &_parseArgList()
253+ function getUsage()
250254 {
251- $r =& $this->_getopt(array('inifile=', 'skelfile=', 'workdir='));
252- if (Ethna::isError($r)) {
253- return $r;
254- }
255- list($opt_list, $arg_list) = $r;
256-
257- // inifile
258- if (isset($opt_list['inifile'])
259- && is_readable(end($opt_list['inifile']))) {
260- $ini = parse_ini_file(end($opt_list['inifile']), true);
261- } else {
262- return Ethna::raiseError('give a valid inifile.');
263- }
264-
265- // skelfile
266- if (isset($opt_list['skelfile'])
267- && is_readable(end($opt_list['skelfile']))) {
268- $skelfile = end($opt_list['skelfile']);
269- } else {
270- return Ethna::raiseError('give a valid filename of plugin skelton file.');
271- }
272-
273- // workdir
274- if (isset($opt_list['workdir'])) {
275- $workdir = end($opt_list['workdir']);
276- } else {
277- $workdir = getcwd();
278- }
279-
280- return array($ini, $skelfile, $workdir);
255+ return <<<EOS
256+ {$this->id} [-b|--basedir=dir] [-i|--ini-file-path=file] [plugin_directory_path]
257+EOS;
281258 }
282259 // }}}
283260
@@ -289,8 +266,7 @@
289266 {
290267 return <<<EOS
291268 make plugin package:
292- {$this->id} [-i|--inifile=file] [-s|--skelfile=file] [-w|--workdir=dir]
293-
269+ {$this->id} [-b|--basedir=dir] [-i|--ini-file-path=file] [plugin_directory_path]
294270 EOS;
295271 }
296272 // }}}
Show on old repository browser