<s> from __future__ import print_function <EOL> __version__ = '<STR_LIT>' <EOL> import sys <EOL> if ( ( ( sys . version_info . major == <NUM_LIT:2> ) and ( sys . version_info . minor < <NUM_LIT:7> ) ) <EOL> or ( ( sys . version_info . major == <NUM_LIT:3> ) and ( sys . version_info . minor < <NUM_LIT:2> ) ) ) : <EOL> sys . stderr . write ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> import os <EOL> import re <EOL> import argparse <EOL> import unicodedata <EOL> import time <EOL> import random <EOL> import json <EOL> import datetime <EOL> import difflib <EOL> import tempfile <EOL> import codecs <EOL> from operator import xor <EOL> from io import BytesIO <EOL> from collections import OrderedDict <EOL> try : <EOL> import xml . etree . cElementTree as ETree <EOL> except ImportError : <EOL> import xml . etree . ElementTree as ETree <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> PBXPROJNAME = '<STR_LIT>' <EOL> OK = <NUM_LIT:0> <EOL> ERROR = <NUM_LIT:1> <EOL> PARSING_FAILED = <NUM_LIT:1> <EOL> LINT_DIFFERENCES = <NUM_LIT:1> <EOL> LINT_FAILED = <NUM_LIT:2> <EOL> CONVERT_OUTPUT_FAILED = <NUM_LIT:2> <EOL> LATEST_OBJECT_VERSION = <NUM_LIT> <EOL> STDIN = None <EOL> STDOUT = '<STR_LIT:->' <EOL> PY2 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> <EOL> PY3 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:3> <EOL> args_info = set ( [ ] ) <EOL> args_debug = set ( [ ] ) <EOL> args_verbose = set ( [ ] ) <EOL> if PY2 : <EOL> text_type = unicode <EOL> binary_type = str <EOL> else : <EOL> text_type = str <EOL> binary_type = bytes <EOL> unichr = chr <EOL> def unistr ( text ) : <EOL> if not isinstance ( text , text_type ) : <EOL> text = text . decode ( '<STR_LIT:utf-8>' ) <EOL> return text <EOL> def bytestr ( text ) : <EOL> if not isinstance ( text , binary_type ) : <EOL> text = text . encode ( '<STR_LIT:utf-8>' ) <EOL> return text <EOL> INFO_TIME = '<STR_LIT:time>' <EOL> INFO_BACKTRACKS = '<STR_LIT>' <EOL> INFO_ALL = [ INFO_TIME , INFO_BACKTRACKS ] <EOL> verbose_categories = { <EOL> <NUM_LIT:1> : [ INFO_TIME ] , <EOL> <NUM_LIT:2> : [ INFO_BACKTRACKS ] , <EOL> } <EOL> DEBUG_OPTIONS = '<STR_LIT>' <EOL> DEBUG_ALL = [ DEBUG_OPTIONS ] <EOL> re_unescape = re . compile ( r'<STR_LIT>' ) <EOL> unescape_dict = { <EOL> '<STR_LIT>' : '<STR_LIT:\\>' , <EOL> '<STR_LIT>' : '<STR_LIT:">' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:\t>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:\n>' , <EOL> } <EOL> re_escape = re . compile ( r'<STR_LIT>' ) <EOL> escape_dict = { v : k for k , v in unescape_dict . items ( ) } <EOL> r_quoteworthy = re . compile ( r'<STR_LIT>' ) <EOL> r_gid = re . compile ( r'<STR_LIT>' ) <EOL> r_ws = re . compile ( r'<STR_LIT>' ) <EOL> r_tokenize = re . compile ( r"""<STR_LIT>""" , re . MULTILINE | re . VERBOSE ) <EOL> rule_mapping = r_tokenize . groupindex <EOL> rulenumber_to_name = dict ( ( vnr , kname ) for ( kname , vnr ) in rule_mapping . items ( ) ) <EOL> rule_names = [ rulenumber_to_name . get ( groupnr , '<STR_LIT>' ) for groupnr in range ( r_tokenize . groups + <NUM_LIT:1> ) ] <EOL> RULE_COMMENT = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_LINECOMMENT = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_UNQUOTEDSTRING = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_EQUALS = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_SEMICOLON = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_QUOTEDSTRING = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_DICTIONARY = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_DICTIONARYEND = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_COMMA = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_ARRAY = rule_mapping [ '<STR_LIT>' ] <EOL> RULE_ARRAYEND = rule_mapping [ '<STR_LIT>' ] <EOL> def parse ( text , format = None , dictionarytype = dict , parsertype = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> text = unistr ( text ) <EOL> root , parseinfo = None , None <EOL> can_only_be_xml = text . startswith ( '<STR_LIT>' ) <EOL> if format == '<STR_LIT>' or ( format is None and can_only_be_xml ) : <EOL> return parse_xcodeproject_xml ( text , dictionarytype = dictionarytype ) <EOL> if format in [ None , '<STR_LIT>' ] : <EOL> root , parseinfo = parse_xcodeproject_json ( text , dictionarytype = dictionarytype ) <EOL> if root is not None or format == '<STR_LIT>' : <EOL> return root , parseinfo <EOL> prev_parseinfo = parseinfo <EOL> root , parseinfo = parse_xcodeproject_plist ( text , dictionarytype = dictionarytype , parsertype = parsertype ) <EOL> if prev_parseinfo is not None : <EOL> parseinfo [ '<STR_LIT>' ] = prev_parseinfo <EOL> return root , parseinfo <EOL> def parse_xcodeproject_plist ( text , dictionarytype = dict , parsertype = '<STR_LIT>' ) : <EOL> text = unistr ( text ) <EOL> if parsertype in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> root , parseinfo = parse_xcodeproject_plist_via_json ( text ) <EOL> if root is not None or parsertype == '<STR_LIT>' : <EOL> return root , parseinfo <EOL> if parsertype in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> root , parseinfo = parse_xcodeproject_plist_direct ( text , dictionarytype = dictionarytype ) <EOL> if root is not None and parsertype == '<STR_LIT>' : <EOL> parseinfo . setdefault ( '<STR_LIT>' , [ ] ) . append ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> return root , parseinfo <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % parsertype ) <EOL> def parse_xcodeproject_plist_via_json ( text , dictionarytype = dict ) : <EOL> """<STR_LIT>""" <EOL> t0 = time . time ( ) <EOL> text = unistr ( text ) <EOL> tokens = [ ] <EOL> emit = tokens . append <EOL> jsondumps = json . JSONEncoder ( ) . encode <EOL> formatdesc = '<STR_LIT>' <EOL> prjname = None <EOL> pos = skip_whitespace ( text ) <EOL> for m in r_tokenize . finditer ( text , pos ) : <EOL> if m . start ( ) != pos : <EOL> return None , error_report_dict ( text , m . start ( ) , m . end ( ) , formatdesc ) <EOL> pos = m . end ( ) <EOL> rulenr = m . lastindex <EOL> if rulenr == RULE_UNQUOTEDSTRING : <EOL> emit ( '<STR_LIT:">' ) <EOL> emit ( m . group ( rulenr ) ) <EOL> emit ( '<STR_LIT:">' ) <EOL> elif rulenr == RULE_SEMICOLON : <EOL> emit ( '<STR_LIT:U+002C>' ) <EOL> elif rulenr == RULE_EQUALS : <EOL> emit ( '<STR_LIT::>' ) <EOL> elif rulenr == RULE_COMMENT : <EOL> if prjname is None : <EOL> prjname = projectname_from_comment ( m . group ( rulenr ) ) <EOL> continue <EOL> elif rulenr == RULE_DICTIONARY : <EOL> emit ( '<STR_LIT:{>' ) <EOL> elif rulenr == RULE_DICTIONARYEND : <EOL> if tokens [ - <NUM_LIT:1> ] == '<STR_LIT:U+002C>' : <EOL> tokens . pop ( ) <EOL> elif tokens [ - <NUM_LIT:1> ] != '<STR_LIT:{>' : <EOL> return None , error_report_dict ( text , m . start ( ) , m . end ( ) , formatdesc ) <EOL> emit ( '<STR_LIT:}>' ) <EOL> elif rulenr == RULE_COMMA : <EOL> emit ( '<STR_LIT:U+002C>' ) <EOL> elif rulenr == RULE_QUOTEDSTRING : <EOL> emit ( jsondumps ( unescape_str ( m . group ( rulenr ) ) ) ) <EOL> elif rulenr == RULE_ARRAY : <EOL> emit ( '<STR_LIT:[>' ) <EOL> elif rulenr == RULE_ARRAYEND : <EOL> if tokens [ - <NUM_LIT:1> ] == '<STR_LIT:U+002C>' : <EOL> tokens . pop ( ) <EOL> emit ( '<STR_LIT:]>' ) <EOL> try : <EOL> jsontext = '<STR_LIT>' . join ( tokens ) <EOL> root = json . loads ( jsontext , object_pairs_hook = dictionarytype ) <EOL> except ValueError as e : <EOL> linenr , column , errortext = error_report_from ( formatdesc , jsontext , text_type ( e ) ) <EOL> return None , { '<STR_LIT>' : column , <EOL> '<STR_LIT>' : linenr , <EOL> '<STR_LIT>' : errortext } <EOL> parseinfo = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : time . time ( ) - t0 , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if prjname is not None : <EOL> parseinfo [ '<STR_LIT>' ] = prjname <EOL> return root , parseinfo <EOL> def skip_whitespace ( text , pos = <NUM_LIT:0> ) : <EOL> m = r_ws . match ( text , pos ) <EOL> if m is not None : <EOL> return m . end ( ) <EOL> return pos <EOL> def decode_utf8_or_sys ( s ) : <EOL> try : <EOL> return unistr ( s ) <EOL> except UnicodeDecodeError : <EOL> return s . decode ( sys . getfilesystemencoding ( ) ) <EOL> def projectname_from_comment ( text ) : <EOL> if text . startswith ( '<STR_LIT>' ) : <EOL> qstart = text . find ( '<STR_LIT:">' ) <EOL> qend = text . rfind ( '<STR_LIT:">' ) <EOL> if qstart >= <NUM_LIT:0> and qend >= <NUM_LIT:0> and qstart + <NUM_LIT:1> < qend : <EOL> return text [ qstart + <NUM_LIT:1> : qend ] <EOL> return None <EOL> def projectname_for_path ( filename ) : <EOL> name , ext = os . path . splitext ( os . path . basename ( os . path . dirname ( filename ) ) ) <EOL> if ext not in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> return None <EOL> return decode_utf8_or_sys ( name ) <EOL> def is_global_id ( node ) : <EOL> return r_gid . match ( node ) is not None <EOL> def escape_str ( text ) : <EOL> def replace ( m ) : <EOL> char = m . group ( <NUM_LIT:0> ) <EOL> return escape_dict . get ( char ) or ( '<STR_LIT>' % ord ( char ) ) <EOL> return re_escape . sub ( replace , text ) <EOL> def unescape_str ( s ) : <EOL> def replace ( m ) : <EOL> txt = m . group ( <NUM_LIT:0> ) <EOL> c = unescape_dict . get ( txt ) <EOL> if c is not None : <EOL> return c <EOL> if s . startswith ( '<STR_LIT>' ) : <EOL> return unichr ( int ( txt [ <NUM_LIT:2> : ] , <NUM_LIT:16> ) ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % repr ( s ) ) <EOL> return re_unescape . sub ( replace , s [ <NUM_LIT:1> : - <NUM_LIT:1> ] ) <EOL> def quoted_string ( s ) : <EOL> if not s : <EOL> return '<STR_LIT>' <EOL> if r_quoteworthy . search ( s ) is not None : <EOL> return '<STR_LIT:">' + escape_str ( s ) + '<STR_LIT:">' <EOL> return s <EOL> def parse_xcodeproject_json ( text , dictionarytype = dict ) : <EOL> try : <EOL> text = unistr ( text ) <EOL> root = json . loads ( text , object_pairs_hook = dictionarytype ) <EOL> parseinfo = { '<STR_LIT>' : '<STR_LIT>' } <EOL> return root , parseinfo <EOL> except ValueError as e : <EOL> linenr , column , errortext = error_report_from ( '<STR_LIT>' , text , text_type ( e ) ) <EOL> parseinfo = { '<STR_LIT>' : column , <EOL> '<STR_LIT>' : linenr , <EOL> '<STR_LIT>' : errortext } <EOL> return None , parseinfo <EOL> def parse_xcodeproject_plist_direct ( text , dictionarytype = dict ) : <EOL> t0 = time . time ( ) <EOL> text = unistr ( text ) <EOL> tokenrules = [ ] <EOL> tokentexts = [ ] <EOL> offsets = [ ] <EOL> num_comments = <NUM_LIT:0> <EOL> prjname = None <EOL> pos = skip_whitespace ( text ) <EOL> for m in r_tokenize . finditer ( text , pos ) : <EOL> if m . start ( ) != pos : <EOL> break <EOL> rule_number = m . lastindex <EOL> if rule_number == RULE_COMMENT : <EOL> if prjname is None : <EOL> prjname = projectname_from_comment ( m . group ( rule_number ) ) <EOL> num_comments += <NUM_LIT:1> <EOL> elif rule_number == RULE_LINECOMMENT : <EOL> pass <EOL> else : <EOL> tokenrules . append ( rule_number ) <EOL> tokentexts . append ( m . group ( rule_number ) ) <EOL> offsets . append ( pos ) <EOL> pos = m . end ( ) <EOL> lastpos = pos <EOL> parseinfo = { '<STR_LIT>' : num_comments } <EOL> success , root = parse_tokens ( tokenrules , tokentexts , <EOL> dictionarytype = dictionarytype ) <EOL> if not success : <EOL> tokenpos = errortokenpos ( root ) <EOL> if tokenpos < len ( tokenrules ) : <EOL> errstart = offsets [ tokenpos ] <EOL> errstop = errstart + len ( tokentexts [ tokenpos ] ) <EOL> else : <EOL> errstart = errstop = lastpos <EOL> parseinfo . update ( error_report_dict ( text , errstart , errstop , '<STR_LIT>' ) ) <EOL> return None , parseinfo <EOL> parseinfo = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : time . time ( ) - t0 , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if prjname is not None : <EOL> parseinfo [ '<STR_LIT>' ] = prjname <EOL> return root , parseinfo <EOL> def errortokenpos ( tokenoffset ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( tokenoffset , ParserError ) : <EOL> for prevexc in iter ( lambda : tokenoffset . prevexc , None ) : <EOL> tokenoffset = prevexc <EOL> tokenoffset = tokenoffset . pos <EOL> return tokenoffset <EOL> def error_report_dict ( text , errstart , errstop , formatdesc ) : <EOL> linenr , column , errortext = parse_error_report ( text , errstart , errstop , formatdesc ) <EOL> return { '<STR_LIT>' : column , <EOL> '<STR_LIT>' : linenr , <EOL> '<STR_LIT>' : errortext } <EOL> def linenr_column_line ( text , offset ) : <EOL> """<STR_LIT>""" <EOL> offset = min ( max ( <NUM_LIT:0> , offset ) , len ( text ) ) <EOL> textbegin = text [ : offset ] <EOL> if not textbegin : <EOL> return <NUM_LIT:1> , <NUM_LIT:1> , None <EOL> lines = textbegin . splitlines ( True ) <EOL> linenr , column = max ( <NUM_LIT:1> , len ( lines ) ) , len ( lines [ - <NUM_LIT:1> ] ) + <NUM_LIT:1> <EOL> line = lines [ - <NUM_LIT:1> ] <EOL> nlpos = text . find ( '<STR_LIT:\n>' , offset ) <EOL> if nlpos >= <NUM_LIT:0> : <EOL> line += text [ offset : nlpos + <NUM_LIT:1> ] <EOL> else : <EOL> line += text [ offset : ] <EOL> return linenr , column , line <EOL> def parse_error_report ( text , errstart , errstop , formatdesc ) : <EOL> errmsg = '<STR_LIT>' % formatdesc <EOL> linenr , column , line = linenr_column_line ( text , errstart ) <EOL> if line is None : <EOL> return <NUM_LIT:1> , <NUM_LIT:1> , errmsg <EOL> if errstop >= len ( text ) : <EOL> return linenr , column , errmsg + '<STR_LIT>' <EOL> blankline = re . sub ( r'<STR_LIT>' , '<STR_LIT:U+0020>' , line ) <EOL> blankline = blankline [ : column - <NUM_LIT:1> ] <EOL> countingline = blankline . replace ( '<STR_LIT:\t>' , '<STR_LIT:U+0020>' ) <EOL> column = len ( countingline ) + <NUM_LIT:1> <EOL> errtoken = text [ errstart : errstop ] <EOL> errtoken = errtoken . replace ( '<STR_LIT:\t>' , '<STR_LIT:U+0020>' ) <EOL> caretline = blankline + '<STR_LIT>' + '<STR_LIT>' * ( len ( errtoken ) - <NUM_LIT:1> ) <EOL> errortext = line . rstrip ( ) + '<STR_LIT:\n>' + caretline + '<STR_LIT:\n>' <EOL> errortext += errmsg <EOL> return linenr , column , errortext <EOL> def error_report_from ( format , text , errortext ) : <EOL> """<STR_LIT>""" <EOL> linepos = errortext . rfind ( '<STR_LIT>' ) <EOL> errmsg = '<STR_LIT>' % format <EOL> standard_error = <NUM_LIT:1> , <NUM_LIT:1> , errmsg <EOL> if linepos == - <NUM_LIT:1> : <EOL> return standard_error <EOL> errortext = errortext [ linepos : ] <EOL> numbers = [ int ( x ) for x in re . split ( r"<STR_LIT>" , errortext ) if x ] <EOL> if len ( numbers ) not in [ <NUM_LIT:2> , <NUM_LIT:3> ] : <EOL> return standard_error <EOL> linenr , column = numbers [ : <NUM_LIT:2> ] <EOL> errstart = <NUM_LIT:0> <EOL> for idx , line in enumerate ( text . splitlines ( True ) ) : <EOL> if idx + <NUM_LIT:1> == linenr : <EOL> errstart += column - <NUM_LIT:1> <EOL> break <EOL> errstart += len ( line ) <EOL> else : <EOL> return linenr , column , errmsg <EOL> return parse_error_report ( text , errstart , errstart , format ) <EOL> class ParserError ( Exception ) : <EOL> def __init__ ( self , text , pos , prevexc = None ) : <EOL> super ( ParserError , self ) . __init__ ( text ) <EOL> self . pos = pos <EOL> self . prevexc = prevexc <EOL> def parse_tokens ( tokenrules , tokentexts , dictionarytype = dict ) : <EOL> def inc ( pos ) : <EOL> return pos + <NUM_LIT:1> <EOL> def rule_at ( pos ) : <EOL> try : <EOL> return tokenrules [ pos ] <EOL> except IndexError : <EOL> raise ParserError ( '<STR_LIT>' , pos ) <EOL> def text_at ( pos ) : <EOL> try : <EOL> return tokentexts [ pos ] <EOL> except IndexError : <EOL> raise ParserError ( '<STR_LIT>' , pos ) <EOL> def skip_literal ( pos , rulenr ) : <EOL> if rule_at ( pos ) == rulenr : <EOL> return inc ( pos ) <EOL> return pos <EOL> def musthave_literal ( pos , s ) : <EOL> nextpos = skip_literal ( pos , s ) <EOL> if nextpos == pos : <EOL> raise ParserError ( "<STR_LIT>" % s , pos ) <EOL> return nextpos <EOL> def sequence ( pos , * args ) : <EOL> elements = [ ] <EOL> for element in args : <EOL> if callable ( element ) : <EOL> r = element ( pos ) <EOL> v , pos = r <EOL> elements . append ( v ) <EOL> else : <EOL> pos = musthave_literal ( pos , element ) <EOL> return elements , pos <EOL> def zero_or_more ( pos , func , nextelem ) : <EOL> elements = [ ] <EOL> while True : <EOL> try : <EOL> v , pos = func ( pos ) <EOL> elements . append ( v ) <EOL> except ParserError as e : <EOL> try : <EOL> musthave_literal ( pos , nextelem ) <EOL> except ParserError as e2 : <EOL> e2 . prevexc = e <EOL> raise e2 <EOL> return elements , pos <EOL> return elements , pos <EOL> def anystring ( pos ) : <EOL> rulenr = rule_at ( pos ) <EOL> if rulenr == RULE_UNQUOTEDSTRING : <EOL> return unquotedstring ( pos ) <EOL> elif rulenr == RULE_QUOTEDSTRING : <EOL> return quotedstring ( pos ) <EOL> raise ParserError ( '<STR_LIT>' , pos ) <EOL> def value ( pos ) : <EOL> rulenr = rule_at ( pos ) <EOL> if rulenr == RULE_UNQUOTEDSTRING : <EOL> return unquotedstring ( pos ) <EOL> elif rulenr == RULE_DICTIONARY : <EOL> return dictionary ( pos ) <EOL> elif rulenr == RULE_QUOTEDSTRING : <EOL> return quotedstring ( pos ) <EOL> elif rulenr == RULE_ARRAY : <EOL> return array ( pos ) <EOL> raise ParserError ( '<STR_LIT>' , pos ) <EOL> def arrayvalue ( pos ) : <EOL> rulenr = rule_at ( pos ) <EOL> if rulenr == RULE_UNQUOTEDSTRING : <EOL> return unquotedstring ( pos ) <EOL> elif rulenr == RULE_QUOTEDSTRING : <EOL> return quotedstring ( pos ) <EOL> elif rulenr == RULE_DICTIONARY : <EOL> return dictionary ( pos ) <EOL> raise ParserError ( '<STR_LIT>' , pos ) <EOL> def arrayelements ( pos ) : <EOL> try : <EOL> return zero_or_more ( pos , arrayelement , RULE_ARRAYEND ) <EOL> except RuntimeError as exc : <EOL> if str ( exc ) . startswith ( '<STR_LIT>' ) : <EOL> raise ParserError ( "<STR_LIT>" , pos ) <EOL> def arrayelement ( pos ) : <EOL> v , pos = arrayvalue ( pos ) <EOL> p2 = skip_literal ( pos , RULE_COMMA ) <EOL> if p2 > pos : <EOL> return v , p2 <EOL> musthave_literal ( pos , RULE_ARRAYEND ) <EOL> return v , pos <EOL> def array ( pos ) : <EOL> v , pos = sequence ( pos , RULE_ARRAY , arrayelements , RULE_ARRAYEND ) <EOL> return v [ <NUM_LIT:0> ] , pos <EOL> def kvpair ( pos ) : <EOL> k , p = anystring ( pos ) <EOL> p = musthave_literal ( p , RULE_EQUALS ) <EOL> v , p = value ( p ) <EOL> p = musthave_literal ( p , RULE_SEMICOLON ) <EOL> return ( k , v ) , p <EOL> def kvpairs ( pos ) : <EOL> return zero_or_more ( pos , kvpair , RULE_DICTIONARYEND ) <EOL> def dictionary ( pos ) : <EOL> try : <EOL> v , pos = sequence ( pos , RULE_DICTIONARY , kvpairs , RULE_DICTIONARYEND ) <EOL> return dictionarytype ( v [ <NUM_LIT:0> ] ) , pos <EOL> except RuntimeError as exc : <EOL> if str ( exc ) . startswith ( '<STR_LIT>' ) : <EOL> raise ParserError ( "<STR_LIT>" , pos ) <EOL> def quotedstring ( pos ) : <EOL> v , pos = named_rule ( pos , RULE_QUOTEDSTRING ) <EOL> return unescape_str ( v ) , pos <EOL> def unquotedstring ( pos ) : <EOL> return named_rule ( pos , RULE_UNQUOTEDSTRING ) <EOL> def named_rule ( pos , rulenr ) : <EOL> if rule_at ( pos ) != rulenr : <EOL> raise ParserError ( '<STR_LIT>' % rulenr , pos ) <EOL> return text_at ( pos ) , inc ( pos ) <EOL> def parse_xcodeplist_tokens ( pos ) : <EOL> try : <EOL> root = dictionary ( pos ) <EOL> except ParserError as e : <EOL> return False , e <EOL> if root is None : <EOL> return False , None <EOL> v , pos = root <EOL> if pos != len ( tokenrules ) : <EOL> return False , ParserError ( "<STR_LIT>" , pos ) <EOL> return True , v <EOL> success , root = parse_xcodeplist_tokens ( <NUM_LIT:0> ) <EOL> return success , root <EOL> def parse_xcodeproject_xml ( text , dictionarytype = dict ) : <EOL> """<STR_LIT>""" <EOL> structures = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> stack = [ '<STR_LIT>' ] <EOL> tokens = [ ] <EOL> def emit ( s ) : <EOL> tokens . append ( s ) <EOL> def emit_text ( s ) : <EOL> emit ( quoted_string ( s ) ) <EOL> def emit_terminator ( parent ) : <EOL> structure_markers = structures . get ( parent ) <EOL> if structure_markers is not None : <EOL> emit ( structure_markers [ - <NUM_LIT:1> ] ) <EOL> emit ( '<STR_LIT:\n>' ) <EOL> def iterxml ( buf ) : <EOL> try : <EOL> for event , elem in ETree . iterparse ( buf , events = ( '<STR_LIT:start>' , '<STR_LIT:end>' ) ) : <EOL> tag = elem . tag <EOL> if event == '<STR_LIT:start>' : <EOL> stack . append ( tag ) <EOL> else : <EOL> stack . pop ( ) <EOL> parent = stack [ - <NUM_LIT:1> ] <EOL> if event == '<STR_LIT:end>' : <EOL> if tag == '<STR_LIT:key>' : <EOL> emit_text ( elem . text ) <EOL> emit ( '<STR_LIT:=>' ) <EOL> elif tag == '<STR_LIT:string>' : <EOL> emit_text ( elem . text ) <EOL> emit_terminator ( parent ) <EOL> structure_markers = structures . get ( tag ) <EOL> if structure_markers : <EOL> if event == '<STR_LIT:start>' : <EOL> emit ( structure_markers [ <NUM_LIT:0> ] ) <EOL> else : <EOL> emit ( structure_markers [ <NUM_LIT:1> ] ) <EOL> emit_terminator ( parent ) <EOL> except ETree . ParseError as e : <EOL> linenr , column , errortext = error_report_from ( '<STR_LIT>' , text , text_type ( e ) ) <EOL> return { '<STR_LIT>' : column , <EOL> '<STR_LIT>' : linenr , <EOL> '<STR_LIT>' : errortext } <EOL> return None <EOL> errorparseinfo = iterxml ( BytesIO ( bytestr ( text ) ) ) <EOL> if errorparseinfo is not None : <EOL> return None , errorparseinfo <EOL> text = '<STR_LIT>' . join ( tokens ) <EOL> root , parseinfo = parse_xcodeproject_plist ( text , dictionarytype = dictionarytype ) <EOL> if root is not None : <EOL> parseinfo [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return root , parseinfo <EOL> def unparse ( root , format = '<STR_LIT>' , projectname = '<STR_LIT>' , disable_comments = False , parseinfo = None ) : <EOL> """<STR_LIT>""" <EOL> if root is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> unparserclass = unparsers . get ( format ) <EOL> if unparserclass is None : <EOL> raise ValueError ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( output_formats ) ) <EOL> unparser = unparserclass ( root ) <EOL> text = unparser . unparse ( root , projectname = projectname , disable_comments = disable_comments , parseinfo = parseinfo ) <EOL> return bytestr ( text ) <EOL> class Unparser ( object ) : <EOL> """<STR_LIT>""" <EOL> header = '<STR_LIT>' <EOL> trailer = '<STR_LIT:\n>' <EOL> keys_without_comments = frozenset ( [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] ) <EOL> pbx_names = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> commentpaths = frozenset ( [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> def __init__ ( self , root ) : <EOL> if root is None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . objects = root . get ( '<STR_LIT>' ) <EOL> self . keypath = [ ] <EOL> self . open_section = None <EOL> self . concise_mode = <NUM_LIT:0> <EOL> self . section_for_file = { } <EOL> self . build_configuration_lists = { } <EOL> self . gidcomments = { } <EOL> self . outputbuffer = None <EOL> self . projectname = None <EOL> self . disable_comments = None <EOL> self . version = None <EOL> self . last_userhash = None <EOL> def unparse ( self , root , projectname = '<STR_LIT>' , disable_comments = False , parseinfo = None ) : <EOL> if root is None : <EOL> return None <EOL> try : <EOL> self . version = int ( root . get ( '<STR_LIT>' ) ) <EOL> except TypeError : <EOL> return None <EOL> self . outputbuffer = [ ] <EOL> if projectname is not None : <EOL> projectname = decode_utf8_or_sys ( projectname ) <EOL> self . projectname = projectname <EOL> self . disable_comments = disable_comments <EOL> self . last_userhash = None <EOL> self . set_comment_handling ( disable_comments , parseinfo ) <EOL> self . create_lookup_tables ( ) <EOL> self . print_root ( root , indent = <NUM_LIT:0> ) <EOL> return self . getoutput ( ) <EOL> def emit ( self , s ) : <EOL> self . outputbuffer . append ( s ) <EOL> @ staticmethod <EOL> def getmember ( obj , name ) : <EOL> try : <EOL> return obj . get ( name ) <EOL> except AttributeError : <EOL> return None <EOL> def getoutput ( self ) : <EOL> return '<STR_LIT>' . join ( self . outputbuffer ) <EOL> def set_comment_handling ( self , disable_comments , parseinfo ) : <EOL> if disable_comments is not None : <EOL> self . disable_comments = disable_comments <EOL> return <EOL> sufficient_num_commented_nodes = <NUM_LIT:10> <EOL> if parseinfo : <EOL> num_present = parseinfo . get ( '<STR_LIT>' ) <EOL> if num_present is not None and num_present < sufficient_num_commented_nodes : <EOL> self . disable_comments = True <EOL> def print_root ( self , root , indent = <NUM_LIT:0> ) : <EOL> if not self . has_comments ( ) : <EOL> self . disable_comments = True <EOL> if self . has_utf8_header ( ) : <EOL> self . emit ( self . header ) <EOL> self . emit_node ( root , indent ) <EOL> self . emit ( self . trailer ) <EOL> def create_lookup_tables ( self ) : <EOL> """<STR_LIT>""" <EOL> for obj in self . objects . values ( ) : <EOL> files = self . getmember ( obj , '<STR_LIT>' ) <EOL> if isinstance ( files , list ) : <EOL> name = self . get_name ( obj ) <EOL> if name is None : <EOL> name = self . buildphasename ( self . getmember ( obj , '<STR_LIT>' ) ) <EOL> for f in files : <EOL> self . section_for_file [ f ] = name <EOL> bcl = self . getmember ( obj , '<STR_LIT>' ) <EOL> if bcl is not None : <EOL> self . build_configuration_lists [ bcl ] = obj <EOL> @ staticmethod <EOL> def buildphasename ( name ) : <EOL> if name is None : <EOL> return None <EOL> start = '<STR_LIT>' <EOL> end = '<STR_LIT>' <EOL> if name . startswith ( start ) and name . endswith ( end ) : <EOL> return name [ len ( start ) : - len ( end ) ] <EOL> return None <EOL> def supress_comment ( self ) : <EOL> if len ( self . keypath ) >= <NUM_LIT:1> and self . keypath [ - <NUM_LIT:1> ] in self . keys_without_comments : <EOL> return True <EOL> if len ( self . keypath ) >= <NUM_LIT:2> and self . keypath [ - <NUM_LIT:2> ] in self . keys_without_comments : <EOL> return True <EOL> return False <EOL> def comment_for_obj ( self , obj ) : <EOL> if self . disable_comments : <EOL> return None <EOL> if self . supress_comment ( ) : <EOL> return None <EOL> isa = self . getmember ( obj , '<STR_LIT>' ) <EOL> return ( self . pbx_names . get ( isa ) <EOL> or self . get_name ( obj ) <EOL> or self . buildphasename ( isa ) <EOL> or self . name_for_object ( obj ) ) <EOL> def build_configuration ( self , bcuuid ) : <EOL> obj = self . objects . get ( bcuuid ) <EOL> if obj is None : <EOL> return None <EOL> if obj . get ( '<STR_LIT>' ) != '<STR_LIT>' : <EOL> return None <EOL> obj = self . build_configuration_lists . get ( bcuuid ) <EOL> if obj is not None : <EOL> isa = obj . get ( '<STR_LIT>' ) <EOL> name = self . get_name ( obj ) or self . name_of_first_target ( obj ) <EOL> if isa == '<STR_LIT>' : <EOL> name = self . projectname or name . strip ( ) <EOL> name = self . transform_to_nfd ( name ) <EOL> comment = '<STR_LIT>' <EOL> if self . has_build_configuration_list_detail ( ) : <EOL> comment += '<STR_LIT>' % ( isa , name ) <EOL> return comment <EOL> return None <EOL> def name_of_first_target ( self , obj ) : <EOL> targets = self . getmember ( obj , '<STR_LIT>' ) <EOL> if isinstance ( targets , list ) : <EOL> for uuid in targets : <EOL> name = self . name_for_object ( self . objects . get ( uuid ) ) <EOL> if name is not None : <EOL> return name <EOL> return None <EOL> def transform_to_nfd ( self , text ) : <EOL> if text is None : <EOL> return None <EOL> if not self . has_nfd_comments ( ) : <EOL> return text <EOL> return unicodedata . normalize ( '<STR_LIT>' , text ) <EOL> def get_name ( self , obj ) : <EOL> return self . transform_to_nfd ( self . getmember ( obj , '<STR_LIT:name>' ) ) <EOL> def name_for_object ( self , obj ) : <EOL> if obj is None or not isinstance ( obj , dict ) : <EOL> return None <EOL> return ( self . get_name ( obj ) <EOL> or self . getmember ( obj , '<STR_LIT:path>' ) <EOL> or self . name_for_object ( self . objects . get ( self . getmember ( obj , '<STR_LIT>' ) ) ) <EOL> or self . name_of_first_target ( obj ) ) <EOL> def comment_for_value ( self , v ) : <EOL> if not is_global_id ( v ) : <EOL> return None <EOL> if not self . valid_comment_keypath ( ) : <EOL> return None <EOL> comment = self . gidcomments . get ( v ) <EOL> if comment is not None : <EOL> return comment <EOL> comment = None <EOL> buildconf = self . build_configuration ( v ) <EOL> if buildconf is not None : <EOL> comment = buildconf <EOL> else : <EOL> obj = self . objects . get ( v ) <EOL> if obj is not None and isinstance ( obj , dict ) : <EOL> comment = self . comment_for_obj ( obj ) <EOL> section = self . section_for_file . get ( v ) <EOL> if section is not None : <EOL> comment = "<STR_LIT>" % ( comment or '<STR_LIT>' , section ) <EOL> self . gidcomments [ v ] = comment or '<STR_LIT>' <EOL> return comment <EOL> def valid_comment_keypath ( self ) : <EOL> """<STR_LIT>""" <EOL> k = self . keypath <EOL> if k [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> if len ( k ) == <NUM_LIT:2> : <EOL> return True <EOL> elif len ( k ) >= <NUM_LIT:3> : <EOL> path = [ self . get_isa ( self . objects . get ( x ) ) or x for x in k [ <NUM_LIT:1> : ] ] <EOL> kp = '<STR_LIT:.>' . join ( path ) <EOL> return kp in self . commentpaths <EOL> return k == [ '<STR_LIT>' ] <EOL> def in_fileobj ( self , obj ) : <EOL> return self . getmember ( obj , '<STR_LIT>' ) in [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def get_isa ( self , obj ) : <EOL> if isinstance ( obj , dict ) : <EOL> return self . getmember ( obj , '<STR_LIT>' ) <EOL> return None <EOL> def begin_section ( self , obj ) : <EOL> isa = self . get_isa ( obj ) <EOL> if isa != self . open_section : <EOL> self . close_section ( ) <EOL> self . emit ( "<STR_LIT>" % isa ) <EOL> self . open_section = isa <EOL> return True <EOL> return False <EOL> def close_section ( self ) : <EOL> if self . open_section : <EOL> self . emit ( '<STR_LIT>' % self . open_section ) <EOL> self . open_section = None <EOL> def has_utf8_header ( self ) : <EOL> return self . version > <NUM_LIT:30> <EOL> def has_userhash_comments ( self ) : <EOL> return <NUM_LIT:32> < self . version < <NUM_LIT> <EOL> def has_ungrouped_objects_sort ( self ) : <EOL> return self . version < <NUM_LIT> <EOL> def has_leading_isa ( self ) : <EOL> return self . version >= <NUM_LIT> <EOL> def has_concise_format ( self ) : <EOL> return self . version >= <NUM_LIT> <EOL> def has_comments ( self ) : <EOL> return self . version >= <NUM_LIT> <EOL> def has_build_configuration_list_detail ( self ) : <EOL> return self . version >= <NUM_LIT> <EOL> def has_nfd_comments ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . version >= <NUM_LIT> <EOL> @ staticmethod <EOL> def objects_sortkey ( kv ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return kv [ <NUM_LIT:1> ] . get ( '<STR_LIT>' ) , kv [ <NUM_LIT:0> ] <EOL> except AttributeError : <EOL> return kv [ <NUM_LIT:0> ] <EOL> @ staticmethod <EOL> def ungrouped_objects_sortkey ( kv ) : <EOL> return kv [ <NUM_LIT:0> ] <EOL> def sorted_items ( self , dictionary ) : <EOL> if self . keypath == [ '<STR_LIT>' ] : <EOL> if self . has_ungrouped_objects_sort ( ) : <EOL> sortkey = self . ungrouped_objects_sortkey <EOL> else : <EOL> sortkey = self . objects_sortkey <EOL> else : <EOL> sortkey = None <EOL> if self . has_leading_isa ( ) : <EOL> isa = dictionary . get ( '<STR_LIT>' ) <EOL> if isa is not None : <EOL> items = [ ( '<STR_LIT>' , isa ) ] <EOL> items . extend ( sorted ( x for x in dictionary . items ( ) if x [ <NUM_LIT:0> ] != '<STR_LIT>' ) ) <EOL> return items <EOL> return sorted ( dictionary . items ( ) , key = sortkey ) <EOL> def emit_value ( self , v ) : <EOL> v = quoted_string ( v ) <EOL> self . emit ( v ) <EOL> comment = self . comment_for_value ( v ) <EOL> if comment is not None : <EOL> if not self . disable_comments : <EOL> self . emit_comment ( comment ) <EOL> def emit_kvpair ( self , k , v , indent ) : <EOL> self . emit_value ( k ) <EOL> self . emit ( '<STR_LIT>' ) <EOL> self . emit_node ( v , <NUM_LIT:0> if self . concise ( ) else indent ) <EOL> def concise ( self ) : <EOL> return self . concise_mode and self . has_concise_format ( ) <EOL> def emit_comment ( self , comment ) : <EOL> if comment : <EOL> self . emit ( '<STR_LIT>' ) <EOL> self . emit ( comment ) <EOL> self . emit ( '<STR_LIT>' ) <EOL> def emit_prologue ( self ) : <EOL> if not self . concise ( ) : <EOL> self . emit ( '<STR_LIT:\n>' ) <EOL> def emit_indent ( self , indent ) : <EOL> self . emit ( '<STR_LIT:\t>' * indent ) <EOL> def emit_leading_separator ( self , indent ) : <EOL> self . emit_indent ( <NUM_LIT:0> if self . concise ( ) else indent ) <EOL> def emit_trailing_separator ( self ) : <EOL> self . emit ( '<STR_LIT:U+0020>' if self . concise ( ) else '<STR_LIT:\n>' ) <EOL> def emit_userhash_comments ( self , k ) : <EOL> if not self . has_userhash_comments ( ) : <EOL> return <EOL> if len ( self . keypath ) != <NUM_LIT:1> : <EOL> return <EOL> if self . keypath [ <NUM_LIT:0> ] != '<STR_LIT>' : <EOL> return <EOL> if self . last_userhash is None : <EOL> self . last_userhash = k <EOL> return <EOL> a = self . last_userhash [ : <NUM_LIT:2> ] <EOL> b = k [ : <NUM_LIT:2> ] <EOL> if a != b : <EOL> self . emit_userhash_range ( a ) <EOL> self . emit_userhash_range ( b ) <EOL> self . last_userhash = b <EOL> def emit_userhash_range ( self , userhash ) : <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> self . emit ( '<STR_LIT>' % ( userhash , i ) ) <EOL> def emit_map ( self , node , indent ) : <EOL> self . emit ( '<STR_LIT:{>' ) <EOL> self . emit_prologue ( ) <EOL> began_sections = False <EOL> sections = self . keypath == [ '<STR_LIT>' ] and not self . disable_comments <EOL> for k , v in self . sorted_items ( node ) : <EOL> self . emit_userhash_comments ( k ) <EOL> self . keypath . append ( k ) <EOL> began_sections = sections and ( self . begin_section ( v ) or began_sections ) <EOL> self . emit_leading_separator ( indent + <NUM_LIT:1> ) <EOL> self . emit_kvpair ( k , v , indent + <NUM_LIT:1> ) <EOL> self . emit ( '<STR_LIT:;>' ) <EOL> self . emit_trailing_separator ( ) <EOL> self . keypath . pop ( ) <EOL> if began_sections : <EOL> self . close_section ( ) <EOL> self . emit_leading_separator ( indent ) <EOL> self . emit ( '<STR_LIT:}>' ) <EOL> def emit_list ( self , node , indent ) : <EOL> self . emit ( '<STR_LIT:(>' ) <EOL> self . emit_prologue ( ) <EOL> for v in node : <EOL> self . emit_leading_separator ( indent + <NUM_LIT:1> ) <EOL> self . emit_node ( v , indent + <NUM_LIT:1> ) <EOL> self . emit ( '<STR_LIT:U+002C>' ) <EOL> self . emit_trailing_separator ( ) <EOL> self . emit_leading_separator ( indent ) <EOL> self . emit ( '<STR_LIT:)>' ) <EOL> def emit_node ( self , node , indent = <NUM_LIT:0> ) : <EOL> if isinstance ( node , dict ) : <EOL> concise_output = self . in_fileobj ( node ) <EOL> if concise_output : <EOL> self . concise_mode += <NUM_LIT:1> <EOL> self . emit_map ( node , indent ) <EOL> if concise_output : <EOL> self . concise_mode -= <NUM_LIT:1> <EOL> elif isinstance ( node , ( list , tuple ) ) : <EOL> self . emit_list ( node , indent ) <EOL> else : <EOL> self . emit_value ( node ) <EOL> class XMLUnparser ( Unparser ) : <EOL> header = """<STR_LIT>""" <EOL> trailer = '<STR_LIT>' <EOL> def __init__ ( self , root ) : <EOL> super ( XMLUnparser , self ) . __init__ ( root ) <EOL> self . disable_comments = True <EOL> def has_concise_format ( self ) : <EOL> return False <EOL> def has_leading_isa ( self ) : <EOL> return False <EOL> @ staticmethod <EOL> def escape_tag_entities ( data ) : <EOL> data = data . replace ( "<STR_LIT:&>" , "<STR_LIT>" ) <EOL> data = data . replace ( "<STR_LIT:>>" , "<STR_LIT>" ) <EOL> data = data . replace ( "<STR_LIT:<>" , "<STR_LIT>" ) <EOL> return data <EOL> def emit_value ( self , v ) : <EOL> self . emit ( '<STR_LIT>' ) <EOL> self . emit ( self . escape_tag_entities ( v ) ) <EOL> self . emit ( '<STR_LIT>' ) <EOL> def emit_kvpair ( self , k , v , indent ) : <EOL> self . emit ( '<STR_LIT>' ) <EOL> self . emit ( self . escape_tag_entities ( k ) ) <EOL> self . emit ( '<STR_LIT>' ) <EOL> self . emit ( '<STR_LIT:\n>' ) <EOL> self . emit_node ( v , indent ) <EOL> def emit_map ( self , node , indent ) : <EOL> if not node : <EOL> self . emit ( '<STR_LIT>' ) <EOL> return <EOL> self . emit ( '<STR_LIT>' ) <EOL> self . emit ( '<STR_LIT:\n>' ) <EOL> for k , v in self . sorted_items ( node ) : <EOL> self . emit_indent ( indent + <NUM_LIT:1> ) <EOL> self . emit_kvpair ( k , v , indent + <NUM_LIT:1> ) <EOL> self . emit_indent ( indent ) <EOL> self . emit ( '<STR_LIT>' ) <EOL> def emit_list ( self , node , indent ) : <EOL> if len ( node ) == <NUM_LIT:0> : <EOL> self . emit ( '<STR_LIT>' ) <EOL> return <EOL> self . emit ( '<STR_LIT>' ) <EOL> self . emit ( '<STR_LIT:\n>' ) <EOL> for v in node : <EOL> self . emit_node ( v , indent + <NUM_LIT:1> ) <EOL> self . emit_leading_separator ( indent ) <EOL> self . emit ( '<STR_LIT>' ) <EOL> def emit_node ( self , node , indent = <NUM_LIT:0> ) : <EOL> self . emit_indent ( indent ) <EOL> super ( XMLUnparser , self ) . emit_node ( node , indent = indent ) <EOL> self . emit ( '<STR_LIT:\n>' ) <EOL> class JSONUnparser ( Unparser ) : <EOL> def __init__ ( self , root ) : <EOL> super ( JSONUnparser , self ) . __init__ ( root ) <EOL> self . disable_comments = True <EOL> def unparse ( self , root , projectname = '<STR_LIT>' , disable_comments = False , parseinfo = None ) : <EOL> try : <EOL> return json . dumps ( root , sort_keys = True , <EOL> indent = <NUM_LIT:2> , <EOL> separators = ( '<STR_LIT:U+002C>' , '<STR_LIT::>' ) ) <EOL> except ValueError : <EOL> return None <EOL> unparsers = OrderedDict ( [ <EOL> ( '<STR_LIT>' , Unparser ) , <EOL> ( '<STR_LIT>' , XMLUnparser ) , <EOL> ( '<STR_LIT>' , JSONUnparser ) ] ) <EOL> output_formats = unparsers . keys ( ) <EOL> class UniqueXcodeIDGenerator ( object ) : <EOL> """<STR_LIT>""" <EOL> AbsoluteTimeIntervalSince1970 = <NUM_LIT> <EOL> def __init__ ( self , username = None , pid = None , refdatefunc = None ) : <EOL> if refdatefunc is None : <EOL> refdatefunc = self . reftime <EOL> self . initialseq = <NUM_LIT:0> <EOL> self . lasttime = <NUM_LIT:0> <EOL> self . refdatefunc = refdatefunc <EOL> if pid is None : <EOL> pid = os . getpid ( ) <EOL> self . rndgen = random . Random ( xor ( ( pid << <NUM_LIT:16> ) , refdatefunc ( ) ) ) <EOL> self . userhash = self . user_hash ( username ) <EOL> self . pidbyte = pid & <NUM_LIT> <EOL> self . randomconst = self . rndgen . randint ( <NUM_LIT:0> , ( <NUM_LIT:2> ** <NUM_LIT> ) - <NUM_LIT:1> ) & <NUM_LIT> <EOL> self . randomseq = self . rndgen . randint ( <NUM_LIT:0> , ( <NUM_LIT:2> ** <NUM_LIT> ) - <NUM_LIT:1> ) & <NUM_LIT> <EOL> def generate ( self ) : <EOL> refdate = self . refdatefunc ( ) <EOL> self . randomseq += <NUM_LIT:1> <EOL> self . lasttime = <NUM_LIT:0> <EOL> if refdate > self . lasttime : <EOL> self . initialseq = self . randomseq <EOL> self . lasttime = refdate <EOL> else : <EOL> if self . randomseq == self . initialseq : <EOL> self . lasttime += <NUM_LIT:1> <EOL> refdate = self . lasttime <EOL> return ( self . hexbyte ( self . userhash ) + self . hexbyte ( self . pidbyte ) <EOL> + self . big_endian_hex ( self . randomseq , <NUM_LIT:2> ) <EOL> + self . big_endian_hex ( refdate , <NUM_LIT:4> ) <EOL> + self . big_endian_hex ( self . randomconst , <NUM_LIT:4> ) ) <EOL> @ staticmethod <EOL> def user_hash ( username = None ) : <EOL> userhash = <NUM_LIT:0> <EOL> hashvalue = <NUM_LIT:0> <EOL> if username is None : <EOL> username = os . getlogin ( ) <EOL> for inp in username : <EOL> cc = UniqueXcodeIDGenerator . five_bit_hash ( ord ( inp ) ) <EOL> if hashvalue != <NUM_LIT:0> : <EOL> cc = ( ( cc << hashvalue ) >> <NUM_LIT:8> ) | ( cc << hashvalue ) <EOL> hashvalue = hashvalue + <NUM_LIT:5> & <NUM_LIT:7> <EOL> userhash = xor ( userhash , cc ) <EOL> return userhash & <NUM_LIT:255> <EOL> @ staticmethod <EOL> def five_bit_hash ( c ) : <EOL> if ord ( '<STR_LIT:A>' ) <= c <= ord ( '<STR_LIT>' ) : <EOL> return c - ord ( '<STR_LIT:A>' ) <EOL> elif ord ( '<STR_LIT:a>' ) <= c <= ord ( '<STR_LIT:z>' ) : <EOL> return c - ord ( '<STR_LIT:a>' ) <EOL> elif ord ( '<STR_LIT:0>' ) <= c <= ord ( '<STR_LIT>' ) : <EOL> return ord ( '<STR_LIT>' ) - ord ( '<STR_LIT:A>' ) + <NUM_LIT:1> + ( ( c - ord ( '<STR_LIT:0>' ) ) % <NUM_LIT:5> ) <EOL> else : <EOL> return <NUM_LIT> <EOL> @ staticmethod <EOL> def hexbyte ( c ) : <EOL> return '<STR_LIT>' % c <EOL> @ staticmethod <EOL> def big_endian_hex ( v , size ) : <EOL> lst = [ ] <EOL> for _ in range ( size ) : <EOL> lst . append ( v & <NUM_LIT> ) <EOL> v >>= <NUM_LIT:8> <EOL> lst . reverse ( ) <EOL> return '<STR_LIT>' . join ( UniqueXcodeIDGenerator . hexbyte ( c ) for c in lst ) <EOL> @ staticmethod <EOL> def big_endian_number ( hexstring ) : <EOL> sum = <NUM_LIT:0> <EOL> while hexstring : <EOL> sum *= <NUM_LIT> <EOL> byte = hexstring [ : <NUM_LIT:2> ] <EOL> sum += int ( byte , <NUM_LIT:16> ) <EOL> hexstring = hexstring [ <NUM_LIT:2> : ] <EOL> return sum <EOL> @ staticmethod <EOL> def reftime ( t = None ) : <EOL> if t is None : <EOL> t = time . time ( ) <EOL> return int ( t - UniqueXcodeIDGenerator . AbsoluteTimeIntervalSince1970 ) <EOL> @ staticmethod <EOL> def reftime_to_epoch ( t ) : <EOL> return t + UniqueXcodeIDGenerator . AbsoluteTimeIntervalSince1970 <EOL> class IDGeneratorClock ( object ) : <EOL> def __init__ ( self , seconds ) : <EOL> self . seconds = seconds <EOL> def tick ( self ) : <EOL> self . seconds += <NUM_LIT:1> <EOL> def getseconds ( self ) : <EOL> return self . seconds <EOL> def datetime_from_utc ( refdate ) : <EOL> return datetime . datetime . strptime ( refdate , '<STR_LIT>' ) <EOL> def generate_gids ( num , username = None , pid = None , refdate = None ) : <EOL> if refdate is not None : <EOL> dt = datetime_from_utc ( refdate ) <EOL> t = time . mktime ( dt . timetuple ( ) ) <EOL> else : <EOL> t = None <EOL> secs = UniqueXcodeIDGenerator . reftime ( t ) <EOL> clock = IDGeneratorClock ( secs ) <EOL> generator = UniqueXcodeIDGenerator ( username = username , pid = pid , refdatefunc = clock . getseconds ) <EOL> for i in range ( num ) : <EOL> gid = generator . generate ( ) <EOL> yield gid <EOL> if i & <NUM_LIT> == <NUM_LIT> : <EOL> clock . tick ( ) <EOL> def iprint ( category , * args , ** kwargs ) : <EOL> if category in args_info : <EOL> print ( * args , ** kwargs ) <EOL> def dprint ( category , * args , ** kwargs ) : <EOL> if category in args_debug : <EOL> print ( * args , ** kwargs ) <EOL> def outline ( s , fp = None ) : <EOL> if fp is None : <EOL> fp = sys . stdout <EOL> fp . write ( unistr ( s + '<STR_LIT:\n>' ) ) <EOL> reportmessage = outline <EOL> def reporterror ( s , fp = None ) : <EOL> if fp is None : <EOL> fp = sys . stderr <EOL> reportmessage ( s , fp = fp ) <EOL> reportwarning = reporterror <EOL> def print_gids ( num , username = None , pid = None , refdate = None ) : <EOL> for g in generate_gids ( num , username = username , pid = pid , refdate = refdate ) : <EOL> outline ( unistr ( g ) ) <EOL> return OK <EOL> def comment_for_gid ( giddict , gid ) : <EOL> if isinstance ( giddict , dict ) : <EOL> comment = giddict . get ( gid ) <EOL> if comment is not None : <EOL> return comment <EOL> return None <EOL> def gidfields ( giddict , gid ) : <EOL> parts = gid [ : <NUM_LIT:2> ] , gid [ <NUM_LIT:2> : <NUM_LIT:4> ] , gid [ <NUM_LIT:4> : <NUM_LIT:8> ] , gid [ <NUM_LIT:8> : <NUM_LIT:16> ] , gid [ <NUM_LIT:16> : <NUM_LIT> ] <EOL> parts = [ UniqueXcodeIDGenerator . big_endian_number ( x ) for x in parts ] <EOL> user , pid , seq , date , randomconst = parts <EOL> date = UniqueXcodeIDGenerator . reftime_to_epoch ( date ) <EOL> date = datetime . datetime . utcfromtimestamp ( date ) <EOL> date = date . isoformat ( ) + '<STR_LIT>' <EOL> comment = comment_for_gid ( giddict , gid ) <EOL> d = OrderedDict ( [ <EOL> ( '<STR_LIT:date>' , date ) , <EOL> ( '<STR_LIT:user>' , user ) , <EOL> ( '<STR_LIT>' , pid ) , <EOL> ( '<STR_LIT>' , randomconst ) , <EOL> ( '<STR_LIT>' , seq ) , <EOL> ( '<STR_LIT>' , gid ) ] ) <EOL> if comment : <EOL> d [ '<STR_LIT>' ] = comment <EOL> return d <EOL> def gidsplit ( gidseq , format = '<STR_LIT:text>' , sort = False , buf = None ) : <EOL> """<STR_LIT>""" <EOL> gids = [ g for g in gidseq if is_global_id ( g ) ] <EOL> if not gids : <EOL> return <EOL> out = buf <EOL> if out is None : <EOL> out = sys . stdout <EOL> def uniwrite ( text ) : <EOL> out . write ( unistr ( text ) ) <EOL> if sort : <EOL> gids . sort ( ) <EOL> entries = [ gidfields ( gidseq , gid ) for gid in gids ] <EOL> if format == '<STR_LIT>' : <EOL> root = { '<STR_LIT>' : entries } <EOL> uniwrite ( json . dumps ( root , sort_keys = True , indent = <NUM_LIT:2> , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT::>' ) ) ) <EOL> uniwrite ( '<STR_LIT:\n>' ) <EOL> elif format == '<STR_LIT:text>' : <EOL> formatstrings = { "<STR_LIT:date>" : "<STR_LIT:%s>" , "<STR_LIT:user>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:%s>" } <EOL> jsondumps = json . JSONEncoder ( ) . encode <EOL> for d in entries : <EOL> comment = d . get ( '<STR_LIT>' ) <EOL> if comment is not None : <EOL> d [ '<STR_LIT>' ] = jsondumps ( comment ) <EOL> uniwrite ( '<STR_LIT:U+0020>' . join ( formatstrings [ k ] % v for k , v in d . items ( ) ) ) <EOL> uniwrite ( '<STR_LIT:\n>' ) <EOL> return OK <EOL> def giddump ( args , parser ) : <EOL> filenames = args . filename <EOL> if len ( filenames ) > <NUM_LIT:1> : <EOL> parser . error ( '<STR_LIT>' ) <EOL> return <NUM_LIT:1> <EOL> filename = ( filenames and filenames [ <NUM_LIT:0> ] ) or STDIN <EOL> xcodeproj = data_from_filename ( filename ) <EOL> root , parseinfo = parse ( xcodeproj , parsertype = args . parser ) <EOL> report_parse_status ( root , parseinfo , filename = filename ) <EOL> if root is None : <EOL> return PARSING_FAILED <EOL> projectname = projectname_from_args ( args , parser , filename , parseinfo . get ( '<STR_LIT>' ) ) <EOL> unparser = Unparser ( root ) <EOL> _ = unparser . unparse ( root , projectname = projectname ) <EOL> if args . outputfile is not None and args . outputfile != '<STR_LIT:->' : <EOL> destfilename = args . outputfile <EOL> with codecs . open ( destfilename , '<STR_LIT:w>' , encoding = '<STR_LIT:utf-8>' ) as fp : <EOL> gidsplit ( unparser . gidcomments , format = args . gid_format , sort = True , buf = fp ) <EOL> else : <EOL> gidsplit ( unparser . gidcomments , format = args . gid_format , sort = True ) <EOL> return OK <EOL> def find_projectfiles ( rootdir ) : <EOL> """<STR_LIT>""" <EOL> validfirstchars = { '<STR_LIT:/>' , <EOL> '<STR_LIT:<>' , <EOL> '<STR_LIT:{>' <EOL> } <EOL> for path , dirs , files in os . walk ( rootdir ) : <EOL> for name in files : <EOL> if name != PBXPROJNAME : <EOL> continue <EOL> filename = os . path . join ( path , name ) <EOL> with codecs . open ( filename , '<STR_LIT:r>' , encoding = '<STR_LIT:utf-8>' ) as f : <EOL> c = f . read ( <NUM_LIT:1> ) <EOL> if c in validfirstchars : <EOL> yield filename <EOL> def unilines ( text ) : <EOL> return unistr ( text ) . splitlines ( True ) <EOL> def print_unified_diff ( a , b , fp = None , ** kwargs ) : <EOL> if fp is None : <EOL> fp = sys . stdout <EOL> for line in difflib . unified_diff ( unilines ( a ) , unilines ( b ) , ** kwargs ) : <EOL> fp . write ( unistr ( line ) ) <EOL> if not line . endswith ( '<STR_LIT:\n>' ) : <EOL> fp . write ( unistr ( '<STR_LIT:\n>' ) ) <EOL> def timestamp ( ) : <EOL> return '<STR_LIT>' + str ( time . time ( ) ) . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) <EOL> def print_diff ( a , b , difftype = '<STR_LIT>' , filename = None , fp = None ) : <EOL> def write_tempfile ( data , ** kwargs ) : <EOL> fd , path = tempfile . mkstemp ( ** kwargs ) <EOL> try : <EOL> os . write ( fd , bytestr ( data ) ) <EOL> finally : <EOL> os . close ( fd ) <EOL> return path <EOL> if difftype == '<STR_LIT>' : <EOL> print_unified_diff ( a , b , fromfile = filename , tofile = '<STR_LIT>' , n = <NUM_LIT:3> , fp = fp ) <EOL> elif difftype == '<STR_LIT:html>' : <EOL> htmldiffer = difflib . HtmlDiff ( tabsize = <NUM_LIT:4> ) <EOL> html = htmldiffer . make_file ( unilines ( a ) , unilines ( b ) , <EOL> fromdesc = filename , <EOL> todesc = '<STR_LIT>' , <EOL> context = True , numlines = <NUM_LIT:2> ) <EOL> htmlfilename = write_tempfile ( html , suffix = '<STR_LIT>' , prefix = timestamp ( ) ) <EOL> reporterror ( '<STR_LIT>' % htmlfilename , fp = fp ) <EOL> elif difftype == '<STR_LIT>' : <EOL> outfilename = write_tempfile ( b , suffix = '<STR_LIT>' , prefix = timestamp ( ) ) <EOL> reporterror ( '<STR_LIT>' % ( filename , outfilename ) , fp = fp ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % difftype ) <EOL> def farthest_parseinfo ( parseinfo ) : <EOL> """<STR_LIT>""" <EOL> line = parseinfo . get ( '<STR_LIT>' , - <NUM_LIT:1> ) <EOL> column = parseinfo . get ( '<STR_LIT>' , - <NUM_LIT:1> ) <EOL> prev = parseinfo . get ( '<STR_LIT>' ) <EOL> if prev is None : <EOL> return line , column , parseinfo <EOL> prevline , prevcolumn , prev = farthest_parseinfo ( prev ) <EOL> if ( prevline , prevcolumn ) > ( line , column ) : <EOL> return prevline , prevcolumn , prev <EOL> else : <EOL> return line , column , parseinfo <EOL> def report_parse_status ( root , parseinfo , filename = None , fp = None ) : <EOL> if isinstance ( parseinfo , dict ) : <EOL> _warnings = parseinfo . get ( '<STR_LIT>' , [ ] ) <EOL> for w in _warnings : <EOL> reportwarning ( w , fp = fp ) <EOL> iprint ( INFO_TIME , "<STR_LIT>" , parseinfo . get ( '<STR_LIT>' ) ) <EOL> if root is not None : <EOL> return <EOL> if filename == STDIN : <EOL> filename = '<STR_LIT>' <EOL> else : <EOL> filename = '<STR_LIT:%s>' % filename <EOL> line , column , parseinfo = farthest_parseinfo ( parseinfo ) <EOL> parseinfo = parseinfo . copy ( ) <EOL> parseinfo [ '<STR_LIT:filename>' ] = filename <EOL> reporterror ( '<STR_LIT>' % parseinfo , fp = fp ) <EOL> reporterror ( parseinfo . get ( '<STR_LIT>' ) , fp = fp ) <EOL> def data_from_filename ( filename ) : <EOL> if filename == STDIN : <EOL> return sys . stdin . read ( ) <EOL> else : <EOL> with open ( filename , '<STR_LIT:rb>' ) as f : <EOL> return f . read ( ) <EOL> def projectname_from_args ( args , parser , filename , prjname = None ) : <EOL> if filename == STDIN : <EOL> projectname = args . projectname <EOL> if projectname is None : <EOL> if prjname is not None : <EOL> reportwarning ( '<STR_LIT>' <EOL> '<STR_LIT>' % prjname ) <EOL> projectname = prjname <EOL> else : <EOL> parser . error ( '<STR_LIT>' ) <EOL> else : <EOL> projectname = projectname_for_path ( filename ) <EOL> return projectname <EOL> def lint ( args , parser ) : <EOL> filenames = args . filename <EOL> exit_code = OK <EOL> if not filenames : <EOL> filenames = [ STDIN ] <EOL> for filename in filenames : <EOL> xcodeproj = data_from_filename ( filename ) <EOL> root , parseinfo = parse ( xcodeproj , format = None , parsertype = args . parser ) <EOL> report_parse_status ( root , parseinfo , filename = filename ) <EOL> if root is None : <EOL> exit_code = max ( exit_code , LINT_FAILED ) <EOL> continue <EOL> if parseinfo [ '<STR_LIT>' ] not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> reportmessage ( '<STR_LIT>' % ( filename , parseinfo [ '<STR_LIT>' ] ) ) <EOL> exit_code = max ( exit_code , LINT_FAILED ) <EOL> continue <EOL> if parseinfo [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> reportmessage ( '<STR_LIT>' % filename ) <EOL> exit_code = max ( exit_code , LINT_FAILED ) <EOL> continue <EOL> projectname = projectname_from_args ( args , parser , filename , parseinfo . get ( '<STR_LIT>' ) ) <EOL> proj = unparse ( root , projectname = projectname ) <EOL> if xcodeproj != proj : <EOL> exit_code = max ( exit_code , LINT_DIFFERENCES ) <EOL> print_unified_diff ( xcodeproj , proj , fromfile = filename ) <EOL> return exit_code <EOL> def convert ( args , parser ) : <EOL> filenames = args . filename <EOL> if len ( filenames ) > <NUM_LIT:1> : <EOL> parser . error ( '<STR_LIT>' ) <EOL> return <NUM_LIT:1> <EOL> filename = ( filenames and filenames [ <NUM_LIT:0> ] ) or STDIN <EOL> xcodeproj = data_from_filename ( filename ) <EOL> root , parseinfo = parse ( xcodeproj , parsertype = args . parser ) <EOL> report_parse_status ( root , parseinfo , filename = filename ) <EOL> if root is None : <EOL> return PARSING_FAILED <EOL> if args . objectversion != '<STR_LIT>' : <EOL> if args . objectversion == '<STR_LIT>' : <EOL> version = text_type ( LATEST_OBJECT_VERSION ) <EOL> else : <EOL> version = args . objectversion <EOL> root [ '<STR_LIT>' ] = version <EOL> projectname = projectname_from_args ( args , parser , filename , parseinfo . get ( '<STR_LIT>' ) ) <EOL> proj = unparse ( root , <EOL> format = args . convert , <EOL> projectname = projectname , <EOL> disable_comments = args . comments == '<STR_LIT>' , <EOL> parseinfo = parseinfo ) <EOL> if args . outputfile is not None : <EOL> destfilename = args . outputfile <EOL> elif filename == STDIN : <EOL> destfilename = STDOUT <EOL> else : <EOL> destfilename = filename <EOL> if destfilename == STDOUT : <EOL> buf = sys . stdout <EOL> try : <EOL> numbytes = buf . write ( proj ) <EOL> except TypeError : <EOL> numbytes = len ( proj ) <EOL> buf . write ( unistr ( proj ) ) <EOL> else : <EOL> with open ( destfilename , '<STR_LIT:wb>' ) as f : <EOL> numbytes = f . write ( proj ) <EOL> if numbytes is not None and numbytes != len ( proj ) : <EOL> reporterror ( '<STR_LIT>' % ( numbytes , len ( proj ) ) ) <EOL> return CONVERT_OUTPUT_FAILED <EOL> return OK <EOL> def cmdline_parser ( parserclass = argparse . ArgumentParser ) : <EOL> """<STR_LIT>""" <EOL> parser = parserclass ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , choices = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , default = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:count>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:version>' , version = '<STR_LIT>' + __version__ ) <EOL> group = parser . add_argument_group ( '<STR_LIT>' ) <EOL> group . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , choices = output_formats , help = '<STR_LIT>' ) <EOL> group . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> group . add_argument ( '<STR_LIT>' , choices = [ '<STR_LIT:yes>' , '<STR_LIT>' , '<STR_LIT>' ] , default = '<STR_LIT:yes>' , <EOL> help = '<STR_LIT>' ) <EOL> lintgroup = parser . add_argument_group ( '<STR_LIT>' ) <EOL> lintgroup . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' ) <EOL> gidgroup = parser . add_argument_group ( '<STR_LIT>' ) <EOL> gidgroup . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:?>' , const = <NUM_LIT:1> , type = int , default = None , metavar = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> gidgroup . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:+>' , default = None , metavar = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> gidgroup . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' ) <EOL> gidgroup . add_argument ( '<STR_LIT>' , type = int , default = None , help = '<STR_LIT>' ) <EOL> gidgroup . add_argument ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> gidgroup . add_argument ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> gidgroup . add_argument ( '<STR_LIT>' , choices = [ '<STR_LIT>' , '<STR_LIT:text>' ] , default = '<STR_LIT:text>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:filename>' , nargs = '<STR_LIT:*>' , help = '<STR_LIT>' ) <EOL> return parser <EOL> def set_logging_parameters ( args ) : <EOL> for attr , catset , defaults in ( <EOL> ( '<STR_LIT:info>' , args_info , INFO_ALL ) , <EOL> ( '<STR_LIT>' , args_debug , DEBUG_ALL ) ) : <EOL> option = getattr ( args , attr ) <EOL> if option : <EOL> catset . update ( x . lower ( ) for x in option . split ( '<STR_LIT:U+002C>' ) ) <EOL> if '<STR_LIT:all>' in catset : <EOL> catset . update ( defaults ) <EOL> if args . verbose is not None : <EOL> for level in sorted ( verbose_categories ) : <EOL> if args . verbose >= level : <EOL> args_info . update ( verbose_categories [ level ] ) <EOL> def run_with_args ( args , parser ) : <EOL> set_logging_parameters ( args ) <EOL> dprint ( DEBUG_OPTIONS , args ) <EOL> num_actions = <NUM_LIT:0> <EOL> actions = '<STR_LIT>' . split ( ) <EOL> for act in actions : <EOL> if getattr ( args , act ) : <EOL> num_actions += <NUM_LIT:1> <EOL> if num_actions != <NUM_LIT:1> : <EOL> parser . error ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' + x for x in actions ) ) <EOL> ret = <NUM_LIT:0> <EOL> if args . gid is not None : <EOL> ret = print_gids ( args . gid , username = args . gid_user , pid = args . gid_pid , refdate = args . gid_date ) <EOL> elif args . gidsplit : <EOL> ret = gidsplit ( args . gidsplit , format = args . gid_format ) <EOL> elif args . giddump : <EOL> ret = giddump ( args , parser ) <EOL> elif args . lint : <EOL> ret = lint ( args , parser ) <EOL> elif args . convert : <EOL> ret = convert ( args , parser ) <EOL> else : <EOL> parser . error ( '<STR_LIT>' ) <EOL> return ret <EOL> def main ( ) : <EOL> parser = cmdline_parser ( ) <EOL> args = parser . parse_args ( ) <EOL> run_with_args ( args , parser ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> if PY3 : <EOL> sys . stdout = codecs . getwriter ( '<STR_LIT:utf8>' ) ( sys . stdout . buffer ) <EOL> sys . stderr = codecs . getwriter ( '<STR_LIT:utf8>' ) ( sys . stderr . buffer ) <EOL> sys . exit ( main ( ) ) </s>
