import time


def formatentry_ls(l):

	"""Returns a string in a format similar to that produced by
	'ls -la'. This is particularly handy to get Emacs' ange-ftp
	working well with FtpServers.

	Expects a list or tuple containing the following members:
		- [0] - permissions, in 'drwxrwxrwx' format
		- [1] - number of links (doesn't really matter much)
		- [2] - file's owner's username (eg. 'root')
		- [3] - file's group's groupname (eg. 'wheel')
		- [4] - file's length in bytes
		- [5] - file's mtime, in seconds since epoch
		- [6] - file's name
	"""
	
	mtime = l[5]
	if time.time() - mtime > (86400 * 28):
		printtime = time.strftime('%b %d %Y', time.localtime(mtime))
	else:
		printtime = time.strftime('%b %d %H:%M', time.localtime(mtime))
	l[5] = printtime
	return '%s %3d %-8s %-8s %8d %-12s %s' % tuple(l)