Skip to content

Commit

Permalink
Merge pull request #3 from urban48/short_description_feature
Browse files Browse the repository at this point in the history
added support for adding a short description to the debain package
  • Loading branch information
urban48 authored Jul 15, 2016
2 parents 9e5536c + ef7e149 commit 72da6be
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
5 changes: 1 addition & 4 deletions debpackager/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -56,8 +56,6 @@ def main():

def parse_arguments():

types = ['python', 'general']

parser = argparse.ArgumentParser(description=
'cli tool for creating debians',
add_help=False)
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions debpackager/packages/general_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
39 changes: 39 additions & 0 deletions debpackager/tests/packages/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
38 changes: 38 additions & 0 deletions debpackager/tests/utils/test_dpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
17 changes: 15 additions & 2 deletions debpackager/utils/debain_package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ def __init__(self, project_path,
package_version,
install_path,
dependencies=None,
description=None,
excludes=None):

self.project_path = project_path
self.package_name = package_name
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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 72da6be

Please sign in to comment.