class Pod::Command::Lzsource

Public Class Methods

new(argv) click to toggle source
Calls superclass method
# File lib/cocoapods-lzsource/command/lzsource.rb, line 38
def initialize(argv)
  @list = argv.flag?('list')
  @info = argv.flag?('query')
  @clear = argv.flag?('clear')
  @reset = argv.flag?('reset')
  @name = argv.shift_argument
  super
end
options() click to toggle source

self.arguments = [CLAide::Argument.new(%w(NAME), true)]

# File lib/cocoapods-lzsource/command/lzsource.rb, line 28
def self.options
  [
          ['--list', 'Show all items list.'],
    ['--clear', 'Clear all items.'],
    ['--query', 'Query a item information.'],
    ['--reset', 'Reset token and gitlab url.'],
  ]
  # .concat(super)
end

Public Instance Methods

checkPod() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 216
def checkPod
    podPath = Dir.pwd+'/Pods/'
    if File.directory?(podPath)
    
    else
      UI.puts "Please check the current directory.This project directory may be not a cocoapods project."
      log()
    end
end
cleanCache() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 233
def cleanCache
  cachePath = File.expand_path('~')+"/Library/Developer/Xcode/DerivedData/"
  if File.directory?(cachePath)
    `rm -r #{cachePath} >/dev/null 2>&1`
  end
end
clear() click to toggle source

lzsource –clear

# File lib/cocoapods-lzsource/command/lzsource.rb, line 278
def clear
  if File.exist?(InstallCodePathFile)
      File.open(InstallCodePathFile,"r").each_line do |line|
        addr = line.gsub("\n", '')
        arr = addr.split("***")
        if File.directory?(arr[1])
            `sudo rm -rf #{arr[1]}`
        end
      end
      File.delete(InstallCodePathFile)
  end
  UI.puts 'Clear successful!'
end
createDownloadDir() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 189
def createDownloadDir

  if File.directory?($CodePath)
    `sudo rm -rf #{$CodePath}`
  end

  `sudo mkdir -p -m 777 #{$CodePath};sudo chown -R $(whoami) #{$CodePath}`

  if !File.directory?($CodePath)
    UI.puts 'Failed to create install path.'
    log()
  end
end
download() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 203
def download
  t = Thread.new {
    startLoading()
  }
  cloneFlag = system("sudo git clone #{$CodeAddr} #{$CodePath} >/dev/null 2>&1")
  Thread.kill(t)
  if cloneFlag == false
    UI.puts 'Failed to download source code.'
    log()
  end
  print "\rDownload successful!\n"
end
getDebugPath() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 153
def getDebugPath
  
  temp_dir = 'unknow'
  
  at_name = `dwarfdump -debug-str -arch=arm64 --lookup 0x0000002f #{$LibPath} | grep 'DW_AT_name' | head -1`
  arr = at_name.split('"')
  if arr.size > 1
    if arr[1].include?(SplitWords)
      temp = arr[1].split(SplitWords)
      if temp.size > 0
        temp_dir = temp[0]+SplitWords
      end
    end
  end

  temp_path = 'unknow'

  at_comp_dir = `dwarfdump -debug-str -arch=arm64 --lookup 0x0000002f #{$LibPath} | grep 'DW_AT_comp_dir' | head -1`
  arr = at_comp_dir.split('"')
  if arr.size > 1
    if arr[1].include?(SplitWords)
      temp = arr[1].split(SplitWords)
      if temp.size > 1
        temp_path = temp[1]
      end
    end
  end

  if temp_dir != 'unknow' && temp_path != 'unknow'
    $CodePath = temp_dir+temp_path
  else
    UI.puts 'Failed to get install path.'
    log()
  end
end
getLibPath() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 123
def getLibPath
  podPath = Dir.pwd+'/Pods/'
  path = Dir.pwd+'/Pods/'+$ProjectDir
  if File.directory?(podPath)
    if File.directory?(path)
     traverse_dir(path)
     if $LibPath == 'unknow'
      UI.puts 'Failed to get lib path.'
      log()
    end
   else
    UI.puts "Failed to get pod path.Please check the parameter."
    log()
   end
  else
    UI.puts "Failed to get pod path.This project directory may be not a cocoapods project."
    log()
  end
