def testGenerateChangelogFile(self): """Tests the _GenerateChangelogFile function.""" project_definition = projects.ProjectDefinition('test') dpkg_files_generator = dpkg_files.DPKGBuildFilesGenerator( project_definition, '1.0', 'data_path', {}) _ = dpkg_files_generator
def _CreatePackagingFiles(self, source_directory, project_version): """Creates packaging files. Args: source_directory (str): name of the source directory. project_version (str): project version. Returns: bool: True if successful, False otherwise. """ debian_directory = os.path.join(source_directory, 'debian') # If there is a debian directory remove it and recreate it from # the dpkg directory. if os.path.exists(debian_directory): logging.info('Removing: {0:s}'.format(debian_directory)) shutil.rmtree(debian_directory) dpkg_directory = os.path.join(source_directory, 'dpkg') if not os.path.exists(dpkg_directory): dpkg_directory = os.path.join(source_directory, 'config', 'dpkg') if os.path.exists(dpkg_directory): shutil.copytree(dpkg_directory, debian_directory) self._RewriteControlFile(debian_directory) else: build_configuration = self._DetermineBuildConfiguration(source_directory) # pylint: disable=assignment-from-none os.chdir(source_directory) try: build_files_generator = dpkg_files.DPKGBuildFilesGenerator( self._project_definition, project_version, self._data_path, self._dependency_definitions, build_configuration=build_configuration) build_files_generator.GenerateFiles('debian') finally: os.chdir('..') if not os.path.exists(debian_directory): logging.error('Missing debian sub directory in: {0:s}'.format( source_directory)) return False return True
def _CreatePackagingFiles(self, source_helper_object, source_directory, project_version): """Creates packaging files. Args: source_helper_object (SourceHelper): source helper. source_directory (str): name of the source directory. project_version (str): project version. Returns: bool: True if successful, False otherwise. """ debian_directory = os.path.join(source_directory, 'debian') # If there is a debian directory remove it and recreate it from # the dpkg directory. if os.path.exists(debian_directory): logging.info('Removing: {0:s}'.format(debian_directory)) shutil.rmtree(debian_directory) dpkg_directory = os.path.join(source_directory, 'dpkg') if not os.path.exists(dpkg_directory): dpkg_directory = os.path.join(source_directory, 'config', 'dpkg') if os.path.exists(dpkg_directory): shutil.copytree(dpkg_directory, debian_directory) else: os.chdir(source_directory) build_files_generator = dpkg_files.DPKGBuildFilesGenerator( source_helper_object.project_name, project_version, self._project_definition, self._data_path) build_files_generator.GenerateFiles('debian') os.chdir('..') if not os.path.exists(debian_directory): logging.error('Missing debian sub directory in: {0:s}'.format( source_directory)) return False return True
def testGenerateChangelogFile(self): """Tests the _GenerateChangelogFile function.""" dpkg_files_generator = dpkg_files.DPKGBuildFilesGenerator( 'test', '1.0', None, '') _ = dpkg_files_generator
def Main(): """The main program function. Returns: bool: True if successful or False if not. """ argument_parser = argparse.ArgumentParser( description=('Generates dpkg packaging files for a project.')) argument_parser.add_argument( 'project_name', action='store', metavar='NAME', type=str, help=('Project name for which the dpkg packaging files should be ' 'generated.')) argument_parser.add_argument('-c', '--config', dest='config_file', action='store', metavar='CONFIG_FILE', default=None, help='path of the build configuration file.') argument_parser.add_argument( '--source-directory', '--source_directory', action='store', metavar='DIRECTORY', dest='source_directory', type=str, default=None, help='The location of the the source directory.') options = argument_parser.parse_args() logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(message)s') if not options.config_file: options.config_file = os.path.dirname(__file__) options.config_file = os.path.dirname(options.config_file) options.config_file = os.path.join(options.config_file, 'data', 'projects.ini') if not os.path.exists(options.config_file): print('No such config file: {0:s}.'.format(options.config_file)) print('') return False project_definition_match = None with open(options.config_file) as file_object: project_definition_reader = projects.ProjectDefinitionReader() for project_definition in project_definition_reader.Read(file_object): if options.project_name == project_definition.name: project_definition_match = project_definition if not project_definition_match: print('No such package name: {0:s}.'.format(options.project_name)) print('') return False source_path = options.source_directory if not source_path: globbed_paths = [] for path in glob.glob('{0:s}*'.format(options.project_name)): if not os.path.isdir(path): continue globbed_paths.append(path) if len(globbed_paths) != 1: print('Unable to determine source directory.') print('') return False source_path = globbed_paths[0] if not os.path.exists(source_path): print('No such source directory: {0:s}.'.format(source_path)) print('') return False source_path = os.path.abspath(source_path) project_version = os.path.basename(source_path) if not project_version.startswith('{0:s}-'.format(options.project_name)): print(('Unable to determine project version based on source ' 'directory: {0:s}.').format(source_path)) print('') return False _, _, project_version = project_version.partition('-') dpkg_path = os.path.join(source_path, 'dpkg') if os.path.exists(dpkg_path): print('Destination dpkg directory: {0:s} already exists.'.format( dpkg_path)) print('') return False tools_path = os.path.dirname(__file__) data_path = os.path.join(os.path.dirname(tools_path), 'data') build_files_generator = dpkg_files.DPKGBuildFilesGenerator( options.project_name, project_version, project_definition_match, data_path) print('Generating dpkg files for: {0:s} {1:s} in: {2:s}'.format( options.project_name, project_version, dpkg_path)) build_files_generator.GenerateFiles(dpkg_path) print('') return True