Skip to content

Commit

Permalink
Merge pull request #3 from moreonion/patched-d.o
Browse files Browse the repository at this point in the history
Allow patched drupal.org projects.
  • Loading branch information
torotil authored Apr 29, 2017
2 parents c522c49 + 55f7de3 commit b81b14d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: python
python:
- "3.4"
install: python setup.py install
script: py.test
42 changes: 33 additions & 9 deletions drupy/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,19 +444,43 @@ def convertToMake(self):


class DrupalOrgProject(Project):
url_pattern = 'https://ftp.drupal.org/files/projects/{}.tar.gz'
url_pattern = 'https://ftp.drupal.org/files/projects/{}-{}-{}.tar.gz'

def __init__(self, runner, config):
"""
Split dirname to see if this is a valid drupal.org package spec.
- Automatically prepends downloading the drupal.org package to the build
queue.
- Packages with a valid spect are detected as drupal.org packages even
if they don't declare config['type'] = 'drupal.org' explicitly.
"""
Project.__init__(self, runner, config)
parts = self.dirname.split('-', 2)
if len(parts) == 3:
self.project, core, self.version = parts
project_build = {
'url': self.url_pattern.format(self.dirname),
}
try:
project, core, version, patches = self.split_project(self.dirname)
build = dict(url=self.url_pattern.format(project, core, version))
if 'hash' in self.config:
project_build['hash'] = self.config['hash']
self.pipeline.insert(0, project_build)
build['hash'] = self.config['hash']
self.pipeline.insert(0, build)
if self.type is None:
self.type = 'drupal.org'
except ValueError:
pass

@staticmethod
def split_project(name):
"""
Split a directory name into project, core-version, version and patches.
Patches should be separated from the main project string and one another
using a '+'.
"""
p = name.split('+')
name, extras = p[0], tuple(p[1:])
p = name.split('-', 2)
if len(p) != 3:
raise ValueError('Not in project format: "{}"'.format(name))
return p[0], p[1], p[2], extras

def isValid(self):
return self.type == 'drupal.org' and len(self.pipeline) >= 1
Expand Down
29 changes: 29 additions & 0 deletions tests/objects_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from unittest import TestCase

from drupy.objects import DrupalOrgProject


class DrupalOrgProjectTest(TestCase):

def test_split_project(self):
assert DrupalOrgProject.split_project('campaignion-7.x-1.5+pr32') == \
('campaignion', '7.x', '1.5', ('pr32', ))
assert DrupalOrgProject.split_project('campaignion-7.x-1.0-rc1') == \
('campaignion', '7.x', '1.0-rc1', tuple())

def test_is_valid(self):
# Valid package spec without declaring type.
p = DrupalOrgProject(None, dict(dirname='campaignion-7.x-1.0'))
assert p.isValid()

# Invalid package spec but declaring type.
p = DrupalOrgProject(None, dict(
dirname='testitt',
build=[{}],
type='drupal.org',
))
assert p.isValid()

# Invalid package spec without declaring type.
p = DrupalOrgProject(None, dict(dirname='testitt'))
assert not p.isValid()

0 comments on commit b81b14d

Please sign in to comment.