ATLAS Offline Software
Classes | Functions | Variables
python.scripts.gen_klass Namespace Reference

Classes

class  GenTypes
 
class  Templates
 

Functions

def gen_files (pkg="", klass="", klass_type='object', fname='foo', ipkg="", iklass="")
 
def gen_pyfiles (pkg="", klass="", klass_type='pyalg', fname='foo')
 
def main (args)
 

Variables

 __author__
 
 __doc__
 

Function Documentation

◆ gen_files()

def python.scripts.gen_klass.gen_files (   pkg = "",
  klass = "",
  klass_type = 'object',
  fname = 'foo',
  ipkg = "",
  iklass = "" 
)
Simple helper function to generate files based off some informations
 @param pkg the name of the package holding the class we want to generate
 @param klass the (fully qualified) name of the C++ class to generate
 @param klass_type the type of class to generate (svc/tool/alg/object)
 @param fname the filename to generate
 @param ipkg the name of the package holding the interface of the class
 @param iklass the name of the interface of the class we generate

Definition at line 537 of file gen_klass.py.

537 def gen_files(pkg="", klass="", klass_type='object', fname='foo',
538  ipkg="", iklass=""):
539  """Simple helper function to generate files based off some informations
540  @param pkg the name of the package holding the class we want to generate
541  @param klass the (fully qualified) name of the C++ class to generate
542  @param klass_type the type of class to generate (svc/tool/alg/object)
543  @param fname the filename to generate
544  @param ipkg the name of the package holding the interface of the class
545  @param iklass the name of the interface of the class we generate
546  """
547  try:
548  hdr = getattr(Templates, '%s_hdr_template'%klass_type)
549  cxx = getattr(Templates, '%s_cxx_template'%klass_type)
550  except AttributeError as err:
551  print ("::: UNKNOWN klass_type [%s] !" % klass_type)
552  raise err
553 
554  namespace_klass = klass.replace('::','_')
555  namespace_begin,namespace_end = "",""
556  if klass.count("::")>0:
557  nm = klass.split("::")[0]
558  klass = klass.split("::")[1]
559  namespace_begin = os.linesep + "namespace %s {" % nm + os.linesep
560  namespace_end = os.linesep + "} // namespace %s" % nm + os.linesep
561  pass
562 
563  guard = "%s_%s_H" % (pkg.upper(), namespace_klass.upper())
564 
565  d = dict( pkg=pkg,
566  klass=klass,
567  ipkg=ipkg,
568  iklass=iklass,
569  guard=guard,
570  namespace_begin=namespace_begin,
571  namespace_end=namespace_end,
572  copyright=Templates.copyright_template
573  )
574  fname = os.path.splitext(fname)[0]
575 
576  o_hdr = open(fname+'.h', 'w')
577  o_hdr.writelines(hdr%d)
578  o_hdr.flush()
579  o_hdr.close()
580 
581  if len(cxx)>0:
582  o_cxx = open(fname+'.cxx', 'w')
583  o_cxx.writelines(cxx%d)
584  o_cxx.flush()
585  o_cxx.close()
586 
587  return 0
588 
589 

◆ gen_pyfiles()

def python.scripts.gen_klass.gen_pyfiles (   pkg = "",
  klass = "",
  klass_type = 'pyalg',
  fname = 'foo' 
)
Simple helper function to generate (python) files based off some
   user informations.
 @param pkg the name of the package holding the class we want to generate
 @param klass the name of the python class to generate
 @param klass_type the type of class to generate (pysvc/pytool/pyalg/pyaud)
 @param fname the filename to generate

Definition at line 590 of file gen_klass.py.

