Class: Coopy::Coopy

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCoopy

Returns a new instance of Coopy.



7
8
# File 'lib/lib/coopy/coopy.rb', line 7

def initialize
end

Class Attribute Details

.versionObject

Returns the value of attribute version.



481
482
483
# File 'lib/lib/coopy/coopy.rb', line 481

def version
  @version
end

Instance Attribute Details

#daff_cmdObject

Returns the value of attribute daff_cmd.



75
76
77
# File 'lib/lib/coopy/coopy.rb', line 75

def daff_cmd
  @daff_cmd
end

#format_preferenceObject

protected - in ruby this doesn’t play well with static/inline methods



12
13
14
# File 'lib/lib/coopy/coopy.rb', line 12

def format_preference
  @format_preference
end

#ioObject

Returns the value of attribute io.



13
14
15
# File 'lib/lib/coopy/coopy.rb', line 13

def io
  @io
end

#mvObject

Returns the value of attribute mv.



14
15
16
# File 'lib/lib/coopy/coopy.rb', line 14

def mv
  @mv
end

#statusObject

Returns the value of attribute status.



74
75
76
# File 'lib/lib/coopy/coopy.rb', line 74

def status
  @status
end

Class Method Details

.cell_for(x) ⇒ Object



563
564
565
566
# File 'lib/lib/coopy/coopy.rb', line 563

def Coopy.cell_for(x)
  return nil if x == nil
  return ::Coopy::SimpleCell.new(x)
end

.compare_tables(local, remote) ⇒ Object



485
486
487
488
489
490
491
492
# File 'lib/lib/coopy/coopy.rb', line 485

def Coopy.compare_tables(local,remote)
  ct = ::Coopy::CompareTable.new
  comp = ::Coopy::TableComparisonState.new
  comp.a = local
  comp.b = remote
  ct.attach(comp)
  return ct
end

.compare_tables3(parent, local, remote) ⇒ Object



494
495
496
497
498
499
500
501
502
# File 'lib/lib/coopy/coopy.rb', line 494

def Coopy.compare_tables3(parent,local,remote)
  ct = ::Coopy::CompareTable.new
  comp = ::Coopy::TableComparisonState.new
  comp.p = parent
  comp.a = local
  comp.b = remote
  ct.attach(comp)
  return ct
end

.json_to_table(json) ⇒ Object



568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
# File 'lib/lib/coopy/coopy.rb', line 568

def Coopy.json_to_table(json)
  output = nil
  begin
    _g = 0
    _g1 = Reflect.fields(json)
    while(_g < _g1.length) 
      name = _g1[_g]
      _g+=1
      t = Reflect.field(json,name)
      columns = Reflect.field(t,"columns")
      next if columns == nil
      rows = Reflect.field(t,"rows")
      next if rows == nil
      output = ::Coopy::SimpleTable.new(columns.length,rows.length)
      has_hash = false
      has_hash_known = false
      begin
        _g3 = 0
        _g2 = rows.length
        while(_g3 < _g2) 
          i = _g3
          _g3+=1
          row = rows[i]
          if !has_hash_known 
            has_hash = true if Reflect.fields(row).length == columns.length
            has_hash_known = true
          end
          if !has_hash 
            lst = row
            begin
              _g5 = 0
              _g4 = columns.length
              while(_g5 < _g4) 
                j = _g5
                _g5+=1
                val = lst[j]
                output.set_cell(j,i,::Coopy::Coopy.cell_for(val))
              end
            end
          else 
            _g51 = 0
            _g41 = columns.length
            while(_g51 < _g41) 
              j1 = _g51
              _g51+=1
              val1 = Reflect.field(row,columns[j1])
              output.set_cell(j1,i,::Coopy::Coopy.cell_for(val1))
            end
          end
        end
      end
    end
  end
  output.trim_blank if output != nil
  return output
end

.jsonify(t) ⇒ Object



660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
# File 'lib/lib/coopy/coopy.rb', line 660

def Coopy.jsonify(t)
  workbook = {}
  sheet = Array.new
  w = t.get_width
  h = t.get_height
  txt = ""
  begin
    _g = 0
    while(_g < h) 
      y = _g
      _g+=1
      row = Array.new
      begin
        _g1 = 0
        while(_g1 < w) 
          x = _g1
          _g1+=1
          v = t.get_cell(x,y)
          if v != nil 
            row.push(v[:to_s].call)
          else 
            row.push(nil)
          end
        end
      end
      sheet.push(row)
    end
  end
  workbook["sheet"] = sheet
  return workbook
