Guest User

Untitled

a guest
Feb 21st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. require 'sixcore'
  2. module SixCore
  3. ConfigSvn = Struct.new(:program)
  4.  
  5. # Core module for Subversion
  6. class Svn
  7. attr_accessor(:repos, :user, :pass)
  8.  
  9. COMPONENT = 'SixCore::Svn'
  10. REGEX_LINE = /------------------------------------------------------------------------/
  11. REGEX_INFO = /r(.*) \| (.*) \| (.*) \| (.*) /
  12. REGEX_REVISION = /Revision\: (.*)/
  13. REGEX_MOD = /(^A )|(^M )|(^D )/
  14. REGEX_PBO = /(.*)\.pbo(.*)/
  15. REGEX_FOLDER = /(.*)\\(.*)/
  16.  
  17. @@log = SixCore.log
  18. @@config = SixCore::read_config('svn', 'sixcore/config')
  19. def config
  20. @@config
  21. end
  22.  
  23. # repos:: String, Repository folder or URL
  24. # user:: String, Username
  25. # pass:: String, Password
  26. def initialize(repos = '', user = '', pass = '')
  27. @repos = repos
  28. @user = user
  29. @pass = pass
  30. end
  31.  
  32. # Command Execution function
  33. # cmd:: Command to execute, excl repositor, username, password
  34. def cmd(cmd)
  35. @@log.debug SixCore::prep_msg('Command', :component => COMPONENT, :verbose => cmd)
  36. cmd = "#{cmd} #{@repos}" unless @repos.empty?
  37. cmd = "#{cmd} --username #{@user}" unless @user.empty?
  38. cmd = "#{cmd} --password #{@pass}" unless @pass.empty?
  39. SixCore::proc_cmd("#{@@config.program} #{cmd}")
  40. end
  41.  
  42. # Generates diff list between revisions
  43. # Returns diff list
  44. # old:: String or Integer, start revision number
  45. # new:: String or Integer, end revision number
  46. def diff(old, new)
  47. cmd("diff -r #{old}:#{new} --summarize").split("\n")
  48. end
  49.  
  50. # Fetches SVN info
  51. def info()
  52. cmd('info').split("\n")
  53. end
  54.  
  55. # Fetches SVN List
  56. def list()
  57. cmd('list').split("\n")
  58. end
  59.  
  60. # Executes SVN Update
  61. # Returns Array of Strings
  62. def update()
  63. cmd('update').split("\n")
  64. end
  65.  
  66. # Generates log between revisions
  67. # old:: String or Integer, start revision number
  68. # new:: String or Integer, end revision number
  69. # Returns Array of Strings (log)
  70. def log(old, new)
  71. cmd("log -r#{old}:#{new}").split("\n")
  72. end
  73.  
  74. # Generates array list of log entry information
  75. # old:: String or Integer, start revision number
  76. # new:: String or Integer, end revision number
  77. # Returns Array of log, split between revision number, committer, log, etc
  78. def log_split(old, new)
  79. ar = log(old,new)
  80. log = []
  81. i = -1
  82. entry = []
  83. com = []
  84. ar.each do |line|
  85. if line =~ REGEX_LINE
  86. unless i == -1
  87. entry << com
  88. log << entry
  89. end
  90. entry = []
  91. com = []
  92. i = 0
  93. else
  94. i += 1
  95. if i == 1
  96. entry << [$1, $2, $3, $4] if line =~ REGEX_INFO
  97. elsif i > 2
  98. com << line unless line.empty?
  99. end
  100. end
  101. end
  102. return log
  103. end
  104.  
  105. # Reads current revision number from repository
  106. # Returns revision number
  107. def read_rev()
  108. inf = info()
  109. inf.each do |line| return $1 if line[REGEX_REVISION] end
  110. end
  111.  
  112.  
  113. # Parses log entry and returns type of change
  114. # entry:: String, line of svn log
  115. # folders:: Boolean, include folders?
  116. # slash:: String, what type of file system / \ should be used
  117. # Returns Array, Per Entry format: [integer, formatted entry string]
  118. def parse_entry(entry, folders = true, slash = '/')
  119. # TODO: slash!
  120. # substract everything after first \
  121. if folders
  122. entrymod = entry.gsub(/\\(.*)/, '')
  123. else
  124. entrymod = entry
  125. end
  126. id = -1
  127. case entrymod
  128. when REGEX_MOD
  129. unless $1.nil?
  130. if folders and entry =~ REGEX_FOLDER
  131. # subfolder, so it's a change
  132. id = 1
  133. else
  134. id = 0
  135. end
  136. end
  137.  
  138. unless $2.nil?
  139. id = 1
  140. end
  141.  
  142. unless $3.nil?
  143. id = 2
  144. unless entry =~ REGEX_PBO
  145. if folders and entry =~ REGEX_FOLDER
  146. # subfolder, so it's a change
  147. id = 1
  148. end
  149. end
  150. end
  151. entrymod.gsub!(REGEX_MOD, '')
  152. return [id, entrymod]
  153. end
  154. end
  155. end
  156. end
  157.  
  158. # Yay
Add Comment
Please, Sign In to add comment