#!/usr/bin/python2.7
# -*- coding: utf-8 -*-

"""
get apps info
"""

import sys
import optparse
import univention.appcenter.app_cache


class AppsInfo(object):

	def __init__(self):
		usage = '''%prog [options] '''
		description = sys.modules[__name__].__doc__
		parser = optparse.OptionParser(usage=usage, description=description)
		parser.add_option("-a", "--app", action="store", dest="app", help="app id")
		parser.add_option("-v", "--version", action="store_true", dest="version", default=False, help="get version")
		(self.options, self.args) = parser.parse_args()
		assert self.options.app is not None
		self.app_cache = univention.appcenter.app_cache.Apps()

	def get_latest_version(self):
		print(self.app_cache.find(self.options.app, latest=True))

	def main(self):
		if self.options.version:
			self.get_latest_version()
		else:
			raise Exception('unknown command')


if __name__ == '__main__':
	info = AppsInfo()
	info.main()