end

.mainObject



627
628
629
630
631
# File 'lib/lib/coopy/coopy.rb', line 627

def Coopy.main 
  io = ::Coopy::TableIO.new
  coopy1 = ::Coopy::Coopy.new
  return coopy1.coopyhx(io)
end

.random_testsObject

protected - in ruby this doesn’t play well with static/inline methods



506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/lib/coopy/coopy.rb', line 506

def Coopy.random_tests 
  st = ::Coopy::SimpleTable.new(15,6)
  tab = st
  ::Haxe::Log._trace.call("table size is " + _hx_str(tab.get_width) + "x" + _hx_str(tab.get_height),{ file_name: "Coopy.hx", line_number: 44, class_name: "coopy.Coopy", method_name: "randomTests"})
  tab.set_cell(3,4,::Coopy::SimpleCell.new(33))
  ::Haxe::Log._trace.call("element is " + _hx_str(lambda{ s = tab.get_cell(3,4)
  _r = s.to_s}.call()),{ file_name: "Coopy.hx", line_number: 46, class_name: "coopy.Coopy", method_name: "randomTests"})
  compare = ::Coopy::Compare.new
  d1 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(10))
  d2 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(10))
  d3 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(20))
  report = ::Coopy::Report.new
  compare.compare(d1,d2,d3,report)
  ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 54, class_name: "coopy.Coopy", method_name: "randomTests"})
  d2 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(50))
  report.clear
  compare.compare(d1,d2,d3,report)
  ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 58, class_name: "coopy.Coopy", method_name: "randomTests"})
  d2 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(20))
  report.clear
  compare.compare(d1,d2,d3,report)
  ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 62, class_name: "coopy.Coopy", method_name: "randomTests"})
  d1 = ::Coopy::ViewedDatum.get_simple_view(::Coopy::SimpleCell.new(20))
  report.clear
  compare.compare(d1,d2,d3,report)
  ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 66, class_name: "coopy.Coopy", method_name: "randomTests"})
  comp = ::Coopy::TableComparisonState.new
  ct = ::Coopy::CompareTable.new
  comp.a = st
  comp.b = st
  ct.attach(comp)
  ::Haxe::Log._trace.call("comparing tables",{ file_name: "Coopy.hx", line_number: 74, class_name: "coopy.Coopy", method_name: "randomTests"})
  t1 = ::Coopy::SimpleTable.new(3,2)
  t2 = ::Coopy::SimpleTable.new(3,2)
  t3 = ::Coopy::SimpleTable.new(3,2)
  dt1 = ::Coopy::ViewedDatum.new(t1,::Coopy::SimpleView.new)
  dt2 = ::Coopy::ViewedDatum.new(t2,::Coopy::SimpleView.new)
  dt3 = ::Coopy::ViewedDatum.new(t3,::Coopy::SimpleView.new)
  compare.compare(dt1,dt2,dt3,report)
  ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 82, class_name: "coopy.Coopy", method_name: "randomTests"})
  t3.set_cell(1,1,::Coopy::SimpleCell.new("hello"))
  compare.compare(dt1,dt2,dt3,report)
  ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 85, class_name: "coopy.Coopy", method_name: "randomTests"})
  t1.set_cell(1,1,::Coopy::SimpleCell.new("hello"))
  compare.compare(dt1,dt2,dt3,report)
  ::Haxe::Log._trace.call("report is " + _hx_str(report.to_s),{ file_name: "Coopy.hx", line_number: 88, class_name: "coopy.Coopy", method_name: "randomTests"})
  v = ::Coopy::Viterbi.new
  td = ::Coopy::TableDiff.new(nil,nil)
  idx = ::Coopy::Index.new
  dr = ::Coopy::DiffRender.new
  cf = ::Coopy::CompareFlags.new
  hp = ::Coopy::HighlightPatch.new(nil,nil)
  csv = ::Coopy::Csv.new
  tm = ::Coopy::TableModifier.new(nil)
  return 0
end

.show(t) ⇒ Object



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/lib/coopy/coopy.rb', line 633

