<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import sys <EOL> from . base import BaseProject <EOL> from . . compat import u , open <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> class Mercurial ( BaseProject ) : <EOL> def process ( self ) : <EOL> self . configDir = self . _find_hg_config_dir ( self . path ) <EOL> return self . configDir is not None <EOL> def name ( self ) : <EOL> if self . configDir : <EOL> return u ( os . path . basename ( os . path . dirname ( self . configDir ) ) ) <EOL> return None <EOL> def branch ( self ) : <EOL> if self . configDir : <EOL> branch_file = os . path . join ( self . configDir , '<STR_LIT>' ) <EOL> try : <EOL> with open ( branch_file , '<STR_LIT:r>' , encoding = '<STR_LIT:utf-8>' ) as fh : <EOL> return u ( fh . readline ( ) . strip ( ) . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] ) <EOL> except UnicodeDecodeError : <EOL> try : <EOL> with open ( branch_file , '<STR_LIT:r>' , encoding = sys . getfilesystemencoding ( ) ) as fh : <EOL> return u ( fh . readline ( ) . strip ( ) . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] ) <EOL> except : <EOL> log . traceback ( ) <EOL> except IOError : <EOL> log . traceback ( ) <EOL> return u ( '<STR_LIT:default>' ) <EOL> def _find_hg_config_dir ( self , path ) : <EOL> path = os . path . realpath ( path ) <EOL> if os . path . isfile ( path ) : <EOL> path = os . path . split ( path ) [ <NUM_LIT:0> ] <EOL> if os . path . isdir ( os . path . join ( path , '<STR_LIT>' ) ) : <EOL> return os . path . join ( path , '<STR_LIT>' ) <EOL> split_path = os . path . split ( path ) <EOL> if split_path [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> return None <EOL> return self . _find_hg_config_dir ( split_path [ <NUM_LIT:0> ] ) </s>
