11#!/usr/bin/python
2- # Copyright The IETF Trust 2009-2021 , All Rights Reserved
2+ # Copyright The IETF Trust 2009-2022 , All Rights Reserved
33# -*- coding: utf-8 -*-
44# -*- python -*-
55
6363opt_timestamp = False
6464opt_trace = False
6565opt_authorinfo = False
66- opt_getauthors = False
6766opt_attributes = False
6867# Don't forget to add the option variable to the globals list in _main below
6968
@@ -1243,28 +1242,6 @@ def getmeta(fn):
12431242 filename = fn
12441243 fn = os .path .basename (fn )
12451244 else :
1246- if fn .lower ().startswith ('rfc' ):
1247- filename = os .path .join ("/www/tools.ietf.org/rfc" , fn )
1248- elif not "/" in fn :
1249- filename = os .path .join ("/www/tools.ietf.org/id" , fn )
1250- if not os .path .exists (filename ):
1251- fn = filename
1252- while not "-00." in fn :
1253- revmatch = re .search (r"-(\d\d)\." , fn )
1254- if revmatch :
1255- rev = revmatch .group (1 )
1256- prev = "%02d" % (int (rev )- 1 )
1257- fn = fn .replace ("-%s." % rev , "-%s." % prev )
1258- if os .path .exists (fn ):
1259- _warn ("Using rev %s instead: '%s'" % (prev , filename ))
1260- filename = fn
1261- fn = os .path .basename (fn )
1262- break
1263- else :
1264- break
1265- else :
1266- filename = fn
1267- if not os .path .exists (filename ):
12681245 _warn ("Could not find file: '%s'" % (filename ))
12691246 return
12701247
@@ -1305,52 +1282,28 @@ def getmeta(fn):
13051282# ----------------------------------------------------------------------
13061283def _output (docname , fields , outfile = sys .stdout ):
13071284 global company_domain
1308- if opt_getauthors :
1309- # Output an (incomplete!) getauthors-compatible format.
1310- # Information about security and iana sections presence is
1311- # missing.
1312- for full ,first ,middle ,last ,suffix ,email ,country ,company in fields ["_authorlist" ]:
1313- if company in company_domain :
1314- company = company_domain [company ]
1285+
1286+ if opt_attributes :
1287+ def outputkey (key , fields ):
1288+ field = fields [key ]
1289+ if "\n " in field :
1290+ field = "\n " + field .rstrip ()
13151291 else :
1316- if email and '@' in email :
1317- company = email .split ('@' )[1 ]
1318- if company .endswith (".com" ):
1319- company = company [:- 4 ]
1320- fields ["name" ] = full
1321- fields ["email" ] = email
1322- fields ["company" ] = company
1323- fields ["country" ] = country or "UNKNOWN"
1324- try :
1325- year , month , day = fields ["doccreationdate" ].split ("-" )
1326- except ValueError :
1327- year , month , day = "UNKNOWN" , "UNKNOWN" , "UNKNOWN"
1328- fields ["day" ] = day
1329- fields ["month" ] = month_names [int (month )] if month != "UNKNOWN" else "UNKNOWN"
1330- fields ["year" ] = year
1331- print ("%(doctag)s:%(name)s:%(company)s:%(email)s:%(country)s:%(docpages)s:%(month)s:%(year)s:%(day)s:" % fields )
1292+ field = field .strip ()
1293+ outfile .write ("%-24s: %s\n " % ( key , field .replace ("\\ " , "\\ \\ " ).replace ("'" , "\\ x27" )))
13321294 else :
1333- if opt_attributes :
1334- def outputkey (key , fields ):
1335- field = fields [key ]
1336- if "\n " in field :
1337- field = "\n " + field .rstrip ()
1338- else :
1339- field = field .strip ()
1340- outfile .write ("%-24s: %s\n " % ( key , field .replace ("\\ " , "\\ \\ " ).replace ("'" , "\\ x27" )))
1341- else :
1342- def outputkey (key , fields ):
1343- outfile .write (" %s='%s'" % ( key .lower (), fields [key ].strip ().replace ("\\ " , "\\ \\ " ).replace ("'" , "\\ x27" ).replace ("\n " , "\\ n" )))
1344- if opt_timestamp :
1345- outfile .write ("%s " % (fields ["eventdate" ]))
1346- outfile .write ("%s" % (os .path .basename (docname .strip ())))
1347-
1348- keys = list (fields .keys ())
1349- keys .sort ()
1350- for key in keys :
1351- if fields [key ] and not key in ["eventdate" , ] and not key .startswith ("_" ):
1352- outputkey (key , fields )
1353- outfile .write ("\n " )
1295+ def outputkey (key , fields ):
1296+ outfile .write (" %s='%s'" % ( key .lower (), fields [key ].strip ().replace ("\\ " , "\\ \\ " ).replace ("'" , "\\ x27" ).replace ("\n " , "\\ n" )))
1297+ if opt_timestamp :
1298+ outfile .write ("%s " % (fields ["eventdate" ]))
1299+ outfile .write ("%s" % (os .path .basename (docname .strip ())))
1300+
1301+ keys = list (fields .keys ())
1302+ keys .sort ()
1303+ for key in keys :
1304+ if fields [key ] and not key in ["eventdate" , ] and not key .startswith ("_" ):
1305+ outputkey (key , fields )
1306+ outfile .write ("\n " )
13541307
13551308# ----------------------------------------------------------------------
13561309def _printmeta (fn , outfile = sys .stdout ):
@@ -1371,7 +1324,7 @@ def _printmeta(fn, outfile=sys.stdout):
13711324
13721325company_domain = {} # type: Dict[str, str]
13731326def _main (outfile = sys .stdout ):
1374- global opt_debug , opt_timestamp , opt_trace , opt_authorinfo , opt_getauthors , files , company_domain , opt_attributes
1327+ global opt_debug , opt_timestamp , opt_trace , opt_authorinfo , files , company_domain , opt_attributes
13751328 # set default values, if any
13761329 # ----------------------------------------------------------------------
13771330 # Option processing
@@ -1408,8 +1361,6 @@ def _main(outfile=sys.stdout):
14081361 elif opt in ["-v" , "--version" ]: # Output version information, then exit
14091362 print (program , version )
14101363 sys .exit (0 )
1411- elif opt in ["--getauthors" ]: # Output an (incomplete) getauthors-compatible format
1412- opt_getauthors = True
14131364 elif opt in ["-a" , "--attribs" ]: # Output key-value attribute pairs
14141365 opt_attributes = True
14151366 elif opt in ["-t" , ]: # Toggle leading timestamp information
@@ -1422,15 +1373,7 @@ def _main(outfile=sys.stdout):
14221373 opt_trace = True
14231374
14241375 company_domain = {}
1425- if opt_getauthors :
1426- gadata = io .open ("/www/tools.ietf.org/tools/getauthors/getauthors.data" )
1427- for line in gadata :
1428- if line .startswith ("company:" ):
1429- try :
1430- kword , name , abbrev = line .strip ().split (':' )
1431- company_domain [name ] = abbrev
1432- except ValueError :
1433- pass
1376+
14341377 if not files :
14351378 files = [ "-" ]
14361379
0 commit comments