Add -C/--checkout-readonly option to wescamp.py
This commit is contained in:
parent
e8925c8487
commit
6949e4679d
2 changed files with 18 additions and 8 deletions
|
@ -211,15 +211,18 @@ class GitHub(object):
|
|||
|
||||
return changed
|
||||
|
||||
def addon(self, name):
|
||||
def addon(self, name, readonly=False):
|
||||
"""Returns an add-on object for the given name.
|
||||
|
||||
name: Name of the add-on.
|
||||
readonly: If set, and the add-on needs to be freshly cloned, use a read-only protocol
|
||||
|
||||
Raises libgithub.Error if no such add-on exists.
|
||||
"""
|
||||
logging.debug("Generating add-on object for {0}".format(name))
|
||||
if not os.path.isdir(self._absolute_path(name)):
|
||||
logging.debug("Add-on {0} not found locally, checking github.".format(name))
|
||||
github_list = self._github_repos_list()
|
||||
github_list = self._github_repos_list(readonly=readonly)
|
||||
matches = filter(lambda x: x[0] == name, github_list)
|
||||
if matches:
|
||||
repo = matches[0]
|
||||
|
@ -297,9 +300,11 @@ class GitHub(object):
|
|||
"""
|
||||
return os.listdir(self.directory)
|
||||
|
||||
def _github_repos_list(self):
|
||||
def _github_repos_list(self, readonly=False):
|
||||
"""Get a list of repositories.
|
||||
|
||||
readonly: Should the tuples have ssh urls or readonly urls.
|
||||
|
||||
Returns a list of tuples that contain the add-on name and the url.
|
||||
"""
|
||||
url = _GITHUB_API_BASE + _GITHUB_API_REPOS
|
||||
|
@ -307,7 +312,7 @@ class GitHub(object):
|
|||
repos = self._github_api_request(request)
|
||||
|
||||
version_suffix = "-{0}".format(self.version)
|
||||
return [(repo["name"][:-len(version_suffix)], repo["ssh_url"])
|
||||
return [(repo["name"][:-len(version_suffix)], repo["git_url"] if readonly else repo["ssh_url"])
|
||||
for repo in repos if repo["name"].endswith(version_suffix)]
|
||||
|
||||
def _github_repos_create(self, name):
|
||||
|
|
|
@ -269,15 +269,16 @@ if __name__ == "__main__":
|
|||
wescamp The directory where all checkouts should be stored.
|
||||
wesnoth_version The wesnoth version we should checkout add-ons for.
|
||||
userpass Authentication data. Shouldn't be needed.
|
||||
readonly Makes a read-only checkout that doesn't require authentication.
|
||||
"""
|
||||
def checkout(wescamp, wesnoth_version, userpass=None):
|
||||
def checkout(wescamp, wesnoth_version, userpass=None, readonly=False):
|
||||
|
||||
logging.debug("checking out add-ons from wesnoth version = '%s' to directory '%s'", wesnoth_version, wescamp)
|
||||
|
||||
github = libgithub.GitHub(wescamp, git_version, userpass=git_userpass)
|
||||
|
||||
for addon in github.list_addons():
|
||||
addon_obj = github.addon(addon)
|
||||
addon_obj = github.addon(addon, readonly=readonly)
|
||||
addon_obj.update()
|
||||
|
||||
|
||||
|
@ -343,6 +344,10 @@ if __name__ == "__main__":
|
|||
help = "Create a new branch checkout directory. "
|
||||
+ "Can also be used to update existing checkout directories.")
|
||||
|
||||
optionparser.add_option("-C", "--checkout-readonly", action = "store_true",
|
||||
help = "Create a read-only branch checkout directory. "
|
||||
+ "Can also be used to update existing checkout directories.")
|
||||
|
||||
options, args = optionparser.parse_args()
|
||||
|
||||
if(options.verbose):
|
||||
|
@ -574,14 +579,14 @@ if __name__ == "__main__":
|
|||
print "Unexpected error occured: " + str(e)
|
||||
sys.exit(e[0])
|
||||
|
||||
elif(options.checkout != None):
|
||||
elif(options.checkout != None or options.checkout_readonly != None):
|
||||
|
||||
if(wescamp == None):
|
||||
logging.error("No wescamp checkout specified.")
|
||||
sys.exit(2)
|
||||
|
||||
try:
|
||||
checkout(wescamp, git_version, userpass=git_userpass)
|
||||
checkout(wescamp, git_version, userpass=git_userpass, readonly=(options.checkout_readonly != None))
|
||||
except libgithub.Error, e:
|
||||
print "[ERROR github] " + str(e)
|
||||
sys.exit(1)
|
||||
|
|
Loading…
Add table
Reference in a new issue