Class: SiSU_Git::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/git.rb

Instance Method Summary collapse

Constructor Details

#initialize(opt, process = :complete) ⇒ Source

Returns a new instance of Source.



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
# File 'lib/sisu/git.rb', line 60

def initialize(opt,process=:complete)
  @opt,@process=opt,process
  @env=SiSU_Env::InfoEnv.new
  @md=SiSU_Param::Parameters.new(@opt).get
  @file=SiSU_Env::FileOp.new(@md)
  l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language
  unless @opt.lng==l[:c] # @md.i18n[0]==l[:c]
    p "using: #{@opt.lng} (@make: :language:); filename #{@md.fns} filename language: #{l[:c]}, mismatch"
  end
  if @env.output_dir_structure.multilingual?
    m=/((.+?)(?:\~\w{2,3})?)\.((?:-|ssm\.)?sst|ssm)$/ #watch added match for sss
    fnb,fnt=@opt.fns[m,2],@opt.fns[m,3]
  else m=/(.+?)\.((?:-|ssm\.)?sst|ssm)$/
    fnb=@fnn=@opt.fns[m,1]
    fnt=@opt.fns[m,2]
  end
  git_path_fnb=@env.processing_path.git + '/' + fnb
  lng=(@md.opt.lng) ? (@md.opt.lng) : (@md.i18n[0])
  @git_path={
    fnb:       git_path_fnb,
    doc:       git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:doc] + '/' + lng,
    po:        git_path_fnb + '/' + Gt[:po] + '/' + lng,
    pot:       git_path_fnb + '/' + Gt[:pot],
    conf:      git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:conf],
    image:     git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:image],
    audio:     git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:audio],
    video:     git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:video],
    conf:      git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:conf]
  }
  SiSU_AO::Source.new(@opt,nil,@process).read                            # -m
end

Instance Method Details

#composite_src?Boolean

Returns:

  • (Boolean)


255
256
257
# File 'lib/sisu/git.rb', line 255

def composite_src?
  @opt.fns=~/\.ssm$/ ? true : false
end


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/sisu/git.rb', line 196

def copy_related_sst_ssi
  doc_import=[]
  @rgx_doc_import=/^<<\s(\S+?\.ss[ti])/
  file_array=IO.readlines(@opt.fns,'')
  file_array.each do |f|
    if f =~@rgx_doc_import
      doc_import = doc_import \
      + f.scan(@rgx_doc_import).uniq.flatten
    end
  end
  doc_import.each do |f|
    if @opt.f_pth[:lng]
      FileUtils::cp_r(
        "#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{f}",
        @git_path[:doc]
      )
    else
      FileUtils::cp_r(
        "#{@env.path.pwd}/#{f}",
        @git_path[:doc]
      )
    end
  end
end

#copy_src_headObject



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/sisu/git.rb', line 176

def copy_src_head
  if @opt.f_pth[:lng] \
  and File.exist?("#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{@opt.fns}")
    FileUtils::cp_r(
      "#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{@opt.fns}",
      @git_path[:doc]
    )
  elsif @opt.fns =~/\.ssm\.sst/
    ssm=@opt.fns.gsub(/\.ssm\.sst/,'.ssm')
    FileUtils::cp_r(
      "#{@env.path.pwd}/#{ssm}",
      @git_path[:doc]
    )
  elsif File.exist?("#{@env.path.pwd}/#{@opt.fns}")
    FileUtils::cp_r(
      "#{@env.path.pwd}/#{@opt.fns}",
      @git_path[:doc]
    )
  end
end

#create_file_structure_gitObject



91
92
93
94
95
96
# File 'lib/sisu/git.rb', line 91

def create_file_structure_git
  make_dir_fnb
  if program_found?
    git_init
  end
end

#git_commitObject



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/sisu/git.rb', line 158

