<s> import re <EOL> import os <EOL> def sanitize ( path ) : <EOL> path = posix ( path ) <EOL> path = re . sub ( "<STR_LIT>" , "<STR_LIT>" , path ) <EOL> path = re . sub ( "<STR_LIT>" , "<STR_LIT:/>" , path ) <EOL> return path <EOL> def posix ( path ) : <EOL> if path is not None : <EOL> path = path . replace ( "<STR_LIT:\\>" , "<STR_LIT:/>" ) <EOL> return path <EOL> def is_relative ( string ) : <EOL> return bool ( re . match ( "<STR_LIT>" , string ) ) <EOL> def is_absolute ( string ) : <EOL> return bool ( re . match ( "<STR_LIT>" , string ) ) <EOL> def sanitize_base_directory ( path ) : <EOL> path = sanitize ( path ) <EOL> path = os . path . dirname ( path ) <EOL> path = re . sub ( "<STR_LIT>" , "<STR_LIT>" , path ) <EOL> path = re . sub ( "<STR_LIT>" , "<STR_LIT>" , path ) <EOL> return path <EOL> def get_absolute_path ( base_path , relative_path ) : <EOL> path = os . path . join ( base_path , relative_path ) <EOL> path = os . path . abspath ( path ) <EOL> return path <EOL> def get_relative_folder ( file_name , base_directory ) : <EOL> folder = os . path . dirname ( file_name ) <EOL> folder = os . path . relpath ( folder , base_directory ) <EOL> folder = "<STR_LIT>" if folder == "<STR_LIT:.>" else folder <EOL> return sanitize ( folder ) <EOL> def trace ( from_folder , to_folder ) : <EOL> if not from_folder : <EOL> return sanitize ( "<STR_LIT>" + to_folder ) <EOL> bases = from_folder . split ( "<STR_LIT:/>" ) <EOL> targets = to_folder . split ( "<STR_LIT:/>" ) <EOL> result = "<STR_LIT>" <EOL> index = <NUM_LIT:0> <EOL> size = min ( len ( bases ) , len ( targets ) ) <EOL> while ( index < size and bases [ index ] == targets [ index ] ) : <EOL> index += <NUM_LIT:1> <EOL> del bases [ <NUM_LIT:0> : index ] <EOL> del targets [ <NUM_LIT:0> : index ] <EOL> if ( len ( bases ) == <NUM_LIT:0> ) : <EOL> result = '<STR_LIT>' <EOL> else : <EOL> result = "<STR_LIT>" * len ( bases ) <EOL> result += "<STR_LIT:/>" . join ( targets ) <EOL> result = re . sub ( "<STR_LIT>" , "<STR_LIT:/>" , result ) ; <EOL> return result </s>
