<commit_before>'''
Created on 16 juil. 2013

@author: tehboii
'''

import os, yaml
from werkzeug import secure_filename

conf = None
strings = dict()
reservedNames = []  # List of names which potentially conflicts with service routes.

def readPath( relativePath, listFiles=True ):
	if relativePath == '/': relativePath = None
	path = os.path.abspath( os.path.join( conf['root'], relativePath if relativePath else '' ) )
	if not path.startswith( conf['root'] ):
		raise Exception( "Illegal access" )

	if os.path.isdir( path ):

		files = list()
		crumbs = list()
		if listFiles:	
			if relativePath:
				parent, child = os.path.split( relativePath )
				crumbs.append( child )
				while( parent ):
					parent, child = os.path.split( parent )
					crumbs.append( child )
				crumbs.reverse()
	
			for file in os.listdir( path ):
				if not exposeFile( file  ):
													continue;
				entry = {'name': file, 'type':'question-sign'}
				ext = os.path.splitext( file )[1][1:]
				if os.path.isdir( os.path.join( path, file ) ): 
					entry['type'] = 'folder-close'
				else:
					for type_, exts in conf['typeIcons'].items():
						if ext in exts:
							entry['type'] = type_
							break;
				entry['size'] = os.stat(os.path.join(path, file)).st_size
				entry['date'] = os.path.getctime(os.path.join(path, file))
				files.append( entry )
		return {'type':'dir', 'crumbs':crumbs, 'files':files, 'canUpload': True if relativePath else False}
	elif os.path.isfile( path ):
		return {'type':'file'}

	return None

def acceptFile( path, name ):
	name = sanitizeName( name )
	return True

def acceptDir( path, name ):
	name = sanitizeName( name )
	return True

def sanitizeName( name ):
	""" Returns a valid file name out of anything """
	if not name:
		raise Exception( "Empty name" )

	while name in reservedNames: name = {'_{0}'.format( name )}

	name = secure_filename( name )
	
	return name<commit_msg>Fixed a bug when POSTing what=mkdir with no name<commit_after>'''
Created on 16 juil. 2013

@author: tehboii
'''

import os, yaml
from werkzeug import secure_filename

conf = None
strings = dict()
reservedNames = []  # List of names which potentially conflicts with service routes.

def readPath( relativePath, listFiles=True ):
	if relativePath == '/': relativePath = None
	path = os.path.abspath( os.path.join( conf['root'], relativePath if relativePath else '' ) )
	if not path.startswith( conf['root'] ):
		raise Exception( "Illegal access" )

	if os.path.isdir( path ):

		files = list()
		crumbs = list()
		if listFiles:	
			if relativePath:
				parent, child = os.path.split( relativePath )
				crumbs.append( child )
				while( parent ):
					parent, child = os.path.split( parent )
					crumbs.append( child )
				crumbs.reverse()
	
			for file in os.listdir( path ):
				if not exposeFile( file  ):
													continue;
				entry = {'name': file, 'type':'question-sign'}
				ext = os.path.splitext( file )[1][1:]
				if os.path.isdir( os.path.join( path, file ) ): 
					entry['type'] = 'folder-close'
				else:
					for type_, exts in conf['typeIcons'].items():
						if ext in exts:
							entry['type'] = type_
							break;
				entry['size'] = os.stat(os.path.join(path, file)).st_size
				entry['date'] = os.path.getctime(os.path.join(path, file))
				files.append( entry )
		return {'type':'dir', 'crumbs':crumbs, 'files':files, 'canUpload': True if relativePath else False}
	elif os.path.isfile( path ):
		return {'type':'file'}

	return None

def acceptFile( path, name ):
	name = sanitizeName( name )
	return True

def acceptDir( path, name ):
	name = sanitizeName( name )
	return True

def sanitizeName( name ):
	""" Returns a valid file name out of anything """

	while name in reservedNames: name = {'_{0}'.format( name )}

	name = secure_filename( name )
	
	return name if name else None
{'fraction_non_alphanumeric': 0.13982717989002358, 'fraction_numerical': 0.004713275726630008, 'mean_word_length': 3.3707093821510297, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6045761', 'n_tokens_mistral': 1463, 'n_tokens_neox': 1253, 'n_words': 384}