c&d: po4a (& git) revisited, revisit
[software/sisu] / lib / sisu / current / 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/current/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]) unless FileTest.directory?(@git_path[:fnb])
136 FileUtils::mkdir_p(@git_path[:doc]) unless FileTest.directory?(@git_path[:doc])
137 FileUtils::mkdir_p(@git_path[:po]) unless FileTest.directory?(@git_path[:po])
138 FileUtils::mkdir_p(@git_path[:pot]) unless FileTest.directory?(@git_path[:pot])
139 FileUtils::mkdir_p(@git_path[:conf]) unless FileTest.directory?(@git_path[:conf])
140 FileUtils::mkdir_p(@git_path[:image]) unless FileTest.directory?(@git_path[:image])
141 #FileUtils::mkdir_p(@git_path[:audio]) unless FileTest.directory?(@git_path[:audio])
142 #FileUtils::mkdir_p(@git_path[:video]) unless FileTest.directory?(@git_path[:video])
143 end
144 def git_init
145 unless FileTest.directory?("#{@git_path[:fnb]}/.git")
146 pwd=Dir.pwd
147 Dir.chdir(@git_path[:fnb])
148 system("git init ")
149 Dir.chdir(pwd)
150 end
151 end
152 def git_commit
153 if program_found?
154 if FileTest.directory?("#{@git_path[:fnb]}")
155 pwd=Dir.pwd
156 Dir.chdir(@git_path[:fnb])
157 system("
158 git add . \
159 && git commit -a
160 ")
161 Dir.chdir(pwd)
162 end
163 end
164 end
165 def populate
166 def identify_language_versions
167 print __FILE__ + ':'
168 p __LINE__
169 end
170 def copy_src_head
171 if @opt.f_pth[:lng]
172 FileUtils::cp_r("#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{@opt.fns}",@git_path[:doc])
173 elsif @opt.fns =~/\.ssm\.sst/
174 ssm=@opt.fns.gsub(/\.ssm\.sst/,'.ssm')
175 FileUtils::cp_r("#{@env.path.pwd}/#{ssm}",@git_path[:doc])
176 else
177 FileUtils::cp_r("#{@env.path.pwd}/#{@opt.fns}",@git_path[:doc])
178 end
179 end
180 def copy_related_sst_ssi
181 doc_import=[]
182 @rgx_doc_import=/^<<\s(\S+?\.ss[ti])/
183 file_array=IO.readlines(@opt.fns,'')
184 file_array.each do |f|
185 if f =~@rgx_doc_import
186 doc_import = doc_import + f.scan(@rgx_doc_import).uniq.flatten
187 end
188 end
189 doc_import.each do |f|
190 if @opt.f_pth[:lng]
191 FileUtils::cp_r("#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{f}",@git_path[:doc])
192 else
193 FileUtils::cp_r("#{@env.path.pwd}/#{f}",@git_path[:doc])
194 end
195 end
196 end
197 def locate_parse_file
198 composite_src=@opt.fns=~/\.ssm$/ ? true : false
199 if composite_src \
200 and not @opt.act[:ao][:set]==:on
201 ##SiSU_Assemble::Composite.new(@opt).read
202 #SiSU_AO::Source.new(@opt).read # -m
203 "#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst"
204 elsif composite_src
205 "#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst"
206 else "#{@env.path.pwd}/#{@opt.fns}"
207 end
208 end
209 def read_composite
210 #print __FILE__ + ':'
211 #p __LINE__
212 end
213 def sisuyaml_rc
214 sisurc=@env.path.sisurc_path
215 if FileTest.file?(sisurc)
216 FileUtils::cp_r(sisurc,@git_path[:conf])
217 end
218 end
219 def read_src
220 print __FILE__ + ':'
221 p __LINE__
222 end
223 def composite_src?
224 @opt.fns=~/\.ssm$/ ? true : false
225 end
226 def sisusrc_files
227 populate.copy_src_head
228 if composite_src?
229 populate.copy_related_sst_ssi
230 end
231 #parse_file_name=locate_parse_file
232 #parse_file=IO.readlines(parse_file_name,'')
233 populate.sisuyaml_rc #(parse_file)
234 #populate.extract_composite_source
235 #populate.read_composite # or read_each_composite
236 populate.identify_language_versions
237 end
238 self
239 end
240 end
241 end
242 __END__
243 @file.output_path.sisugit