def Coopy.show(t)
  w = t.get_width
  h = t.get_height
  txt = ""
  begin
    _g = 0
    while(_g < h) 
      y = _g
      _g+=1
      begin
        _g1 = 0
        while(_g1 < w) 
          x = _g1
          _g1+=1
          begin
            s = t.get_cell(x,y)
            txt += s.to_s
          end
          txt += " "
        end
      end
      txt += "\n"
    end
  end
  ::Haxe::Log._trace.call(txt,{ file_name: "Coopy.hx", line_number: 627, class_name: "coopy.Coopy", method_name: "show"})
end

Instance Method Details

#command(io, cmd, args) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/lib/coopy/coopy.rb', line 77

def command(io,cmd,args)
  r = 0
  r = io.command(cmd,args) if io.async
  if r != 999 
    io.write_stdout("$ " + _hx_str(cmd))
    begin
      _g = 0
      while(_g < args.length) 
        arg = args[_g]
        _g+=1
        io.write_stdout(" ")
        spaced = (arg.index(" ",nil || 0) || -1) >= 0
        io.write_stdout("\"") if spaced
        io.write_stdout(arg)
        io.write_stdout("\"") if spaced
      end
    end
    io.write_stdout("\n")
  end
  r = io.command(cmd,args) if !io.async
  return r
end

#coopyhx(io) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/lib/coopy/coopy.rb', line 251

