/usr/lib/python2.7/dist-packages/charmtools/generators/utils.py is in charm-tools 2.1.2-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | #!/usr/bin/python
# Copyright (C) 2014 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
import os
import socket
import textwrap
import pkg_resources
log = logging.getLogger(__name__)
def get_installed_templates():
for ep in pkg_resources.iter_entry_points('charmtools.templates'):
yield ep.name
def apt_fill(package):
v = {}
try:
import apt
c = apt.Cache()
c.open()
p = c[package]
log.info(
"Found %s in apt cache; charm contents have been pre-populated "
"from package metadata.", package)
# summary and description attrs moved to Version
# object in python-apt 0.7.9
if not hasattr(p, 'summary'):
p = p.versions[0]
v['summary'] = p.summary
v['description'] = textwrap.fill(p.description, width=72,
subsequent_indent=' ')
except:
log.info(
"No %s in apt cache; creating an empty charm instead.", package)
v['summary'] = '<Fill in summary here>'
v['description'] = '<Multi-line description here>'
return v
def portable_get_maintainer():
""" Portable best effort to determine a maintainer """
if 'NAME' in os.environ:
name = os.environ['NAME']
else:
try:
import pwd
name = pwd.getpwuid(os.getuid()).pw_gecos.split(',')[0].strip()
if not len(name):
name = pwd.getpwuid(os.getuid())[0]
except:
name = 'Your Name'
if not len(name):
name = 'Your Name'
email = os.environ.get('EMAIL', '%s@%s' % (name.replace(' ', '.'),
socket.getfqdn()))
return name, email
|