# Path: tracer/resources/collections.py
# class ProcessesCollection(Collection):
# 
# 	def owned_by(self, user):
# 		if not user:
# 			return self
# 		return self.filtered(lambda process: process.username() == user)
# 
# 	def newer_than(self, timestamp):
# 		return self.filtered(lambda process: process.create_time() >= timestamp)
# 
# 	def unique(self):
# 		unique = set()
# 		for process in self:
# 			try: unique.add(process)
# 			except NoSuchProcess: pass
# 		return ProcessesCollection(unique)
# 
# 	def filtered(self, function):
# 		processes = ProcessesCollection()
# 		for process in self:
# 			try:
# 				if function(process):
# 					processes.append(process)
# 			except NoSuchProcess: pass
# 		return processes


from .collections import ProcessesCollection
from .FilenameCleaner import FilenameCleaner
from subprocess import PIPE, Popen
from threading import Timer
from six import with_metaclass
import psutil
import datetime
import time
import os
import re
		# Process arguments
		for arg in self.cmdline()[1:]:
			if not os.path.isabs(arg):
				continue

			if Process.safe_isfile(arg):
				files.append(arg)

		return sorted(files)

	def parent(self):
		"""The parent process casted from ``psutil.Process`` to tracer ``Process``"""
		if self.ppid():
			return Process(self.ppid())
		return None

	def username(self):
		"""The user who owns the process. If user was deleted in the meantime,
		``None`` is returned instead."""

		# User who run the process can be deleted
		try:
			return super(Process, self).username()
		except KeyError:
			return None

	def children(self, recursive=False):
		"""The collection of process's children. Each of them casted from ``psutil.Process``
		to tracer ``Process``."""
		children = super(Process, self).children(recursive)

# Path: tracer/resources/collections.py
# class ProcessesCollection(Collection):
# 
# 	def owned_by(self, user):
# 		if not user:
# 			return self
# 		return self.filtered(lambda process: process.username() == user)
# 
# 	def newer_than(self, timestamp):
# 		return self.filtered(lambda process: process.create_time() >= timestamp)
# 
# 	def unique(self):
# 		unique = set()
# 		for process in self:
# 			try: unique.add(process)
# 			except NoSuchProcess: pass
# 		return ProcessesCollection(unique)
# 
# 	def filtered(self, function):
# 		processes = ProcessesCollection()
# 		for process in self:
# 			try:
# 				if function(process):
# 					processes.append(process)
# 			except NoSuchProcess: pass
# 		return processes


# Path: tracer/resources/processes.py
from .collections import ProcessesCollection
from .FilenameCleaner import FilenameCleaner
from subprocess import PIPE, Popen
from threading import Timer
from six import with_metaclass
import psutil
import datetime
import time
import os
import re

		# Process arguments
		for arg in self.cmdline()[1:]:
			if not os.path.isabs(arg):
				continue

			if Process.safe_isfile(arg):
				files.append(arg)

		return sorted(files)

	def parent(self):
		"""The parent process casted from ``psutil.Process`` to tracer ``Process``"""
		if self.ppid():
			return Process(self.ppid())
		return None

	def username(self):
		"""The user who owns the process. If user was deleted in the meantime,
		``None`` is returned instead."""

		# User who run the process can be deleted
		try:
			return super(Process, self).username()
		except KeyError:
			return None

	def children(self, recursive=False):
		"""The collection of process's children. Each of them casted from ``psutil.Process``
		to tracer ``Process``."""
		children = super(Process, self).children(recursive)

		return ProcessesCollection([Process(child.pid) for child in children])