def coopyhx(io)
  args = io.args
  return ::Coopy::Coopy.random_tests if args[0] == "--test"
  more = true
  output = nil
  css_output = nil
  fragment = false
  pretty = true
  inplace = false
  git = false
  color = false
  flags = ::Coopy::CompareFlags.new
  flags.always_show_header = true
  while(more) 
    more = false
    begin
      _g1 = 0
      _g = args.length
      while(_g1 < _g) 
        i = _g1
        _g1+=1
        tag = args[i]
        if tag == "--output" 
          more = true
          output = args[i + 1]
          args.slice!(i,2)
          break
        elsif tag == "--css" 
          more = true
          fragment = true
          css_output = args[i + 1]
          args.slice!(i,2)
          break
        elsif tag == "--fragment" 
          more = true
          fragment = true
          args.slice!(i,1)
          break
        elsif tag == "--plain" 
          more = true
          pretty = false
          args.slice!(i,1)
          break
        elsif tag == "--all" 
          more = true
          flags.show_unchanged = true
          args.slice!(i,1)
          break
        elsif tag == "--act" 
          more = true
          flags.acts = {} if flags.acts == nil
          begin
            flags.acts[args[i + 1]] = true
            true
          end
          args.slice!(i,2)
          break
        elsif tag == "--context" 
          more = true
          context = args[i + 1].to_i
          flags.unchanged_context = context if context >= 0
          args.slice!(i,2)
          break
        elsif tag == "--inplace" 
          more = true
          inplace = true
          args.slice!(i,1)
          break
        elsif tag == "--git" 
          more = true
          git = true
          args.slice!(i,1)
          break
        elsif tag == "--color" 
          more = true
          color = true
          args.slice!(i,1)
          break
        end
      end
    end
  end
  cmd = args[0]
  if args.length < 2 
    if cmd == "version" 
      io.write_stdout(_hx_str(::Coopy::Coopy.version) + "\n")
      return 0
    end
    if cmd == "git" 
      io.write_stdout("You can use daff to improve git's handling of csv files, by using it as a\ndiff driver (for showing what has changed) and as a merge driver (for merging\nchanges between multiple versions).\n")
      io.write_stdout("\n")
      io.write_stdout("Automatic setup\n")
      io.write_stdout("---------------\n\n")
      io.write_stdout("Run:\n")
      io.write_stdout("  daff git csv\n")
      io.write_stdout("\n")
      io.write_stdout("Manual setup\n")
      io.write_stdout("------------\n\n")
      io.write_stdout("Create and add a file called .gitattributes in the root directory of your\nrepository, containing:\n\n")
      io.write_stdout("  *.csv diff=daff-csv\n")
      io.write_stdout("  *.csv merge=daff-csv\n")
      io.write_stdout("\nCreate a file called .gitconfig in your home directory (or alternatively\nopen .git/config for a particular repository) and add:\n\n")
      io.write_stdout("  [diff \"daff-csv\"]\n")
      io.write_stdout("  command = daff diff --color --git\n")
      io.write_stderr("\n")
      io.write_stdout("  [merge \"daff-csv\"]\n")
      io.write_stdout("  name = daff tabular merge\n")
      io.write_stdout("  driver = daff merge --output %A %O %A %B\n\n")
      io.write_stderr("Make sure you can run daff from the command-line as just \"daff\" - if not,\nreplace \"daff\" in the driver and command lines above with the correct way\nto call it. Omit --color if your terminal does not support ANSI colors.")
      io.write_stderr("\n")
      return 0
    end
    io.write_stderr("daff can produce and apply tabular diffs.\n")
    io.write_stderr("Call as:\n")
    io.write_stderr("  daff [--color] [--output OUTPUT.csv] a.csv b.csv\n")
    io.write_stderr("  daff [--output OUTPUT.csv] parent.csv a.csv b.csv\n")
    io.write_stderr("  daff [--output OUTPUT.jsonbook] a.jsonbook b.jsonbook\n")
    io.write_stderr("  daff patch [--inplace] [--output OUTPUT.csv] a.csv patch.csv\n")
    io.write_stderr("  daff merge [--inplace] [--output OUTPUT.csv] parent.csv a.csv b.csv\n")
    io.write_stderr("  daff trim [--output OUTPUT.csv] source.csv\n")
    io.write_stderr("  daff render [--output OUTPUT.html] diff.csv\n")
    io.write_stderr("  daff git\n")
    io.write_stderr("  daff version\n")
    io.write_stderr("\n")
    io.write_stderr("The --inplace option to patch and merge will result in modification of a.csv.\n")
    io.write_stderr("\n")
    io.write_stderr("If you need more control, here is the full list of flags:\n")
    io.write_stderr("  daff diff [--output OUTPUT.csv] [--context NUM] [--all] [--act ACT] a.csv b.csv\n")
    io.write_stderr("     --color:       highlight changes with terminal colors\n")
    io.write_stderr("     --context NUM: show NUM rows of context\n")
    io.write_stderr("     --all:         do not prune unchanged rows\n")
    io.write_stderr("     --act ACT:     show only a certain kind of change (update, insert, delete)\n")
    io.write_stderr("\n")
    io.write_stderr("  daff diff --git path old-file old-hex old-mode new-file new-hex new-mode\n")
    io.write_stderr("     --git:         process arguments provided by git to diff drivers\n")
    io.write_stderr("\n")
    io.write_stderr("  daff render [--output OUTPUT.html] [--css CSS.css] [--fragment] [--plain] diff.csv\n")
    io.write_stderr("     --css CSS.css: generate a suitable css file to go with the html\n")
    io.write_stderr("     --fragment:    generate just a html fragment rather than a page\n")
    io.write_stderr("     --plain:       do not use fancy utf8 characters to make arrows prettier\n")
    return 1
  end
  cmd1 = args[0]
  offset = 1
  if !Lambda.has(["diff","patch","merge","trim","render","git","version"],cmd1) 
    if (cmd1.index(".",nil || 0) || -1) != -1 || (cmd1.index("--",nil || 0) || -1) == 0 
      cmd1 = "diff"
      offset = 0
    end
  end
  if cmd1 == "git" 
    types = args.slice!(offset,args.length - offset)
    return self.install_git_driver(io,types)
  end
  if git 
    ct = args.length - offset
    if ct != 7 
      io.write_stderr("Expected 7 parameters from git, but got " + _hx_str(ct) + "\n")
      return 1
    end
    git_args = args.slice!(offset,ct)
    args.slice!(0,args.length)
    offset = 0
    path = git_args[0]
    old_file = git_args[1]
    new_file = git_args[4]
    io.write_stdout("--- a/" + _hx_str(path) + "\n")
    io.write_stdout("+++ b/" + _hx_str(path) + "\n")
    args.push(old_file)
    args.push(new_file)
  end
  tool = ::Coopy::Coopy.new
  tool.io = io
  parent = nil
  if args.length - offset >= 3 
    parent = tool.load_table(args[offset])
    offset+=1
  end
  aname = args[offset]
  a = tool.load_table(aname)
  b = nil
  b = tool.load_table(args[1 + offset]) if args.length - offset >= 2
  if inplace 
    io.write_stderr("Please do not use --inplace when specifying an output.\n") if output != nil
    output = aname
    return 1
  end
  output = "-" if output == nil
  ok = true
  if cmd1 == "diff" 
    ct1 = ::Coopy::Coopy.compare_tables3(parent,a,b)
    align = ct1.align
    td = ::Coopy::TableDiff.new(align,flags)
    o = ::Coopy::SimpleTable.new(0,0)
    td.hilite(o)
    if color 
      render = ::Coopy::TerminalDiffRender.new
      tool.save_text(output,render.render(o))
    else 
      tool.save_table(output,o)
    end
  elsif cmd1 == "patch" 
    patcher = ::Coopy::HighlightPatch.new(a,b)
    patcher.apply
    tool.save_table(output,a)
  elsif cmd1 == "merge" 
    merger = ::Coopy::Merger.new(parent,a,b,flags)
    conflicts = merger.apply
    ok = conflicts == 0
    io.write_stderr(_hx_str(conflicts) + " conflict" + _hx_str((((conflicts > 1) ? "s" : ""))) + "\n") if conflicts > 0
    tool.save_table(output,a)
  elsif cmd1 == "trim" 
    tool.save_table(output,a)
  elsif cmd1 == "render" 
    renderer = ::Coopy::DiffRender.new
    renderer.use_pretty_arrows(pretty)
    renderer.render(a)
    renderer.complete_html if !fragment
    tool.save_text(output,renderer.html)
    tool.save_text(css_output,renderer.sample_css) if css_output != nil
  end
  if ok 
    return 0
  else 
    return 1
  end