590 def gen_pyfiles(pkg="", klass="", klass_type='pyalg', fname='foo'):
591  """Simple helper function to generate (python) files based off some
592  user informations.
593  @param pkg the name of the package holding the class we want to generate
594  @param klass the name of the python class to generate
595  @param klass_type the type of class to generate (pysvc/pytool/pyalg/pyaud)
596  @param fname the filename to generate
597  """
598  try:
599  py_template = getattr(Templates, '%s_template'%klass_type)
600  except AttributeError as err:
601  print ("::: UNKNOWN klass_type [%s] !" % klass_type)
602  raise err
603 
604  invalid_py_chars = ( ':', '.', '>', '<', ' ' )
605 
606  if any([c for c in invalid_py_chars if c in klass]):
607  err = "::: INVALID class name ! (%s) !\n"%klass
608  err += "::: python class names can *NOT* contain any character of %s"%\
609  repr(invalid_py_chars)
610  print (err)
611  raise RuntimeError(err)
612 
613  fname=''.join([fname,'.py'])
614  d = dict( pkg=pkg,
615  klass=klass,
616  fname=fname,
617  copyright=Templates.copyright_template
618  )
619  o = open(fname, 'w')
620  o.writelines(py_template%d)
621  o.flush()
622  o.close()
623  return 0
624 
625 @acmdlib.command(name='gen-klass')
626 @acmdlib.argument(
627  "--klass",
628  required=True,
629  help = "The (fully qualified) name of the python or C++ class to create (ex: ElectronContainer, Analysis::Electron, MyAlgTool, PyTestAlg)")
630 @acmdlib.argument(
631  "--pkg",
632  required=True,
633  help = "The name of the package holding the C++ class to create (ex: MyAnalysis, JetEvent)")
634 @acmdlib.argument(
635  "--type",
636  dest = "klass_type",
637  required=True,
638  choices = GenTypes.values,
639  help = "The type of class to create")
640 @acmdlib.argument(
641  "--ipkg",
642  default = None,
643  help = "The name of the package holding the interface of the C++ class (mandatory for 'svc' and 'tool' types)")
644 @acmdlib.argument(
645  "--iklass",
646  default = None,
647  help = "The name of the interface the C++ class is implementing (mandatory for 'svc' and 'tool' types)")
648 @acmdlib.argument(
649  "-o",
650  "--output-file",
651  required=True,
652  dest = "fname",
653  help = "The name of the file(s) which will hold header and implementation of the class (ex: 'Foo' --> ('Foo.h','Foo.cxx'))")

◆ main()

def python.scripts.gen_klass.main (   args)
helper script to generate header and cxx files
of various athena components (svc/tool/alg/isvc/itool/object)

Definition at line 654 of file gen_klass.py.

654 def main(args):
655  """helper script to generate header and cxx files
656  of various athena components (svc/tool/alg/isvc/itool/object)
657  """
658 
659  exitcode = 0
660 
661  if args.klass_type in GenTypes.needing_iface and \
662  ( args.ipkg is None or args.iklass is None ) :
663  print (":: You have to give 'ipkg' and 'iklass' options to properly ",)
664  print ("generate an implementation for '%s'"%args.klass_type)
665  return 3
666 
667 
668  if args.ipkg is None:
669  args.ipkg = ""
670 
671  if args.iklass is None:
672  args.iklass = ""
673 
674  if args.klass_type.startswith('py'):
675  exitcode = gen_pyfiles(
676  klass=args.klass,
677  klass_type=args.klass_type,
678  pkg=args.pkg,
679  fname=args.fname
680  )
681  else:
682  exitcode = gen_files(
683  klass=args.klass,
684  klass_type=args.klass_type,
685  pkg=args.pkg,
686  iklass=args.iklass,
687  ipkg=args.ipkg,
688  fname=args.fname
689  )
690  return exitcode

Variable Documentation

◆ __author__

python.scripts.gen_klass.__author__
private

Definition at line 13 of file gen_klass.py.

◆ __doc__

python.scripts.gen_klass.__doc__
private

Definition at line 14 of file gen_klass.py.

python.scripts.gen_klass.gen_files
def gen_files(pkg="", klass="", klass_type='object', fname='foo', ipkg="", iklass="")
Definition: gen_klass.py:537
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
python.scripts.gen_klass.gen_pyfiles
def gen_pyfiles(pkg="", klass="", klass_type='pyalg', fname='foo')
Definition: gen_klass.py:590
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
Trk::open
@ open
Definition: BinningType.h:40
python.scripts.gen_klass.main
def main(args)
Definition: gen_klass.py:654