Ejemplo n.º 1
0
	def _create_new_repo(self, args):
		if not args.ini or not os.path.exists(args.ini):
			raise LocalAppCenterError('An ini file is needed for new apps')
		app = App.from_ini(args.ini)
		if not app:
			raise LocalAppCenterError('Cannot continue with flawed ini file')
		if args.component_id:
			component_id = args.component_id
		else:
			component_id = '%s_%s' % (app.id, date.today().strftime('%Y%m%d'))
		return self._build_repo_dir(app, component_id, args.path, args.ucs_version)
Ejemplo n.º 2
0
 def set_ini_value(self, section, attr, value, parser):
     if not re.match('^[a-zA-Z0-9_]+$', attr):
         raise LocalAppCenterError('May not use %s as attribute' % attr)
     try:
         items = parser.items(section)
     except NoSectionError:
         items = []
     for name, old_value in items:
         if attr.lower() == name.lower():
             if attr != name:
                 self.warn('Using %s instead of %s as attribute' %
                           (name, attr))
                 attr = name
             self.log('%s: Overwriting %r' % (attr, old_value))
     self.debug('Setting [%s]%s=%r' % (section, attr, value))
     if value is None:
         try:
             parser.remove_option(section, attr)
         except NoSectionError:
             pass
     else:
         try:
             parser.add_section(section)
         except DuplicateSectionError:
             pass
         except ValueError:
             section = 'DEFAULT'
         parser.set(section, attr, value)
Ejemplo n.º 3
0
 def main(self, args):
     if args.meta:
         ini_file = args.app.get_cache_file('meta')
     else:
         ini_file = args.app.get_ini_file()
     parser = read_ini_file(ini_file, CaseSensitiveConfigParser)
     for section, attr, value in args.attrs:
         attribute = args.app.get_attr(underscore(attr))
         self.process(args.app, attribute, section, camelcase(attr), value,
                      parser)
     self.log('Rewriting %s' % ini_file)
     with NamedTemporaryFile('w+b') as tmp_ini_file:
         parser.write(tmp_ini_file)
         tmp_ini_file.flush()
         if not args.meta:
             for locale in ['en', 'de']:
                 new_app = App.from_ini(tmp_ini_file.name,
                                        locale=locale,
                                        cache=args.app.get_app_cache_obj())
                 if new_app is None:
                     raise LocalAppCenterError(
                         'ini file would be malformed. Not saving attributes!'
                     )
         shutil.copy2(tmp_ini_file.name, ini_file)
         os.chmod(ini_file, 0o644)
         args.app.get_app_cache_obj().clear_cache()
Ejemplo n.º 4
0
 def main(self, args):
     component_id = args.component_id
     app_id = None
     if args.new:
         component_id, app_id = self._create_new_repo(args)
     meta_inf_dir = os.path.join(args.path, 'meta-inf', args.ucs_version)
     if LooseVersion(args.ucs_version) >= '4.1':
         if app_id is None:
             if args.ini:
                 ini_file = args.ini
             else:
                 for root, dirnames, filenames in os.walk(meta_inf_dir):
                     for filename in filenames:
                         if filename == '%s.ini' % component_id:
                             ini_file = os.path.join(root, filename)
                             break
                     else:
                         continue
                     break
                 else:
                     raise LocalAppCenterError(
                         'Could not determine app id. Specify an --ini file!'
                     )
             app = App.from_ini(ini_file)
             app_id = app.id
         meta_inf_dir = os.path.join(meta_inf_dir, app_id)
     mkdir(meta_inf_dir)
     repo_dir = os.path.join(args.path, 'univention-repository',
                             args.ucs_version, 'maintained', 'component',
                             component_id)
     mkdir(repo_dir)
     if args.unmaintained:
         version = ucr_get('version/version')
         if args.ucs_version != version:
             self.fatal(
                 'Cannot easily set up unmaintained packages for %s (need %s). You need to download them into the repository manually. Sorry!'
                 % (args.ucs_version, version))
         else:
             self._copy_unmaintained_packages(repo_dir, args)
     app = self._copy_meta_files(component_id, meta_inf_dir, repo_dir, args)
     if app and args.packages:
         self._handle_packages(app, repo_dir, args)
         self._generate_repo_index_files(repo_dir)
     self._generate_meta_index_files(args)
     self.log('Component is: %s' % component_id)
