utils.py
Go to the documentation of this file.
00001 ##############################################################################
00002 # Utilities
00003 ##############################################################################
00004 
00005 def author_name():
00006     """
00007     Utility to compute logged in user name
00008     
00009     :returns: name of current user, ``str``
00010     """
00011     import getpass
00012     name = getpass.getuser()
00013     try:
00014         import pwd
00015         login = name
00016         name = pwd.getpwnam(login)[4]
00017         name = ''.join(name.split(',')) # strip commas
00018         # in case pwnam is not set
00019         if not name:
00020             name = login
00021     except:
00022         #pwd failed
00023         pass
00024     if type(name) == str:
00025         name = name.decode('utf-8')
00026     return name
00027 
00028 # Finds and reads one of the templates.
00029 def read_template(tmplf):
00030     f = open(tmplf, 'r')
00031     try:
00032         t = f.read()
00033     finally:
00034         f.close()
00035     return t
00036 
00037 # This inserts the labelled variables into the template wherever the corresponding
00038 # %package, %brief, %description and %depends is found.
00039 def instantiate_template(template, package, description, author, depends):
00040     return template%locals()


qt_create
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 22:05:36