end

#install_git_driver(io, formats) ⇒ Object



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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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
# File 'lib/lib/coopy/coopy.rb', line 102

def install_git_driver(io,formats)
  r = 0
  if @status == nil 
    @status = {}
    @daff_cmd = ""
  end
  key = "hello"
  if !@status.include?(key) 
    io.write_stdout("Setting up git to use daff on")
    begin
      _g = 0
      while(_g < formats.length) 
        format = formats[_g]
        _g+=1
        io.write_stdout(" *." + _hx_str(format))
      end
    end
    io.write_stdout(" files\n")
    @status[key] = r
  end
  key = "can_run_git"
  if !@status.include?(key) 
    r = self.command(io,"git",["--version"])
    return r if r == 999
    @status[key] = r
    if r != 0 
      io.write_stderr("! Cannot run git, aborting\n")
      return 1
    end
    io.write_stdout("- Can run git\n")
  end
  daffs = ["daff","daff.rb","daff.py"]
  if @daff_cmd == "" 
    begin
      _g1 = 0
      while(_g1 < daffs.length) 
        daff = daffs[_g1]
        _g1+=1
        key1 = "can_run_" + _hx_str(daff)
        if !@status.include?(key1) 
          r = self.command(io,daff,["version"])
          return r if r == 999
          @status[key1] = r
          if r == 0 
            @daff_cmd = daff
            io.write_stdout("- Can run " + _hx_str(daff) + " as \"" + _hx_str(daff) + "\"\n")
            break
          end
        end
      end
    end
    if @daff_cmd == "" 
      io.write_stderr("! Cannot find daff, is it in your path?\n")
      return 1
    end
  end
  begin
    _g2 = 0
    while(_g2 < formats.length) 
      format1 = formats[_g2]
      _g2+=1
      key = "have_diff_driver_" + _hx_str(format1)
      if !@status.include?(key) 
        r = self.command(io,"git",["config","--global","--get","diff.daff-" + _hx_str(format1) + ".command"])
        return r if r == 999
        @status[key] = r
      end
      have_diff_driver = @status[key] == 0
      key = "add_diff_driver_" + _hx_str(format1)
      if !@status.include?(key) 
        if !have_diff_driver 
          r = self.command(io,"git",["config","--global","diff.daff-" + _hx_str(format1) + ".command",_hx_str(@daff_cmd) + " diff --color --git"])
          return r if r == 999
          io.write_stdout("- Added diff driver for " + _hx_str(format1) + "\n")
        else 
          r = 0
          io.write_stdout("- Already have diff driver for " + _hx_str(format1) + ", not touching it\n")
        end
        @status[key] = r
      end
      key = "have_merge_driver_" + _hx_str(format1)
      if !@status.include?(key) 
        r = self.command(io,"git",["config","--global","--get","merge.daff-" + _hx_str(format1) + ".driver"])
        return r if r == 999
        @status[key] = r
      end
      have_merge_driver = @status[key] == 0
      key = "name_merge_driver_" + _hx_str(format1)
      if !@status.include?(key) 
        if !have_merge_driver 
          r = self.command(io,"git",["config","--global","merge.daff-" + _hx_str(format1) + ".name","daff tabular " + _hx_str(format1) + " merge"])
          return r if r == 999
        else 
          r = 0
        end
        @status[key] = r
      end
      key = "add_merge_driver_" + _hx_str(format1)
      if !@status.include?(key) 
        if !have_merge_driver 
          r = self.command(io,"git",["config","--global","merge.daff-" + _hx_str(format1) + ".driver",_hx_str(@daff_cmd) + " merge --output %A %O %A %B"])
          return r if r == 999
          io.write_stdout("- Added merge driver for " + _hx_str(format1) + "\n")
        else 
          r = 0
          io.write_stdout("- Already have merge driver for " + _hx_str(format1) + ", not touching it\n")
        end
        @status[key] = r
      end
    end
  end
  if !io.exists(".git/config") 
    io.write_stderr("! This next part needs to happen in a git repository.\n")
    io.write_stderr("! Please run again from the root of a git repository.\n")
    return 1
  end
  attr = ".gitattributes"
  txt = ""
  post = ""
  if !io.exists(attr) 
    io.write_stdout("- No .gitattributes file\n")
  else 
    io.write_stdout("- You have a .gitattributes file\n")
    txt = io.get_content(attr)
  end
  need_update = false
  begin
    _g3 = 0
    while(_g3 < formats.length) 
      format2 = formats[_g3]
      _g3+=1
      if (txt.index("*." + _hx_str(format2),nil || 0) || -1) >= 0 
        io.write_stderr("- Your .gitattributes file already mentions *." + _hx_str(format2) + "\n")
      else 
        post += "*." + _hx_str(format2) + " diff=daff-" + _hx_str(format2) + "\n"
        post += "*." + _hx_str(format2) + " merge=daff-" + _hx_str(format2) + "\n"
        io.write_stdout("- Placing the following lines in .gitattributes:\n")
        io.write_stdout(post)
        txt += "\n" if txt != "" && !need_update
        txt += post
        need_update = true
      end
    end
  end
  io.save_content(attr,txt) if need_update
  io.write_stdout("- Done!\n")
  return 0