Ejemplo n.º 5
0
 def _copy_meta_files(self, component_id, meta_inf_dir, repo_dir, args):
     ini_file = os.path.join(meta_inf_dir, '%s.ini' % component_id)
     if args.clear:
         if os.path.exists(repo_dir):
             rmdir(repo_dir)
         if os.path.exists(ini_file):
             os.unlink(ini_file)
     if args.ini:
         self.copy_file(args.ini, ini_file)
     if not os.path.exists(ini_file):
         self.warn('Stopping here due to no ini file')
         return
     app_en = App.from_ini(ini_file, 'en')
     app_de = App.from_ini(ini_file, 'de')
     if args.clear:
         self._build_repo_dir(app_en, component_id, args.path,
                              args.ucs_version)
     if not app_en or not app_de:
         raise LocalAppCenterError('Cannot continue with flawed ini file')
     if args.logo:
         if LooseVersion(args.ucs_version) >= '4.1':
             parser = ConfigParser()
             parser.read(ini_file)
             try:
                 logo_fname = parser.get('Application', 'Logo')
             except NoOptionError:
                 self.fatal('No Logo specified in ini file!')
             else:
                 self.copy_file(args.logo,
                                os.path.join(meta_inf_dir, logo_fname))
         else:
             self.copy_file(
                 args.logo,
                 os.path.join(meta_inf_dir, '%s.png' % component_id))
     if args.logo_detail_page:
         parser = ConfigParser()
         parser.read(ini_file)
         try:
             logo_detail_fname = parser.get('Application', 'LogoDetailPage')
         except NoOptionError:
             self.fatal('No Logo specified in ini file!')
         self.copy_file(args.logo_detail_page,
                        os.path.join(meta_inf_dir, logo_detail_fname))
     if args.screenshot:
         self.copy_file(args.screenshot[0],
                        os.path.join(meta_inf_dir, app_en.screenshot))
         if len(args.screenshot) > 1:
             self.copy_file(args.screenshot[1],
                            os.path.join(meta_inf_dir, app_de.screenshot))
     if args.thumbnails:
         thumbnails = []
         for thumbnail in app_en.thumbnails + app_de.thumbnails:
             if thumbnail in thumbnails:
                 continue
             if thumbnail.startswith('http'):
                 continue
             thumbnails.append(thumbnail)
         for i, thumbnail in enumerate(args.thumbnails):
             try:
                 self.copy_file(thumbnail,
                                os.path.join(meta_inf_dir, thumbnails[i]))
             except IndexError:
                 raise LocalAppCenterError(
                     'The ini file must state as much Thumbnails= as --thumbnails are given'
                 )
     if args.readme:
         for readme in args.readme:
             self.copy_file(readme, repo_dir)
     if args.license:
         for license in args.license:
             self.copy_file(license, repo_dir)
     if args.ucr:
         self.copy_file(
             args.ucr,
             os.path.join(repo_dir, 'univention-config-registry-variables'))
     if args.schema:
         self.copy_file(args.schema, os.path.join(repo_dir, 'schema'))
     if args.attributes:
         self.copy_file(args.attributes,
                        os.path.join(repo_dir, 'attributes'))
     if args.configure:
         self.copy_file(args.configure, os.path.join(repo_dir, 'configure'))
     if args.configure_host:
         self.copy_file(args.configure_host,
                        os.path.join(repo_dir, 'configure_host'))
     if args.settings:
         self.copy_file(args.settings, os.path.join(repo_dir, 'settings'))
     if args.preinst:
         self.copy_file(args.preinst, os.path.join(repo_dir, 'preinst'))
     if args.join:
         self.copy_file(args.join, os.path.join(repo_dir, 'inst'))
     if args.prerm:
         self.copy_file(args.prerm, os.path.join(repo_dir, 'prerm'))
     if args.unjoin:
         self.copy_file(args.unjoin, os.path.join(repo_dir, 'uinst'))
     if args.setup:
         self.copy_file(args.setup, os.path.join(repo_dir, 'setup'))
     if args.store_data:
         self.copy_file(args.store_data,
                        os.path.join(repo_dir, 'store_data'))
     if args.restore_data_before_setup:
         self.copy_file(args.restore_data_before_setup,
                        os.path.join(repo_dir, 'restore_data_before_setup'))
     if args.restore_data_after_setup:
         self.copy_file(args.restore_data_after_setup,
                        os.path.join(repo_dir, 'restore_data_after_setup'))
     if args.update_available:
         self.copy_file(args.update_available,
                        os.path.join(repo_dir, 'update_available'))
     if args.update_packages:
         self.copy_file(args.update_packages,
                        os.path.join(repo_dir, 'update_packages'))
     if args.update_release:
         self.copy_file(args.update_release,
                        os.path.join(repo_dir, 'update_release'))
     if args.update_app_version:
         self.copy_file(args.update_app_version,
                        os.path.join(repo_dir, 'update_app_version'))
     if args.env:
         self.copy_file(args.env, os.path.join(repo_dir, 'env'))
     return app_en