diff --git a/debpackager/main.py b/debpackager/main.py index 158dc13..622acc8 100644 --- a/debpackager/main.py +++ b/debpackager/main.py @@ -8,7 +8,7 @@ from debpackager.utils.pom import Pom from debpackager.conf.log_conf import LOG_CONF -__version__ = '0.1.1' +__version__ = '0.1.2' logger = logging.getLogger(__name__) @@ -56,8 +56,6 @@ def main(): def parse_arguments(): - types = ['python', 'general'] - parser = argparse.ArgumentParser(description= 'cli tool for creating debians', add_help=False) @@ -86,7 +84,6 @@ def parse_arguments(): metavar='', dest='project_type', action='store', - choices=types, help='set project type, default: auto detect') build.add_argument('-p', '--path', metavar='', dest='project_path', action='store', default=os.getcwd(), diff --git a/debpackager/packages/general_package.py b/debpackager/packages/general_package.py index 537f14f..1dd72b2 100644 --- a/debpackager/packages/general_package.py +++ b/debpackager/packages/general_package.py @@ -76,6 +76,7 @@ def _create_debians(self): package_version=self.new_version, install_path=deb.get('install_path'), dependencies=deb_dependencies, + description=deb.get('description'), excludes=project.get('excludes', [])) build_dir = dpm.build() diff --git a/debpackager/tests/packages/test_general.py b/debpackager/tests/packages/test_general.py index 42072a2..2ecf527 100644 --- a/debpackager/tests/packages/test_general.py +++ b/debpackager/tests/packages/test_general.py @@ -69,3 +69,42 @@ def test_build_with_exclude(self): result = os.popen('dpkg -c test-proj_0.1.0_all.deb').read() assert 'folderA' in result assert 'folderB' not in result + + def test_build_with_description(self): + with open(self.tmp_dir + '/' + 'project.json', 'r') as pjf: + j = json.loads(pjf.read()) + j['debians'][0]['description'] = 'test description package' + with open(self.tmp_dir + '/' + 'project.json', 'w') as tkw: + tkw.write(json.dumps(j)) + + pom = Pom(project_path=self.tmp_dir) + gp = General({'project_path': self.tmp_dir, + 'project_type': 'general', + 'pom': pom}) + gp.build() + result = os.popen('dpkg -I test-proj_0.1.0_all.deb').read() + assert 'Description: test description package' in result + + def test_build_without_description(self): + pom = Pom(project_path=self.tmp_dir) + gp = General({'project_path': self.tmp_dir, + 'project_type': 'general', + 'pom': pom}) + gp.build() + result = os.popen('dpkg -I test-proj_0.1.0_all.deb').read() + assert 'Description: test-proj Package' in result + + def test_build_with_long_description(self): + with open(self.tmp_dir + '/' + 'project.json', 'r') as pjf: + j = json.loads(pjf.read()) + j['debians'][0]['description'] = 'test description package' * 100 + with open(self.tmp_dir + '/' + 'project.json', 'w') as tkw: + tkw.write(json.dumps(j)) + + pom = Pom(project_path=self.tmp_dir) + gp = General({'project_path': self.tmp_dir, + 'project_type': 'general', + 'pom': pom}) + gp.build() + result = os.popen('dpkg -I test-proj_0.1.0_all.deb').read() + assert 'Description: test-proj Package' in result \ No newline at end of file diff --git a/debpackager/tests/utils/test_dpb.py b/debpackager/tests/utils/test_dpb.py index 6d8f4fd..e4a6286 100644 --- a/debpackager/tests/utils/test_dpb.py +++ b/debpackager/tests/utils/test_dpb.py @@ -143,3 +143,41 @@ def test_add_startup_script_no_deb_dir(self): init_file_path = self.dpb.debian_package_path + \ '/debian/ad-server.init' assert os.path.exists(init_file_path) is False + + def test_add_default_description(self): + """ test that description is added""" + self.dpb._dh_make() + self.dpb._add_description() + + control_file_path = self.dpb.debian_package_path + '/debian/control' + + description_string = 'Description: test-proj Package' + + with open(control_file_path, 'r') as inst_file: + assert description_string in inst_file.read() + + def test_add_too_long_description(self): + """ test that too long description is discarded""" + self.dpb._dh_make() + self.dpb.description = 'very long description' * 100 + self.dpb._add_description() + + control_file_path = self.dpb.debian_package_path + '/debian/control' + + description_string = 'Description: test-proj Package' + + with open(control_file_path, 'r') as inst_file: + assert description_string in inst_file.read() + + def test_custom_description(self): + """ test that custom description is added""" + self.dpb._dh_make() + self.dpb.description = 'custom description' + self.dpb._add_description() + + control_file_path = self.dpb.debian_package_path + '/debian/control' + + description_string = 'custom description' + + with open(control_file_path, 'r') as inst_file: + assert description_string in inst_file.read() diff --git a/debpackager/utils/debain_package_manager.py b/debpackager/utils/debain_package_manager.py index af79767..674e1cc 100644 --- a/debpackager/utils/debain_package_manager.py +++ b/debpackager/utils/debain_package_manager.py @@ -20,6 +20,7 @@ def __init__(self, project_path, package_version, install_path, dependencies=None, + description=None, excludes=None): self.project_path = project_path @@ -27,6 +28,7 @@ def __init__(self, project_path, self.package_version = package_version self.install_path = install_path self.dependencies = dependencies + self.description = description or '{} Package'.format(package_name) self.excludes = excludes or [] self.deb_setting_dir = os.path.join(self.project_path, cfg.PROJECT_DEBIAN_SETTINGS_DIR) @@ -45,6 +47,7 @@ def build(self): self._set_exclude() self._add_maintainer_scripts() self._add_startup_script() + self._add_description() run_command('dpkg-buildpackage -uc -us -tc -rfakeroot') os.chdir(self.project_path) @@ -79,7 +82,7 @@ def _create_install_file(self): def _add_deb_dependencies(self): """ adds deb dependencies to control file """ if self.dependencies: - debian_dependencies = self._dependencies_to_debian_format( + debian_dependencies = self.dependencies_to_debian_format( self.dependencies) dependencies_str = ', '.join(debian_dependencies) @@ -142,8 +145,18 @@ def _add_startup_script(self): return logger.warning('No start-up scrip was found') + def _add_description(self): + """ adds description to control file""" + if not self.description or not len(self.description) <= 60: + logger.warning('bad description, using default pattern') + self.description = '{} Package'.format(self.package_name) + + sh.sed('-i', r'/^Description/c\\Description: {}' + .format(self.description), + self.debian_package_path + '/debian/control').wait() + @staticmethod - def _dependencies_to_debian_format(dependencies): + def dependencies_to_debian_format(dependencies): """ reformat deb dependencies to format that debian can understand""" debian_dependencies = [] for deb_name in dependencies: