c&d: po4a (& git) revisited, revisit
[software/sisu] / lib / sisu / develop / git.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** system environment, resource control and configuration details
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/git.rb;hb=HEAD>
55
56 =end
57 module SiSU_Git
58 require_relative 'dp' # dp.rb
59 require_relative 'se' # se.rb
60 require_relative 'ao' # ao.rb
61 class Source
62 def initialize(opt,process=:complete)
63 @opt,@process=opt,process
64 @env=SiSU_Env::InfoEnv.new
65 @md=SiSU_Param::Parameters.new(@opt).get
66 @file=SiSU_Env::FileOp.new(@md)
67 l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language
68 unless @opt.lng==l[:c] # @md.i18n[0]==l[:c]
69 p "using: #{@opt.lng} (@make: :language:); filename #{@md.fns} filename language: #{l[:c]}, mismatch"
70 end
71 if @env.output_dir_structure.multilingual?
72 m=/((.+?)(?:\~\w{2,3})?)\.((?:-|ssm\.)?sst|ssm)$/ #watch added match for sss
73 fnb,fnt=@opt.fns[m,2],@opt.fns[m,3]
74 else m=/(.+?)\.((?:-|ssm\.)?sst|ssm)$/
75 fnb=@fnn=@opt.fns[m,1]
76 fnt=@opt.fns[m,2]
77 end
78 git_path_fnb=@env.processing_path.git + '/' + fnb
79 lng=(@md.opt.lng) ? (@md.opt.lng) : (@md.i18n[0])
80 @git_path={
81 fnb: git_path_fnb,
82 doc: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:doc] + '/' + lng,
83 po: git_path_fnb + '/' + Gt[:po] + '/' + lng,
84 pot: git_path_fnb + '/' + Gt[:pot],
85 conf: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:conf],
86 image: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:image],
87 audio: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:audio],
88 video: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:video],
89 conf: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:conf]
90 }
91 SiSU_AO::Source.new(@opt,nil,@process).read # -m
92 end
93 def create_file_structure_git
94 make_dir_fnb
95 if program_found?
96 git_init
97 end
98 end
99 def read
100 create_file_structure_git
101 populate.sisusrc_files
102 #if program_found?
103 # git_commit
104 #end
105 unless @opt.act[:quiet][:set]==:on
106 (@opt.act[:verbose][:set]==:on \
107 || @opt.act[:verbose_plus][:set]==:on \
108 || @opt.act[:maintenance][:set]==:on) \
109 ? SiSU_Screen::Ansi.new(
110 @opt.act[:color_state][:set],
111 'Git path',
112 @git_path[:fnb]
113 ).green_hi_blue
114 : SiSU_Screen::Ansi.new(
115 @opt.act[:color_state][:set],
116 'Git path',
117 @git_path[:fnb]
118 ).green_title_hi
119 if (@opt.act[:verbose][:set]==:on \
120 || @opt.act[:verbose_plus][:set]==:on \
121 || @opt.act[:maintenance][:set]==:on)
122 SiSU_Screen::Ansi.new(
123 @opt.act[:color_state][:set],
124 "Git path",
125 "#{@opt.fns} -> #{@git_path[:fnb]}"
126 ).warn
127 end
128 end
129 end
130 def program_found?
131 found=`whereis git`
132 (found =~/bin\/git\b/) ? true : false
133 end
134 def make_dir_fnb
135 FileUtils::mkdir_p(@git_path[:fnb]) \
136 unless FileTest.directory?(@git_path[:fnb])
137 FileUtils::mkdir_p(@git_path[:doc]) \
138 unless FileTest.directory?(@git_path[:doc])
139 FileUtils::mkdir_p(@git_path[:po]) \
140 unless FileTest.directory?(@git_path[:po])
141 FileUtils::mkdir_p(@git_path[:pot]) \
142 unless FileTest.directory?(@git_path[:pot])
143 FileUtils::mkdir_p(@git_path[:conf]) \
144 unless FileTest.directory?(@git_path[:conf])
145 FileUtils::mkdir_p(@git_path[:image]) \
146 unless FileTest.directory?(@git_path[:image])
147 #FileUtils::mkdir_p(@git_path[:audio]) \
148 # unless FileTest.directory?(@git_path[:audio])
149 #FileUtils::mkdir_p(@git_path[:video]) \
150 # unless FileTest.directory?(@git_path[:video])
151 end
152 def git_init
153 unless FileTest.directory?("#{@git_path[:fnb]}/.git")
154 pwd=Dir.pwd
155 Dir.chdir(@git_path[:fnb])
156 system("git init ")
157 Dir.chdir(pwd)
158 end
159 end
160 def git_commit
161 if program_found?
162 if FileTest.directory?("#{@git_path[:fnb]}")
163 pwd=Dir.pwd
164 Dir.chdir(@git_path[:fnb])
165 system("
166 git add . \
167 && git commit -a
168 ")
169 Dir.chdir(pwd)
170 end
171 end
172 end
173 def populate
174 def identify_language_versions
175 print __FILE__ + ':'
176 p __LINE__
177 end
178 def copy_src_head
179 if @opt.f_pth[:lng] \
180 and File.exist?("#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{@opt.fns}")
181 FileUtils::cp_r(
182 "#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{@opt.fns}",
183 @git_path[:doc]
184 )
185 elsif @opt.fns =~/\.ssm\.sst/
186 ssm=@opt.fns.gsub(/\.ssm\.sst/,'.ssm')
187 FileUtils::cp_r(
188 "#{@env.path.pwd}/#{ssm}",
189 @git_path[:doc]
190 )
191 elsif File.exist?("#{@env.path.pwd}/#{@opt.fns}")
192 FileUtils::cp_r(
193 "#{@env.path.pwd}/#{@opt.fns}",
194 @git_path[:doc]
195 )
196 end
197 end
198 def copy_related_sst_ssi
199 doc_import=[]
200 @rgx_doc_import=/^<<\s(\S+?\.ss[ti])/
201 file_array=IO.readlines(@opt.fns,'')
202 file_array.each do |f|
203 if f =~@rgx_doc_import
204 doc_import = doc_import \
205 + f.scan(@rgx_doc_import).uniq.flatten
206 end
207 end
208 doc_import.each do |f|
209 if @opt.f_pth[:lng]
210 FileUtils::cp_r(
211 "#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{f}",
212 @git_path[:doc]
213 )
214 else
215 FileUtils::cp_r(
216 "#{@env.path.pwd}/#{f}",
217 @git_path[:doc]
218 )
219 end
220 end
221 end
222 def locate_parse_file
223 composite_src=@opt.fns=~/\.ssm$/ ? true : false
224 if composite_src \
225 and not @opt.act[:ao][:set]==:on
226 ##SiSU_Assemble::Composite.new(@opt).read
227 #SiSU_AO::Source.new(@opt).read # -m
228 @env.processing_path.composite_file \
229 + '/' \
230 + @opt.fnb \
231 + '.ssm.sst'
232 elsif composite_src
233 @env.processing_path.composite_file \
234 + '/' \
235 + @opt.fnb \
236 + '.ssm.sst'
237 else
238 @env.path.pwd
239 + '/' \
240 + @opt.fns
241 end
242 end
243 def read_composite
244 #print __FILE__ + ':'
245 #p __LINE__
246 end
247 def sisuyaml_rc
248 sisurc=@env.path.sisurc_path
249 if FileTest.file?(sisurc)
250 FileUtils::cp_r(sisurc,@git_path[:conf])
251 end
252 end
253 def read_src
254 print __FILE__ + ':'
255 p __LINE__
256 end
257 def composite_src?
258 @opt.fns=~/\.ssm$/ ? true : false
259 end
260 def sisusrc_files
261 populate.copy_src_head
262 if composite_src?
263 populate.copy_related_sst_ssi
264 end
265 #parse_file_name=locate_parse_file
266 #parse_file=IO.readlines(parse_file_name,'')
267 populate.sisuyaml_rc #(parse_file)
268 #populate.extract_composite_source
269 #populate.read_composite # or read_each_composite
270 populate.identify_language_versions
271 end
272 self
273 end
274 end
275 end
276 __END__
277 @file.output_path.sisugit