9265
|
1 %% Copyright (c) 2011 Juan Pablo Carbajal <carbajal@ifi.uzh.ch> |
|
2 %% |
|
3 %% This program is free software: you can redistribute it and/or modify |
|
4 %% it under the terms of the GNU General Public License as published by |
|
5 %% the Free Software Foundation, either version 3 of the License, or |
|
6 %% any later version. |
|
7 %% |
|
8 %% This program is distributed in the hope that it will be useful, |
|
9 %% but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 %% GNU General Public License for more details. |
|
12 %% |
|
13 %% You should have received a copy of the GNU General Public License |
|
14 %% along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 |
|
16 %% -*- texinfo -*- |
|
17 %% @deftypefn {Function File} {[@var{pkgtar} @var{htmltar}] = } releasePKG (@var{pkgname}) |
|
18 %% @deftypefnx {Function File} {[@dots{}] = } releasePKG (@var{pkgname},@var{property},@var{value},@dots{}) |
|
19 %% Create files ready to release the Octave-Forge package @var{pkgname}. |
|
20 %% |
|
21 %% @var{property} and @var{value} are used to indicate where is the source of the |
|
22 %% package. |
|
23 %% @var{property} can be: |
|
24 %% @table @samp |
|
25 %% @item outpath |
|
26 %% Is the path where the files will be created. If not provided the current working |
|
27 %% directory @code{pwd()} is used. |
|
28 %% |
|
29 %% @item repopath |
|
30 %% Is the path where the local copy of package is located. For example, to release |
|
31 %% any package in @code{main} you should pass '<my-path.to-repository>/main'. |
|
32 %% If not provided, the environment variable OFPATH is used (you can set it in your) |
|
33 %% .octaverc variable or using @code{setenv()}). If that variable is empty, the |
|
34 %% property must be provided the first time the function is called. After that |
|
35 %% it creates the environment variable (but only for the current octave session) |
|
36 %% |
|
37 %% @end deftypefn |
|
38 function [pkgtar htmltar] = releasePKG (pkgname, varargin) |
|
39 OFPATH = getenv ('OFPATH'); |
|
40 use_inputP = exist('inputParser') == 2; |
|
41 |
|
42 if use_inputP |
|
43 parser = inputParser (); |
|
44 parser = addParamValue (parser,'repopath', OFPATH , @ischar); |
|
45 parser = addParamValue (parser,'outpath', pwd (), @ischar); |
|
46 |
|
47 parser = parse(parser,varargin{:}); |
|
48 else |
|
49 opt = {varargin{1:2:end}}; |
|
50 val = {varargin{2:2:end}}; |
|
51 parser.Results.repopath = OFPATH; |
|
52 parser.Results.outpath = pwd (); |
|
53 |
|
54 if !isempty(opt) |
|
55 [tf indx] = ismember (fieldnames(parser.Results), opt); |
|
56 opt{indx(tf)} = opt{indx(tf)}; |
|
57 val{indx(tf)} = val{indx(tf)}; |
|
58 for i=1:numel(opt) |
|
59 parser.Results.(opt{i}) = val{i}; |
|
60 end |
|
61 endif |
|
62 |
|
63 checkrepopath(parser.Results.repopath); |
|
64 |
|
65 end |
|
66 |
|
67 |
|
68 |
|
69 % Export from repo |
|
70 outpath = checkpath(parser.Results.outpath); |
|
71 |
|
72 exported = sprintf([outpath "%s"], pkgname); |
|
73 |
|
74 % Repo path |
|
75 svn_repo = checkpath(parser.Results.repopath); |
|
76 disp(['Exporting from ' svn_repo]); |
|
77 |
|
78 export_call = ["svn export " svn_repo filesep() pkgname " " exported " --force"]; |
|
79 if system (export_call); |
|
80 error ("Can not export.\n"); |
|
81 elseif isempty (OFPATH) || !strcmpi(svn_repo, OFPATH) |
|
82 setenv('OFPATH',parser.Results.repopath); |
|
83 printf (["\nEnvironment variable OFPATH set to %s\n" ... |
|
84 'add setenv("OFPATH","%s");' ... |
|
85 'to your .octaverc to make it permanent.' "\n\n"], ... |
|
86 parser.Results.repopath, parser.Results.repopath); |
|
87 fflush (stdout); |
|
88 end |
|
89 |
|
90 printf("Exported to %s\n", exported); |
|
91 fflush(stdout); |
|
92 |
|
93 % Get package version |
|
94 desc_file = textread([exported filesep() "DESCRIPTION"],"%s"); |
|
95 [tf ind] = ismember ("Version:",desc_file); |
|
96 pkgversion = desc_file{ind+1}; |
|
97 |
|
98 % Compress package |
|
99 pkgtar = sprintf ("%s-%s.tar.gz", pkgname, pkgversion); |
|
100 if system (sprintf ("tar cfz %s %s/", pkgtar, pkgname)); |
|
101 error ("Can not make package tar.\n"); |
|
102 end |
|
103 |
|
104 printf("Tared to %s\n", pkgtar); |
|
105 fflush(stdout); |
|
106 |
|
107 do_doc = input("\nCreate documentation for Octave-Forge? [y|Yes|Y] / [n|No|N] ","s"); |
|
108 do_doc = strcmpi(do_doc(1),'y'); |
|
109 |
|
110 if do_doc |
9731
|
111 % Install package |
|
112 printf("Installing...\n"); |
|
113 fflush(stdout); |
|
114 pkg ('install', pkgtar); |
|
115 |
|
116 |
9265
|
117 % Load package and generate_html |
|
118 printf("Generating html...\n"); |
|
119 fflush(stdout); |
|
120 |
|
121 pkg('load', pkgname); |
|
122 pkg('load','generate_html'); |
|
123 pkghtml = [pkgname '-html']; |
|
124 generate_package_html (pkgname, pkghtml, 'octave-forge'); |
|
125 |
|
126 % Compress html |
|
127 htmltar = sprintf ("%s-html.tar.gz", pkgname); |
|
128 if system (sprintf ("tar cfz %s %s/", htmltar, pkghtml)); |
|
129 error ("Can not make html tar.\n"); |
|
130 end |
|
131 |
|
132 printf("Documentation tared to %s\n", pkghtml); |
|
133 fflush(stdout); |
|
134 |
|
135 % md5sum |
|
136 printf(["md5sum for " htmltar "\n"]); |
|
137 fflush (stdout); |
|
138 if system(["md5sum " htmltar]); |
|
139 warning ("md5sum failed.\n"); |
|
140 end |
|
141 |
10058
|
142 % Uninstall package |
|
143 printf("Uninstalling...\n"); |
|
144 fflush(stdout); |
|
145 pkg ('uninstall', pkgname); |
9265
|
146 |
|
147 endif % do_doc |
|
148 |
|
149 % md5sum |
|
150 printf(["md5sum for " pkgtar "\n"]); |
|
151 fflush (stdout); |
|
152 if system(["md5sum " pkgtar]); |
|
153 warning ("md5sum failed.\n"); |
|
154 end |
|
155 |
|
156 |
|
157 endfunction |
|
158 |
|
159 function str = checkpath (str) |
|
160 if str(end) != filesep() |
|
161 str = [str filesep()]; |
|
162 end |
|
163 endfunction |
|
164 |
|
165 function tf = checkrepopath (str) |
|
166 |
|
167 if !ischar (str) |
|
168 tf = false; |
|
169 elseif isempty (str) |
|
170 error ([' If no path to the local Octave-Forge repository is given, ' ... |
|
171 'the environment variable OFPATH should be set. ' |
|
172 'Use setenv("OFPATH", path-to-repo) to set it.']) |
|
173 tf = false; |
|
174 else |
|
175 tf = true; |
|
176 end |
|
177 |
|
178 endfunction |