class TYUtil::TYFile

Public Class Methods

add_to_line(target, line_content, line_number) click to toggle source
# File lib/tuya/ci/core/util/file.rb, line 15
def self.add_to_line(target, line_content, line_number)
        line_number_temp = 0
        target.each_line do |line|
                if (line_number_temp += 1) == line_number
                        target.gsub!(/#{line}/, "#{line}#{line_content}\n")
                end
        end
        target
end
delete(path) click to toggle source
# File lib/tuya/ci/core/util/file.rb, line 7
def self.delete(path)
        `rm #{path}`
end
folder_copy(from, to, is_need_delete=true ) click to toggle source
# File lib/tuya/ci/core/util/file.rb, line 38
def self.folder_copy(from, to, is_need_delete=true )

        target = to + '/' << from.split('/')[-1]

        if is_need_delete
                TYCiCore::EXE.exe('rm', %W(-rf #{to})) if File.exist? target
        else
                raise 'File to copy at is exist.'
        end

        TYCiCore::EXE.exe('mkdir', %W(-p #{to}))

        TYCiCore::EXE.exe('cp', %W(-a #{from} #{to}))

        target
end
line_contain_content(target, content, lastMatch=true) click to toggle source
# File lib/tuya/ci/core/util/file.rb, line 25
def self.line_contain_content(target, content, lastMatch=true)
        line_number = 0
        exist_num = 0
        if !(content.nil? || content.empty?)
                target.each_line do |line|
                        line_number += 1
                        exist_num = line_number if line.include?(content)
                        break unless lastMatch
                end
        end
        exist_num
end
podspec_files(podspec) click to toggle source

def self.copy(from, to, is_need_delete=true)

if File.exist? from
        TYCiCore::EXE.exe('cp', %W(-a #{from} #{to}))
        TYCiCore::EXE.exe('rm', %W(-rf #{to})) if is_needend_delete
end
to

end

# File lib/tuya/ci/core/util/file.rb, line 63
def self.podspec_files(podspec)
        if podspec
                path = Pathname(podspec)
                raise Informative, "Couldn't find #{podspec}" unless path.exist?
                [path]
        else
                files = Pathname.glob('*.podspec{,.json}')
                # raise Informative, "Couldn't find any podspec files in current directory" if files.empty?
                puts "Couldn't find any podspec files in current directory".red if files.empty?
                files
        end
end
read(filepath) click to toggle source
# File lib/tuya/ci/core/util/file.rb, line 11
def self.read(filepath)

end
unzip(target, path='./') click to toggle source
# File lib/tuya/ci/core/util/file.rb, line 3
def self.unzip(target, path='./')
        `unzip #{target} -d #{path}`
end