Skip to content

Instantly share code, notes, and snippets.

@archiloque
Created November 22, 2013 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archiloque/7602045 to your computer and use it in GitHub Desktop.
Save archiloque/7602045 to your computer and use it in GitHub Desktop.
Parse a gitolite configuration file
# Parse a gitolite configuration file
# Copyright (c) 2011 - 2013, Julien Kirch - Licensed under MIT license
projects = []
# Regex for repo name []repo foo/bar]
REPO_NAME_REGEX = /\Arepo (.*)\n\z/
# Regex for project description [foo/bar "owner" = "Description of repo"], owner may be empty
REPO_INFO_REGEX = /\A([^ ]*) "([^"]*)" = "(.*)"\n\z/
# Regex for access rights [ RW+ = username1 username2]
REPO_ACCESS_REGEX = /\A ([^ ]*) = (.*)\n\z/
content = File.readlines('gitolite.conf')
i = 0
reading_finished = false
until reading_finished
current_project = {}
projects << current_project
current_project[:repo_name] = REPO_NAME_REGEX.match(content[i])[1]
i += 1
access_rights = current_project[:access_rights] = {}
while content[i] != "\n"
current_access_rights = REPO_ACCESS_REGEX.match(content[i])
access_rights[current_access_rights[1]] = current_access_rights[2].split(' ')
i+= 1
end
i+= 1
repo_info = REPO_INFO_REGEX.match(content[i])
unless repo_info[2].empty?
current_project[:owner] = repo_info[2]
end
unless repo_info[3].empty?
current_project[:description] = repo_info[3]
end
i+= 2
if content[i].nil?
reading_finished = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment