#!/usr/bin/env python
# CCS Computer Science
#   Layout
#
# Douglas Thrift
#
# $Id$

import admin
import common
import os
import sys

if __name__ == '__main__':
	path = os.environ['PATH'].split(os.pathsep)
	shells = []
	verbose = bool(sys.argv[1:])

	for shell in map(lambda shell: shell[0], common.SHELLS[:-1]):
		found = False

		for directory in path:
			_shell = os.path.join(directory, shell)

			if os.path.exists(_shell) and os.access(_shell, os.R_OK | os.X_OK):
				shells.append(_shell)

				if verbose:
					print shell + ': ' + _shell

				found = True

				break

		if not found:
			admin.error('Shell not found: %s.' % shell)

	for system in common.SYSTEMS:
		if shells == map(lambda shell: shell[1][system], common.SHELLS[:-1]):
			print system

			sys.exit(0)
	
	admin.error('Unknown shell layout.')
