<s> from datetime import datetime <EOL> import errno <EOL> from fnmatch import fnmatch <EOL> import io <EOL> import os <EOL> import shutil <EOL> import unicodedata <EOL> def to_unicode ( txt , encoding = '<STR_LIT:utf8>' ) : <EOL> if not isinstance ( txt , basestring ) : <EOL> txt = str ( txt ) <EOL> if isinstance ( txt , unicode ) : <EOL> return txt <EOL> return unicode ( txt , encoding ) <EOL> def unormalize ( text , form = '<STR_LIT>' ) : <EOL> return unicodedata . normalize ( form , text ) <EOL> def fullmatch ( path , pattern ) : <EOL> path = unormalize ( path ) <EOL> name = os . path . basename ( path ) <EOL> return fnmatch ( name , pattern ) or fnmatch ( path , pattern ) <EOL> def make_dirs ( * lpath ) : <EOL> path = os . path . join ( * lpath ) <EOL> try : <EOL> os . makedirs ( path ) <EOL> except OSError as e : <EOL> if e . errno != errno . EEXIST : <EOL> raise <EOL> return path <EOL> def create_file ( path , content , encoding = '<STR_LIT:utf8>' ) : <EOL> if not isinstance ( content , unicode ) : <EOL> content = unicode ( content , encoding ) <EOL> make_dirs ( os . path . dirname ( path ) ) <EOL> with io . open ( path , '<STR_LIT>' , encoding = encoding ) as f : <EOL> f . write ( content ) <EOL> def copy_if_updated ( path_in , path_out ) : <EOL> if os . path . exists ( path_out ) : <EOL> newt = os . path . getmtime ( path_in ) <EOL> currt = os . path . getmtime ( path_out ) <EOL> if currt >= newt : <EOL> return <EOL> shutil . copy2 ( path_in , path_out ) <EOL> def get_updated_datetime ( path ) : <EOL> ut = os . path . getmtime ( path ) <EOL> return datetime . fromtimestamp ( ut ) <EOL> def sort_paths_dirs_last ( paths ) : <EOL> def dirs_last ( a , b ) : <EOL> return cmp ( a [ <NUM_LIT:0> ] . count ( '<STR_LIT:/>' ) , b [ <NUM_LIT:0> ] . count ( '<STR_LIT:/>' ) ) or cmp ( a [ <NUM_LIT:0> ] , b [ <NUM_LIT:0> ] ) <EOL> return sorted ( paths , cmp = dirs_last ) </s>
