#!/usr/bin/env python3
import argparse
import os
import addoninfo
from gmpublish import GmPublish

def main():
	# Define command line parameters
	parser = argparse.ArgumentParser(description = "Garry's mod workshop cli wrapper.")
	args = parser.parse_args()
	curdir = os.getcwd()

	# Try to get the addon information
	try:
		addon = addoninfo.get_addon_info(addoninfo.find_addon(curdir))
		publisher = GmPublish(addon)
	except addoninfo.AddonNotFoundError as err:
		print(err)
		return

	# The addon can be updated if it has a workshop id
	if addon.has_workshop_id():
		publisher.update()
		return

	uploaded = request_uploaded()

	if uploaded == None:
		return
	elif uploaded:
		request_workshopid(addon)
		publisher.update()
		return

	publisher.create()

def request_uploaded():
	"""Ask whether the addon exists on the workshop"""
	try:
		uploaded = input("No workshop ID found in the addon. Has this addon been uploaded to the workshop yet? (y/n)\n")
		return uploaded == 'y' or uploaded == 'yes' or uploaded == '\n'
	except EOFError:
		print("Setup cancelled")
		return None

def request_workshopid(addon):
	"""The addon is uploaded, but the workshop ID hasn't been registered yet
		This function requests the workshop ID
	"""
	try:
		inp = input("Please enter the workshop ID of the addon: ")
		addon.set_workshopid(int(inp))
	except NameError:
		print("Not a valid workshop ID.")
		request_workshopid()


if __name__ == '__main__':
	main()
#!/usr/bin/env python3
import argparse
import os
import addoninfo
from gmad import *
from gmpublish import GmPublish

def main():
	curdir = os.getcwd()

	# Define command line parameters
	parser = argparse.ArgumentParser(description = "Garry's mod workshop cli wrapper.")
	parser.add_argument('-l', '--logo', nargs=1, help='Path of the logo image.', metavar='path')
	parser.add_argument('-d', '--dir', nargs=1, help='Directory of the addon.', metavar='path')
	parser.add_argument('-v', '--verify', action='store_true', help='Verify the contents of the current folder.')

	args = parser.parse_args()
	curdir = args.dir and args.dir[0] or curdir

	# Try to get the addon information
	try:
		addon = addoninfo.get_addon_info(addoninfo.find_addon(curdir))
		publisher = GmPublish(addon)
	except addoninfo.AddonNotFoundError as err:
		print(err)
		return

	if args.verify:
		verify_files(curdir, addon)
		return

	# The addon can be updated if it has a workshop id
	if addon.has_workshop_id():
		publisher.update()
		return

	uploaded = request_uploaded()

	if uploaded == None:
		return
	elif uploaded:
		request_workshopid(addon)
		publisher.update()
		return

	publisher.create()

def request_uploaded():
	"""Ask whether the addon exists on the workshop"""
	try:
		uploaded = input("No workshop ID found in the addon. Has this addon been uploaded to the workshop yet? (y/n)\n")
		return uploaded == 'y' or uploaded == 'yes' or uploaded == '\n'
	except EOFError:
		print("Setup cancelled")
		return None

def request_workshopid(addon):
	"""The addon is uploaded, but the workshop ID hasn't been registered yet
		This function requests the workshop ID
	"""
	try:
		inp = input("Please enter the workshop ID of the addon: ")
		addon.set_workshopid(int(inp))
	except NameError:
		print("Not a valid workshop ID.")
		request_workshopid()

def verify_files(dir, addon):
	"""Verify if the files in the path can be compressed in a gma"""
	verified, disallowed = GMad(dir, addon).verify_files()

	if verified:
		print("Current addon can be packed in a gma.\nNo illegal files were found.")
	else:
		print("Illegal files were found:")
		for f in disallowed: print('\t' + f)
		print("Please remove these files or add them to the ignore list of your addon.")

if __name__ == '__main__':
	main()
Set directory and verify files