def git_commit
  if program_found?
    if FileTest.directory?("#{@git_path[:fnb]}")
      pwd=Dir.pwd
      Dir.chdir(@git_path[:fnb])
      system("
        git add . \
        && git commit -a
      ")
      Dir.chdir(pwd)
    end
  end
end

#git_initObject

FileUtils::mkdir_p(@git_path) \

unless FileTest.directory?(@git_path[:audio])

FileUtils::mkdir_p(@git_path) \

unless FileTest.directory?(@git_path[:video])


150
151
152
153
154
155
156
157
# File 'lib/sisu/git.rb', line 150

def git_init
  unless FileTest.directory?("#{@git_path[:fnb]}/.git")
    pwd=Dir.pwd
    Dir.chdir(@git_path[:fnb])
    system("git init ")
    Dir.chdir(pwd)
  end
end

#identify_language_versionsObject



172
173
174
175
# File 'lib/sisu/git.rb', line 172

def identify_language_versions
  print __FILE__ + ':'
  p __LINE__
end

#locate_parse_fileObject



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/sisu/git.rb', line 220

def locate_parse_file
  composite_src=@opt.fns=~/\.ssm$/ ? true : false
  if composite_src \
  and not @opt.act[:ao][:set]==:on
    ##SiSU_Assemble::Composite.new(@opt).read
    #SiSU_AO::Source.new(@opt).read                                         # -m
    @env.processing_path.composite_file \
    + '/' \
    + @opt.fnb \
    + '.ssm.sst'
  elsif composite_src
    @env.processing_path.composite_file \
    + '/' \
    + @opt.fnb \
    + '.ssm.sst'
  else
    @env.path.pwd
    + '/' \
    + @opt.fns
  end
end

#make_dir_fnbObject



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/sisu/git.rb', line 132

def make_dir_fnb
  FileUtils::mkdir_p(@git_path[:fnb]) \
    unless FileTest.directory?(@git_path[:fnb])
  FileUtils::mkdir_p(@git_path[:doc]) \
    unless FileTest.directory?(@git_path[:doc])
  FileUtils::mkdir_p(@git_path[:po]) \
    unless FileTest.directory?(@git_path[:po])
  FileUtils::mkdir_p(@git_path[:pot]) \
    unless FileTest.directory?(@git_path[:pot])
  FileUtils::mkdir_p(@git_path[:conf]) \
    unless FileTest.directory?(@git_path[:conf])
  FileUtils::mkdir_p(@git_path[:image]) \
    unless FileTest.directory?(@git_path[:image])
  #FileUtils::mkdir_p(@git_path[:audio]) \
  #  unless FileTest.directory?(@git_path[:audio])
  #FileUtils::mkdir_p(@git_path[:video]) \
  #  unless FileTest.directory?(@git_path[:video])
end

#populateObject



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/sisu/git.rb', line 171

def populate
  def identify_language_versions
    print __FILE__ + ':'
    p __LINE__
  end
  def copy_src_head
    if @opt.f_pth[:lng] \
    and File.exist?("#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{@opt.fns}")
      FileUtils::cp_r(
        "#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{@opt.fns}",
        @git_path[:doc]
      )
    elsif @opt.fns =~/\.ssm\.sst/
      ssm=@opt.fns.gsub(/\.ssm\.sst/,'.ssm')
      FileUtils::cp_r(
        "#{@env.path.pwd}/#{ssm}",
        @git_path[:doc]
      )
    elsif File.exist?("#{@env.path.pwd}/#{@opt.fns}")
      FileUtils::cp_r(
        "#{@env.path.pwd}/#{@opt.fns}",
        @git_path[:doc]
      )
    end
  end
  def copy_related_sst_ssi
    doc_import=[]
    @rgx_doc_import=/^<<\s(\S+?\.ss[ti])/
    file_array=IO.readlines(@opt.fns,'')
    file_array.each do |f|
      if f =~@rgx_doc_import
        doc_import = doc_import \
        + f.scan(@rgx_doc_import).uniq.flatten
      end
    end
    doc_import.each do |f|
      if @opt.f_pth[:lng]
        FileUtils::cp_r(
          "#{@env.path.pwd}/#{@opt.f_pth[:lng]}/#{f}",
          @git_path[:doc]
        )
      else
        FileUtils::cp_r(
          "#{@env.path.pwd}/#{f}",
          @git_path[:doc]
        )
      end
    end
  end
  def locate_parse_file
    composite_src=@opt.fns=~/\.ssm$/ ? true : false
    if composite_src \
    and not @opt.act[:ao][:set]==:on
      ##SiSU_Assemble::Composite.new(@opt).read
      #SiSU_AO::Source.new(@opt).read                                         # -m
      @env.processing_path.composite_file \
      + '/' \
      + @opt.fnb \
      + '.ssm.sst'
    elsif composite_src
      @env.processing_path.composite_file \
      + '/' \
      + @opt.fnb \
      + '.ssm.sst'
    else
      @env.path.pwd
      + '/' \
      + @opt.fns
    end
  end
  def read_composite
    #print __FILE__ + ':'
    #p __LINE__
  end
  def sisuyaml_rc
    sisurc=@env.path.sisurc_path
    if FileTest.file?(sisurc)
      FileUtils::cp_r(sisurc,@git_path[:conf])
    end
  end
  def read_src
    print __FILE__ + ':'
    p __LINE__
  end
  def composite_src?
    @opt.fns=~/\.ssm$/ ? true : false
  end
  def sisusrc_files
    populate.copy_src_head
    if composite_src?
      populate.copy_related_sst_ssi
    end
    #parse_file_name=locate_parse_file
    #parse_file=IO.readlines(parse_file_name,'')
    populate.sisuyaml_rc #(parse_file)
    #populate.extract_composite_source
    #populate.read_composite # or read_each_composite
    populate.identify_language_versions
  end
  self
end

#program_found?Boolean

Returns:

  • (Boolean)


128
129
130
131
# File 'lib/sisu/git.rb', line 128

def program_found?
  found=`whereis git`
  (found =~/bin\/git\b/) ? true : false
end

#readObject



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
# File 'lib/sisu/git.rb', line 97

def read
  create_file_structure_git
  populate.sisusrc_files
  #if program_found?
  #  git_commit
  #end
  unless @opt.act[:quiet][:set]==:on
    (@opt.act[:verbose][:set]==:on \
    || @opt.act[:verbose_plus][:set]==:on \
    || @opt.act[:maintenance][:set]==:on) \
    ? SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        'Git path',
        @git_path[:fnb]
      ).green_hi_blue
    : SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        'Git path',
        @git_path[:fnb]
      ).green_title_hi
    if (@opt.act[:verbose][:set]==:on \
    || @opt.act[:verbose_plus][:set]==:on \
    || @opt.act[:maintenance][:set]==:on)
      SiSU_Screen::Ansi.new(
        @opt.act[:color_state][:set],
        "Git path",
        "#{@opt.fns} -> #{@git_path[:fnb]}"
      ).warn
    end
  end
end

#read_compositeObject



241
242
243
244
# File 'lib/sisu/git.rb', line 241

def read_composite
  #print __FILE__ + ':'
  #p __LINE__
end

#read_srcObject



251
252
253
254
# File 'lib/sisu/git.rb', line 251

def read_src
  print __FILE__ + ':'
  p __LINE__
end

#sisusrc_filesObject



258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/sisu/git.rb', line 258

def sisusrc_files
  populate.copy_src_head
  if composite_src?
    populate.copy_related_sst_ssi
  end
  #parse_file_name=locate_parse_file
  #parse_file=IO.readlines(parse_file_name,'')
  populate.sisuyaml_rc #(parse_file)
  #populate.extract_composite_source
  #populate.read_composite # or read_each_composite
  populate.identify_language_versions
end

#sisuyaml_rcObject

print __FILE__ + ‘:’ p __LINE__



245
246
247
248
249
250
# File 'lib/sisu/git.rb', line 245

def sisuyaml_rc
  sisurc=@env.path.sisurc_path
  if FileTest.file?(sisurc)
    FileUtils::cp_r(sisurc,@git_path[:conf])
  end
end