<s> import os , pickle , sys , locale <EOL> from stat import * <EOL> def recurse ( root , tree , count = <NUM_LIT:0> ) : <EOL> A_NAME , A_TYPE , A_UID , A_GID , A_SIZE , A_MODE , A_CTIME , A_CONTENTS , A_TARGET , A_REALFILE = range ( <NUM_LIT:0> , <NUM_LIT:10> ) <EOL> T_LINK , T_DIR , T_FILE , T_BLK , T_CHR , T_SOCK , T_FIFO = range ( <NUM_LIT:0> , <NUM_LIT:7> ) <EOL> for name in os . listdir ( root ) : <EOL> path = os . path . join ( root , name ) <EOL> if path in ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) : <EOL> continue <EOL> try : <EOL> if os . path . islink ( path ) : <EOL> s = os . lstat ( path ) <EOL> else : <EOL> s = os . stat ( path ) <EOL> except OSError : <EOL> continue <EOL> entry = [ name , T_FILE , s . st_uid , s . st_gid , s . st_size , s . st_mode , int ( s . st_ctime ) , [ ] , None , None ] <EOL> if S_ISLNK ( s [ ST_MODE ] ) : <EOL> entry [ A_TYPE ] = T_LINK <EOL> entry [ A_TARGET ] = os . path . realpath ( path ) <EOL> elif S_ISDIR ( s [ ST_MODE ] ) : <EOL> entry [ A_TYPE ] = T_DIR <EOL> if not path . startswith ( '<STR_LIT>' ) : <EOL> recurse ( path , entry [ A_CONTENTS ] ) <EOL> elif S_ISREG ( s [ ST_MODE ] ) : <EOL> entry [ A_TYPE ] = T_FILE <EOL> elif S_ISBLK ( s [ ST_MODE ] ) : <EOL> entry [ A_TYPE ] = T_BLK <EOL> elif S_ISCHR ( s [ ST_MODE ] ) : <EOL> entry [ A_TYPE ] = T_CHR <EOL> elif S_ISSOCK ( s [ ST_MODE ] ) : <EOL> entry [ A_TYPE ] = T_SOCK <EOL> elif S_ISFIFO ( s [ ST_MODE ] ) : <EOL> entry [ A_TYPE ] = T_FIFO <EOL> else : <EOL> sys . stderr . write ( '<STR_LIT>' % path ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> tree . append ( entry ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> A_NAME , A_TYPE , A_UID , A_GID , A_SIZE , A_MODE , A_CTIME , A_CONTENTS , A_TARGET , A_REALFILE = range ( <NUM_LIT:0> , <NUM_LIT:10> ) <EOL> T_LINK , T_DIR , T_FILE , T_BLK , T_CHR , T_SOCK , T_FIFO = range ( <NUM_LIT:0> , <NUM_LIT:7> ) <EOL> tree = [ '<STR_LIT:/>' , T_DIR , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , [ ] , '<STR_LIT>' ] <EOL> recurse ( '<STR_LIT:/>' , tree [ A_CONTENTS ] , tree [ A_CONTENTS ] ) <EOL> sys . stderr . write ( '<STR_LIT>' ) <EOL> print pickle . dumps ( tree ) </s>
