utils.py
Go to the documentation of this file.
1 ##############################################################################
2 # Utilities
3 ##############################################################################
4 
5 def author_name():
6  """
7  Utility to compute logged in user name
8 
9  :returns: name of current user, ``str``
10  """
11  import getpass
12  name = getpass.getuser()
13  try:
14  import pwd
15  login = name
16  name = pwd.getpwnam(login)[4]
17  name = ''.join(name.split(',')) # strip commas
18  # in case pwnam is not set
19  if not name:
20  name = login
21  except:
22  #pwd failed
23  pass
24  if type(name) == str:
25  name = name.decode('utf-8')
26  return name
27 
28 # Finds and reads one of the templates.
29 def read_template(tmplf):
30  f = open(tmplf, 'r')
31  try:
32  t = f.read()
33  finally:
34  f.close()
35  return t
36 
37 # This inserts the labelled variables into the template wherever the corresponding
38 # %package, %brief, %description and %depends is found.
39 def instantiate_template(template, package, description, author, depends):
40  return template%locals()
def read_template(tmplf)
Definition: utils.py:29
def author_name()
Utilities.
Definition: utils.py:5
def instantiate_template(template, package, description, author, depends)
Definition: utils.py:39


qt_create
Author(s): Daniel Stonier
autogenerated on Wed Mar 11 2020 03:12:19