end

#load_table(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/lib/coopy/coopy.rb', line 37

def load_table(name)
  txt = @io.get_content(name)
  begin
    json = ::Haxe::Format::JsonParser.new(txt).parse_rec
    @format_preference = "json"
    t = ::Coopy::Coopy.json_to_table(json)
    raise "JSON failed" if t == nil
    return t
  rescue => e
    csv = ::Coopy::Csv.new
    @format_preference = "csv"
    data = csv.parse_table(txt)
    h = data.length
    w = 0
    w = data[0].length if h > 0
    output = ::Coopy::SimpleTable.new(w,h)
    begin
      _g = 0
      while(_g < h) 
        i = _g
        _g+=1
        begin
          _g1 = 0
          while(_g1 < w) 
            j = _g1
            _g1+=1
            val = data[i][j]
            output.set_cell(j,i,::Coopy::Coopy.cell_for(val))
          end
        end
      end
    end
    output.trim_blank if output != nil
    return output
  end
end

#save_table(name, t) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/lib/coopy/coopy.rb', line 16

def save_table(name,t)
  txt = ""
  if @format_preference != "json" 
    csv = ::Coopy::Csv.new
    txt = csv.render_table(t)
  else 
    value = ::Coopy::Coopy.jsonify(t)
    txt = ::Haxe::Format::JsonPrinter._print(value,nil,nil)
  end
  return self.save_text(name,txt)
end

#save_text(name, txt) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/lib/coopy/coopy.rb', line 28

def save_text(name,txt)
  if name != "-" 
    @io.save_content(name,txt)
  else 
    @io.write_stdout(txt)
  end
  return true
end