summaryrefslogtreecommitdiffstats
path: root/tinyusb/test/vendor/ceedling/lib/ceedling/file_wrapper.rb
blob: 1680ca520791ac2507a8a92852bd2ca0185a0683 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
73
74
75
76
77
78
79
80
81
82
83
require 'rubygems'
require 'rake' # for FileList
require 'fileutils'
require 'ceedling/constants'


class FileWrapper

  def get_expanded_path(path)
    return File.expand_path(path)
  end

  def basename(path, extension=nil)
    return File.basename(path, extension) if extension
    return File.basename(path)
  end

  def exist?(filepath)
    return true if (filepath == NULL_FILE_PATH)
    return File.exist?(filepath)
  end

  def directory?(path)
    return File.directory?(path)
  end

  def dirname(path)
    return File.dirname(path)
  end

  def directory_listing(glob)
    return Dir.glob(glob, File::FNM_PATHNAME)
  end

  def rm_f(filepath, options={})
    FileUtils.rm_f(filepath, options)
  end

  def rm_r(filepath, options={})
    FileUtils.rm_r(filepath, options={})
  end

  def cp(source, destination, options={})
    FileUtils.cp(source, destination, options)
  end

  def compare(from, to)
    return FileUtils.compare_file(from, to)
  end

  def open(filepath, flags)
    File.open(filepath, flags) do |file|
      yield(file)
    end
  end

  def read(filepath)
    return File.read(filepath)
  end

  def touch(filepath, options={})
    FileUtils.touch(filepath, options)
  end

  def write(filepath, contents, flags='w')
    File.open(filepath, flags) do |file|
      file.write(contents)
    end
  end

  def readlines(filepath)
    return File.readlines(filepath)
  end

  def instantiate_file_list(files=[])
    return FileList.new(files)
  end

  def mkdir(folder)
    return FileUtils.mkdir_p(folder)
  end

end