Merge lp:~dholbach/developer-ubuntu-com/1510904 into lp:developer-ubuntu-com

Proposed by Daniel Holbach
Status: Merged
Approved by: David Callé
Approved revision: 160
Merged at revision: 161
Proposed branch: lp:~dholbach/developer-ubuntu-com/1510904
Merge into: lp:developer-ubuntu-com
Diff against target: 77 lines (+30/-8)
2 files modified
developer_portal/management/commands/import-external-docs-branches.py (+25/-7)
developer_portal/models.py (+5/-1)
To merge this branch: bzr merge lp:~dholbach/developer-ubuntu-com/1510904
Reviewer Review Type Date Requested Status
David Callé Pending
Michael Hall Pending
Ubuntu App Developer site developers Pending
Review via email: mp+276111@code.launchpad.net

Commit message

Let us import docs branches from git:// and lp: URLs.

Description of the change

Let us import docs branches from git:// and lp: URLs.

As test-data use:

sqlite> select * from developer_portal_externaldocsbranch;
1|git://github.com/ubuntu-core/snapcraft|snappy/build-apps|intro.md
2|lp:snappy/15.04|snappy/guides/current|
3|git://github.com/ubuntu-core/snappy|snappy/guides/devel|
sqlite>

To post a comment you must log in.
Revision history for this message
Daniel Holbach (dholbach) wrote :

Oh, and we should ensure that git is available in staging and prod.

159. By Daniel Holbach

fail gracefully if bzr or git are not installed

Revision history for this message
David Callé (davidc3) :
160. By Daniel Holbach

fix URL, thanks for pointing it out David Callé

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'developer_portal/management/commands/import-external-docs-branches.py'
--- developer_portal/management/commands/import-external-docs-branches.py 2015-10-29 14:50:24 +0000
+++ developer_portal/management/commands/import-external-docs-branches.py 2015-10-30 08:50:39 +0000
@@ -151,11 +151,6 @@
151 return os.path.basename(filename).replace('.md', '')151 return os.path.basename(filename).replace('.md', '')
152152
153153
154def get_branch_from_lp(origin, alias):
155 return subprocess.call([
156 'bzr', 'checkout', '--lightweight', origin, alias])
157
158
159class LocalBranch:154class LocalBranch:
160 titles = {}155 titles = {}
161156
@@ -307,10 +302,12 @@
307 docs_namespace__regex=selection):302 docs_namespace__regex=selection):
308 checkout_location = os.path.join(303 checkout_location = os.path.join(
309 tempdir, os.path.basename(branch.docs_namespace))304 tempdir, os.path.basename(branch.docs_namespace))
310 if get_branch_from_lp(branch.lp_origin, checkout_location) != 0:305 sourcecode = SourceCode(branch.lp_origin, checkout_location)
306 if sourcecode.get() != 0:
311 logging.error(307 logging.error(
312 'Could not check out branch "%s".' % branch.lp_origin)308 'Could not check out branch "%s".' % branch.lp_origin)
313 shutil.rmtree(checkout_location)309 if os.path.exists(checkout_location):
310 shutil.rmtree(checkout_location)
314 break311 break
315 if branch.lp_origin.startswith('lp:snappy'):312 if branch.lp_origin.startswith('lp:snappy'):
316 local_branch = SnappyLocalBranch(checkout_location, branch,313 local_branch = SnappyLocalBranch(checkout_location, branch,
@@ -324,6 +321,27 @@
324 db_actions.run()321 db_actions.run()
325322
326323
324class SourceCode():
325 def __init__(self, branch_origin, checkout_location):
326 self.branch_origin = branch_origin
327 self.checkout_location = checkout_location
328
329 def get(self):
330 if self.branch_origin.startswith('lp:') and \
331 os.path.exists('/usr/bin/bzr'):
332 return subprocess.call([
333 'bzr', 'checkout', '--lightweight', self.branch_origin,
334 self.checkout_location])
335 if self.branch_origin.startswith('git://') and \
336 os.path.exists('/usr/bin/git'):
337 return subprocess.call([
338 'git', 'clone', '-q', self.branch_origin,
339 self.checkout_location])
340 logging.error(
341 'Branch format "{}" not understood.'.format(self.branch_origin))
342 return 1
343
344
327class Command(BaseCommand):345class Command(BaseCommand):
328 help = "Import external branches for documentation."346 help = "Import external branches for documentation."
329347
330348
=== modified file 'developer_portal/models.py'
--- developer_portal/models.py 2015-10-21 14:41:23 +0000
+++ developer_portal/models.py 2015-10-30 08:50:39 +0000
@@ -21,9 +21,13 @@
2121
2222
23class ExternalDocsBranch(models.Model):23class ExternalDocsBranch(models.Model):
24 # We originally assumed that branches would also live in LP,
25 # well, we were wrong, but let's keep the name around. It's
26 # no use having a schema/data migration just for this.
24 lp_origin = models.CharField(27 lp_origin = models.CharField(
25 max_length=200,28 max_length=200,
26 help_text=_('Launchpad branch location, ie: lp:snappy/15.04'))29 help_text=_('External branch location, ie: lp:snappy/15.04 or '
30 'git://github.com/ubuntu-core/snappy'))
27 docs_namespace = models.CharField(31 docs_namespace = models.CharField(
28 max_length=120,32 max_length=120,
29 help_text=_('Path alias we want to use for the docs, '33 help_text=_('Path alias we want to use for the docs, '

Subscribers

People subscribed via source and target branches