# Path: tracer/resources/package.py
# class Package:
# 	"""Represents linux package"""
# 
# 	name = None  #: Name of the package
# 	modified = None  #: UNIX timestamp of the modification
# 	description = None
# 	category = None
# 	epoch = None
# 	version = None
# 	release = None
# 
# 	def __init__(self, name, modified=None):
# 		self.name = name
# 		self.modified = modified
# 
# 	def __eq__(self, package):
# 		"""Packages are equal when they have same name"""
# 		return (isinstance(package, self.__class__)
# 			and self.name == package.name)
# 
# 	def __ne__(self, package):
# 		return not self.__eq__(package)
# 
# 	def __repr__(self):
# 		return "<Package:" + self.name + ">"
# 
# 	def __str__(self):
# 		return self.name
# 
# 	def __hash__(self):
# 		return hash(self.name)
# 
# 	def load_info(self, package_manager):
# 		package_manager.load_package_info(self)
# 
# Path: tracer/resources/exceptions.py
# class TracerError(Exception, Printable):
# 	"""
# 	Unspecified tracer error
# 	"""
# 	def __init__(self, message):
# 		self.message = message
# 
# class UnsupportedDistribution(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _(
# 			"You are running unsupported linux distribution\n"
# 			"\n"
# 			"Please visit https://github.com/FrostyX/tracer/issues\n"
# 			"and create new issue called 'Unknown or unsupported linux distribution: {0} (v{1})' if there isn't such.\n"
# 			"\n"
# 			"Don't you have an GitHub account? Please report this issue on frostyx@email.cz")
# 
# 	def __init__(self, distro):
# 		OSError.__init__(self, self.message.format(distro, __version__))
# 
# class PathNotFound(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _(
# 			"Problem occurred - neither one of {0} paths exists\n"
# 			"Please contact maintainer of tracer package in your distribution.")
# 
# 	def __init__(self, name):
# 		OSError.__init__(self, self.message.format(name))
# 
# class LockedDatabase(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _("Package database is locked by another process")
# 
# 	def __init__(self):
# 		OSError.__init__(self, self.message)
# 
# class DatabasePermissions(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _("You can't open package database due to insufficient permissions")
# 
# 	def __init__(self):
# 		OSError.__init__(self, self.message)


import sys
import time
from tracer.resources.router import Router
from tracer.resources.args_parser import parser
from tracer.resources.package import Package
from tracer.resources.exceptions import (
	TracerError,
	UnsupportedDistribution,
	PathNotFound,
	LockedDatabase,
	DatabasePermissions,
)
from tracer.resources.lang import _
# 02110-1301, USA.
#

from __future__ import print_function



def run():
	args = parser.parse_args()

	# If there is something on stdin (that means piped into tracer)
	stdin_packages = []
	if not sys.stdin.isatty():
		stdin_packages = sys.stdin.readline().split()

	# All input packages enchanced by actual time (as modified time)
	packages = []
	for package in args.packages + args.pkgs + stdin_packages:
		packages.append(Package(package, time.time() if args.now else None))

	try:
		router = Router(args, packages)
		return router.dispatch()

	except (UnsupportedDistribution, PathNotFound, LockedDatabase) as ex:
		ex.print()
		exit(1)
	except DatabasePermissions as ex:
		ex.print()
		print(_("You will probably need to run tracer as root"))

# Path: tracer/resources/package.py
# class Package:
# 	"""Represents linux package"""
# 
# 	name = None  #: Name of the package
# 	modified = None  #: UNIX timestamp of the modification
# 	description = None
# 	category = None
# 	epoch = None
# 	version = None
# 	release = None
# 
# 	def __init__(self, name, modified=None):
# 		self.name = name
# 		self.modified = modified
# 
# 	def __eq__(self, package):
# 		"""Packages are equal when they have same name"""
# 		return (isinstance(package, self.__class__)
# 			and self.name == package.name)
# 
# 	def __ne__(self, package):
# 		return not self.__eq__(package)
# 
# 	def __repr__(self):
# 		return "<Package:" + self.name + ">"
# 
# 	def __str__(self):
# 		return self.name
# 
# 	def __hash__(self):
# 		return hash(self.name)
# 
# 	def load_info(self, package_manager):
# 		package_manager.load_package_info(self)
# 
# Path: tracer/resources/exceptions.py
# class TracerError(Exception, Printable):
# 	"""
# 	Unspecified tracer error
# 	"""
# 	def __init__(self, message):
# 		self.message = message
# 
# class UnsupportedDistribution(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _(
# 			"You are running unsupported linux distribution\n"
# 			"\n"
# 			"Please visit https://github.com/FrostyX/tracer/issues\n"
# 			"and create new issue called 'Unknown or unsupported linux distribution: {0} (v{1})' if there isn't such.\n"
# 			"\n"
# 			"Don't you have an GitHub account? Please report this issue on frostyx@email.cz")
# 
# 	def __init__(self, distro):
# 		OSError.__init__(self, self.message.format(distro, __version__))
# 
# class PathNotFound(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _(
# 			"Problem occurred - neither one of {0} paths exists\n"
# 			"Please contact maintainer of tracer package in your distribution.")
# 
# 	def __init__(self, name):
# 		OSError.__init__(self, self.message.format(name))
# 
# class LockedDatabase(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _("Package database is locked by another process")
# 
# 	def __init__(self):
# 		OSError.__init__(self, self.message)
# 
# class DatabasePermissions(OSError, Printable):
# 
# 	@property
# 	def message(self):
# 		return _("You can't open package database due to insufficient permissions")
# 
# 	def __init__(self):
# 		OSError.__init__(self, self.message)


# Path: tracer/main.py
import sys
import time
from tracer.resources.router import Router
from tracer.resources.args_parser import parser
from tracer.resources.package import Package
from tracer.resources.exceptions import (
	TracerError,
	UnsupportedDistribution,
	PathNotFound,
	LockedDatabase,
	DatabasePermissions,
)
from tracer.resources.lang import _

# 02110-1301, USA.
#

from __future__ import print_function



def run():
	args = parser.parse_args()

	# If there is something on stdin (that means piped into tracer)
	stdin_packages = []
	if not sys.stdin.isatty():
		stdin_packages = sys.stdin.readline().split()

	# All input packages enchanced by actual time (as modified time)
	packages = []
	for package in args.packages + args.pkgs + stdin_packages:
		packages.append(Package(package, time.time() if args.now else None))

	try:
		router = Router(args, packages)
		return router.dispatch()

	except (UnsupportedDistribution, PathNotFound, LockedDatabase) as ex:
		ex.print()
		exit(1)
	except DatabasePermissions as ex:
		ex.print()
		print(_("You will probably need to run tracer as root"))

		exit(1)