Package elisa :: Package core :: Package utils :: Module dist
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.utils.dist

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 16   
 17  """ 
 18  Functions used to extend setuptools and add elisa specific metadata 
 19  when distributing plugins. 
 20  """ 
 21   
 22  __maintainer__ = 'Philippe Normand <philippe@fluendo.com>' 
 23   
 24  import os 
 25  import types 
 26  from elisa.core import config 
 27  from elisa.core.utils import i18n 
 28  from setuptools import find_packages 
 29  from distutils.errors import DistutilsSetupError, DistutilsOptionError 
 30  from distutils.core import Command 
 31   
32 -def write_dict(cmd, basename, filename, force=False):
33 """ 34 """ 35 argname = os.path.splitext(basename)[0] 36 arg_value = getattr(cmd.distribution, argname, None) 37 text_value = "" 38 if arg_value is not None: 39 for key, value in arg_value.iteritems(): 40 41 text_value += "%s = %s\n" % (key, value) 42 cmd.write_or_delete_file(argname, filename, text_value, force)
43
44 -def assert_dict_or_none(dist, attr, value):
45 """Verify that value is a dictionary""" 46 if type(value) not in (dict, types.NoneType): 47 raise DistutilsSetupError("%r must be a dictionary or None value. "\ 48 "Got %r" % (attr,value))
49
50 -def scan_plugin_conf(conf_path, name_prefix='elisa-plugin-'):
51 """ Read the config located at given path and return data suitable 52 to distutils' setup(). 53 54 @param conf_path: absolute or relative path to a plugin.conf file 55 @type conf_path: string 56 @param name_prefix: plugin's name prefix 57 @type name_prefix: string 58 @rtype: dict 59 """ 60 cfg = config.Config(conf_path) 61 section = cfg.get_section('general') 62 63 # Basic distutils supported keywords 64 name = section.get('name', default='unknown') 65 version = section.get('version', default='0.1') 66 description = section.get('description', default='no description') 67 long_description = section.get('long_description', default=description) 68 author = section.get('author', default='John Doe') 69 author_email = section.get('author_email', default='john@doe.com') 70 keywords = ','.join(section.get('keywords', default=[])) 71 license = section.get('license', default='UNKNOWN') 72 73 # Elisa specific metadata, to go in elisa_infos.txt 74 category_id = section.get('category_id', default='unknown') 75 plugin_deps = ','.join([d.strip() for d in 76 section.get('plugin_dependencies', default=[])]) 77 py_deps = section.get('external_dependencies', default=[]) 78 for component_path, component_config in cfg.as_dict().iteritems(): 79 if component_path == 'general': 80 continue 81 for dep in component_config.get('external_dependencies',[]): 82 dep = dep.strip() 83 if dep not in py_deps: 84 py_deps.append(dep) 85 86 py_deps = ','.join(py_deps) 87 ext_deps = '' 88 elisa_infos = {'plugin_deps': plugin_deps, 'py_deps': py_deps, 89 'ext_deps': ext_deps, 'category_id': category_id} 90 91 # Setuptools specific: entry_points keyword 92 package_path = os.path.split(os.path.dirname(conf_path)) 93 if package_path[0] in ('','.'): 94 package_path = package_path[1:] 95 package_path = os.path.sep.join(package_path).replace(os.path.sep, '.') 96 entry_points = {'elisa.plugins': ['%s = %s' % (name, package_path),]} 97 98 infos = {'name': '%s%s' % (name_prefix, name), 99 'description': description, 'license': license, 100 'keywords': keywords, 101 'version': version, 'long_description': long_description, 102 'author': author, 'author_email': author_email, 103 'elisa_infos': elisa_infos, 'packages': find_packages(), 104 'entry_points': entry_points} 105 return infos
106 107
108 -class build_po(Command):
109 """ 110 Read a set of Elisa translation files, compile po files existing 111 in the directories listed in those files and ship mo files as 112 package_data of the distribution. 113 114 Translation files have the following format:: 115 116 # 117 # domain path/to/input /path/to/output 118 # other-domain path/to/input/only 119 # 120 # 121 # Don't forget the empty line at the end! 122 123 """ 124 125 description = "compile Elisa translation file(s)" 126 127 user_options = [ 128 ('trans-files=', 't', 'Elisa translation files') 129 ] 130 131
132 - def initialize_options(self):
133 self.trans_files = []
134
135 - def finalize_options (self):
136 self.ensure_filename_list('trans_files') 137 if not self.trans_files: 138 self.trans_files = ['data/translations.lst',]
139
140 - def run(self):
141 mo_files = i18n.compile_translations_from_files(self.trans_files) 142 self.distribution.package_data.update(mo_files)
143
144 - def ensure_filename_list(self, option):
145 self.ensure_string_list(option) 146 for fname in getattr(self, option): 147 if not os.path.exists(fname): 148 msg = "'%s' does not exist or is not a file" % fname 149 raise DistutilsOptionError("error in '%s' option: %s" % (option, 150 msg))
151