end
getSourceCodeInfo(keyword) click to toggle source

下载源代码流程 lzsource

# File lib/cocoapods-lzsource/command/lzsource.rb, line 100
def getSourceCodeInfo(keyword)

  gitlabHttp= GitLabHttp.new 
  info = gitlabHttp.getSourceCodeInfo(keyword)
  if info.count > 0
    $CodeAddr = info[2]
    $ProjectDir = info[3]
  else
    UI.puts "No search result by the keyword.Please check the parameter."
    log()
  end

  if $ProjectDir == 'unknow'
    UI.puts 'Failed to get lib dir.'
    log()
  end
  if $CodeAddr == 'unknow'
    UI.puts 'Failed to get git address.'
    log()
  end

end
info(keyword) click to toggle source

lzsource –info

# File lib/cocoapods-lzsource/command/lzsource.rb, line 261
def info(keyword)
  gitlabHttp= GitLabHttp.new 
  info = gitlabHttp.getProjectInfo(keyword)
  if info.count > 0
    puts '----------------'
  end
  info.each do |d|
    puts 'Repository name:'+d[0]
    puts 'Repository web:'+d[1]
    puts 'Repository ssh:'+d[2]
    # puts 'Repository path:'+d[3]
    puts '----------------'
  end
end
list() click to toggle source

lzsource –list

# File lib/cocoapods-lzsource/command/lzsource.rb, line 241
def list
  if File.exist?(InstallCodePathFile)
    UI.puts "Currently installed:"
    tempNames = Array.new
    names = Array.new
    count = 0
    File.open(InstallCodePathFile,"r").each_line do |line|
      temp = line.gsub("\n", '')
      arr = temp.split("***")
      if !tempNames.include?(arr[0])
        names << " "+"#{count+1}:"+ arr[0]
        tempNames << arr[0]
        count = count +1
      end
    end
    puts names
  end
end
log() click to toggle source

tools

# File lib/cocoapods-lzsource/command/lzsource.rb, line 302
def log
  # UI.puts ''
 #  UI.puts 'Dir  Name:'+$ProjectDir
 #  UI.puts 'Lib  Path:'+$LibPath
 #  UI.puts 'Code Path:'+$CodePath
 #  UI.puts 'Code Addr:'+$CodeAddr
  exit
end
reset() click to toggle source

lzsource –reset

# File lib/cocoapods-lzsource/command/lzsource.rb, line 294
def reset
  gitlabHttp= GitLabHttp.new 
  gitlabHttp.resetInfo()
end
run() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 53
def run
  if @clear != true &&  @list != true && @reset != true && @query != true && @name.nil?
          help!
          log()
  end
  if @clear == true
    checkPod()
          clear()
  elsif @list == true
    checkPod()
          list()
  elsif @reset == true
    checkPod()
    reset()
  elsif @query == true
          if @name.nil?
                  help!
                  log()
          else
      checkPod()
                  info(@name)
          end
  else

    checkPod()

    getSourceCodeInfo(@name) # CodeAddr ProjectDir

          getLibPath() # LibPath

          getDebugPath() # $CodePath
          
    createDownloadDir()

    download()

    saveCodePath()

    cleanCache()

    list()

  end
end
saveCodePath() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 226
def saveCodePath
  f=File.open(InstallCodePathFile,"a+")
  f.puts $ProjectDir+"***"+$CodePath
  f.close
  
end
startLoading() click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 311
def startLoading
  spin = ["\\",'|','/','-']
  cunt = 0
  while true
    cunt +=1
    str = spin[cunt%4]
    print "downloading:#{str}"
    sleep 0.12
    print "\r"
  end
end
traverse_dir(file_path) click to toggle source
# File lib/cocoapods-lzsource/command/lzsource.rb, line 143
def traverse_dir(file_path)
  Find.find(file_path) do |filename|
    extn = File.extname filename
    if extn == '.a'
      $LibPath = filename
      break
    end
  end
end
validate!() click to toggle source
Calls superclass method
# File lib/cocoapods-lzsource/command/lzsource.rb, line 47
def validate!
  super

  # help!
end