<s> """<STR_LIT>""" <EOL> from __future__ import print_function , division <EOL> import sys <EOL> import os <EOL> import fnmatch <EOL> import re <EOL> EXCLUSIONS = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> re_defs = re . compile ( "<STR_LIT>" , re . MULTILINE ) <EOL> re_pins = re . compile ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> re . MULTILINE ) <EOL> re_refn = re . compile ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , re . MULTILINE ) <EOL> re_name = re . compile ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , re . MULTILINE ) <EOL> re_fp = re . compile ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , re . MULTILINE ) <EOL> re_ds = re . compile ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , re . MULTILINE ) <EOL> re_oc = re . compile ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , re . MULTILINE ) <EOL> re_poly = re . compile ( "<STR_LIT>" , re . MULTILINE ) <EOL> def checkdefs ( contents , libf , errs ) : <EOL> n_defs = re_defs . findall ( contents ) <EOL> if len ( n_defs ) > <NUM_LIT:1> : <EOL> errs . append ( "<STR_LIT>" ) <EOL> elif len ( n_defs ) == <NUM_LIT:0> : <EOL> errs . append ( "<STR_LIT>" ) <EOL> partname = n_defs [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> designator = n_defs [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> libname = os . path . split ( libf ) [ - <NUM_LIT:1> ] . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] <EOL> if partname . lower ( ) != libname : <EOL> errs . append ( "<STR_LIT>" <EOL> . format ( partname , libname ) ) <EOL> return partname , designator <EOL> def checkpins ( contents , designator , errs ) : <EOL> pins = re_pins . findall ( contents ) <EOL> nums = [ ] <EOL> for name , num , x , y , length , numsize , namesize in pins : <EOL> if int ( x ) % <NUM_LIT:100> != <NUM_LIT:0> or int ( y ) % <NUM_LIT:100> != <NUM_LIT:0> : <EOL> errs . append ( "<STR_LIT>" . format ( name ) ) <EOL> if designator in ( "<STR_LIT>" , "<STR_LIT>" ) and int ( length ) not in ( <NUM_LIT:100> , <NUM_LIT> ) : <EOL> errs . append ( "<STR_LIT>" <EOL> . format ( name ) ) <EOL> if int ( namesize ) != <NUM_LIT:50> or ( int ( numsize ) != <NUM_LIT:50> and num . isdigit ( ) ) : <EOL> errs . append ( "<STR_LIT>" . format ( name ) ) <EOL> if num . isdigit ( ) : <EOL> nums . append ( int ( num ) ) <EOL> if nums : <EOL> expected = set ( range ( min ( nums ) , max ( nums ) + <NUM_LIT:1> ) ) <EOL> if set ( nums ) != expected : <EOL> missing = [ str ( x ) for x in set ( expected ) - set ( nums ) ] <EOL> errs . append ( "<STR_LIT>" . format ( "<STR_LIT:U+002CU+0020>" . join ( missing ) ) ) <EOL> duplicates = set ( [ str ( x ) for x in nums if nums . count ( x ) > <NUM_LIT:1> ] ) <EOL> if duplicates : <EOL> errs . append ( "<STR_LIT>" . format ( "<STR_LIT:U+002CU+0020>" . join ( duplicates ) ) ) <EOL> def checkboxes ( contents , designator , errs ) : <EOL> if designator == "<STR_LIT>" : <EOL> boxes = re_poly . findall ( contents ) <EOL> if "<STR_LIT:f>" not in boxes : <EOL> errs . append ( "<STR_LIT>" ) <EOL> def checkfields ( contents , errs , prettypath ) : <EOL> refn_f = re_refn . findall ( contents ) <EOL> name_f = re_name . findall ( contents ) <EOL> foot_f = re_fp . findall ( contents ) <EOL> data_f = re_ds . findall ( contents ) <EOL> code_f = re_oc . findall ( contents ) <EOL> fields = ( ( refn_f , "<STR_LIT>" ) , ( name_f , "<STR_LIT:name>" ) , ( foot_f , "<STR_LIT>" ) , <EOL> ( data_f , "<STR_LIT>" ) , ( code_f , "<STR_LIT>" ) ) <EOL> for field , fn in fields : <EOL> for value , x , y , size , orient , visible , hjust , vjust in field : <EOL> if fn in ( "<STR_LIT>" , "<STR_LIT:name>" ) : <EOL> if visible != "<STR_LIT>" : <EOL> if "<STR_LIT>" . format ( fn ) not in contents : <EOL> errs . append ( "<STR_LIT>" . format ( fn ) ) <EOL> else : <EOL> if visible != "<STR_LIT:I>" : <EOL> errs . append ( "<STR_LIT>" . format ( fn ) ) <EOL> if orient != "<STR_LIT:H>" : <EOL> errs . append ( "<STR_LIT>" . format ( fn ) ) <EOL> if size != "<STR_LIT>" : <EOL> errs . append ( "<STR_LIT>" . format ( fn ) ) <EOL> refn_y = int ( refn_f [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] ) <EOL> name_y = int ( name_f [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] ) <EOL> if refn_y <= name_y : <EOL> errs . append ( "<STR_LIT>" ) <EOL> fp = foot_f [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> if fp . startswith ( "<STR_LIT>" ) : <EOL> fp = fp . split ( "<STR_LIT::>" ) [ <NUM_LIT:1> ] + "<STR_LIT>" <EOL> path = os . path . join ( prettypath , fp ) <EOL> if not os . path . exists ( path ) : <EOL> errs . append ( "<STR_LIT>" <EOL> . format ( fp ) ) <EOL> elif len ( fp ) > <NUM_LIT:0> and "<STR_LIT::>" not in fp : <EOL> errs . append ( "<STR_LIT>" <EOL> . format ( fp ) ) <EOL> def checklib ( libf , prettypath ) : <EOL> errs = [ ] <EOL> dcmpath = "<STR_LIT:.>" . join ( libf . split ( "<STR_LIT:.>" ) [ : - <NUM_LIT:1> ] ) + "<STR_LIT>" <EOL> if not os . path . isfile ( dcmpath ) : <EOL> errs . append ( "<STR_LIT>" ) <EOL> with open ( libf ) as f : <EOL> contents = f . read ( ) <EOL> partname , designator = checkdefs ( contents , libf , errs ) <EOL> checkpins ( contents , designator , errs ) <EOL> checkboxes ( contents , designator , errs ) <EOL> checkfields ( contents , errs , prettypath ) <EOL> if len ( errs ) == <NUM_LIT:0> : <EOL> print ( "<STR_LIT>" . format ( libf ) ) <EOL> return True <EOL> else : <EOL> print ( "<STR_LIT>" . format ( libf ) , file = sys . stderr ) <EOL> for err in errs : <EOL> print ( "<STR_LIT:U+0020>" + err , file = sys . stderr ) <EOL> print ( "<STR_LIT>" , file = sys . stderr ) <EOL> return False <EOL> def main ( libpath , prettypath ) : <EOL> ok = True <EOL> for dirpath , dirnames , files in os . walk ( libpath ) : <EOL> dirnames . sort ( ) <EOL> files . sort ( ) <EOL> for f in fnmatch . filter ( files , "<STR_LIT>" ) : <EOL> path = os . path . join ( dirpath , f ) <EOL> if f not in EXCLUSIONS : <EOL> result = checklib ( path , prettypath ) <EOL> if not result : <EOL> ok = False <EOL> else : <EOL> print ( "<STR_LIT>" . format ( path ) ) <EOL> return ok <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if len ( sys . argv ) != <NUM_LIT:3> : <EOL> print ( "<STR_LIT>" . format ( sys . argv [ <NUM_LIT:0> ] ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> libpath = sys . argv [ <NUM_LIT:1> ] <EOL> prettypath = sys . argv [ <NUM_LIT:2> ] <EOL> success = main ( libpath , prettypath ) <EOL> if success : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> else : <EOL> sys . exit ( <NUM_LIT:1> ) </s>
