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

Proposed by Daniel Holbach on 2015-10-29
Status: Merged
Approved by: David Callé on 2015-10-30
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é 2015-10-29 Pending
Michael Hall 2015-10-29 Pending
Ubuntu App Developer site developers 2015-10-29 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.
Daniel Holbach (dholbach) wrote :

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

159. By Daniel Holbach on 2015-10-29

fail gracefully if bzr or git are not installed

David Callé (davidc3) :
160. By Daniel Holbach on 2015-10-30

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
1=== modified file 'developer_portal/management/commands/import-external-docs-branches.py'
2--- developer_portal/management/commands/import-external-docs-branches.py 2015-10-29 14:50:24 +0000
3+++ developer_portal/management/commands/import-external-docs-branches.py 2015-10-30 08:50:39 +0000
4@@ -151,11 +151,6 @@
5 return os.path.basename(filename).replace('.md', '')
6
7
8-def get_branch_from_lp(origin, alias):
9- return subprocess.call([
10- 'bzr', 'checkout', '--lightweight', origin, alias])
11-
12-
13 class LocalBranch:
14 titles = {}
15
16@@ -307,10 +302,12 @@
17 docs_namespace__regex=selection):
18 checkout_location = os.path.join(
19 tempdir, os.path.basename(branch.docs_namespace))
20- if get_branch_from_lp(branch.lp_origin, checkout_location) != 0:
21+ sourcecode = SourceCode(branch.lp_origin, checkout_location)
22+ if sourcecode.get() != 0:
23 logging.error(
24 'Could not check out branch "%s".' % branch.lp_origin)
25- shutil.rmtree(checkout_location)
26+ if os.path.exists(checkout_location):
27+ shutil.rmtree(checkout_location)
28 break
29 if branch.lp_origin.startswith('lp:snappy'):
30 local_branch = SnappyLocalBranch(checkout_location, branch,
31@@ -324,6 +321,27 @@
32 db_actions.run()
33
34
35+class SourceCode():
36+ def __init__(self, branch_origin, checkout_location):
37+ self.branch_origin = branch_origin
38+ self.checkout_location = checkout_location
39+
40+ def get(self):
41+ if self.branch_origin.startswith('lp:') and \
42+ os.path.exists('/usr/bin/bzr'):
43+ return subprocess.call([
44+ 'bzr', 'checkout', '--lightweight', self.branch_origin,
45+ self.checkout_location])
46+ if self.branch_origin.startswith('git://') and \
47+ os.path.exists('/usr/bin/git'):
48+ return subprocess.call([
49+ 'git', 'clone', '-q', self.branch_origin,
50+ self.checkout_location])
51+ logging.error(
52+ 'Branch format "{}" not understood.'.format(self.branch_origin))
53+ return 1
54+
55+
56 class Command(BaseCommand):
57 help = "Import external branches for documentation."
58
59
60=== modified file 'developer_portal/models.py'
61--- developer_portal/models.py 2015-10-21 14:41:23 +0000
62+++ developer_portal/models.py 2015-10-30 08:50:39 +0000
63@@ -21,9 +21,13 @@
64
65
66 class ExternalDocsBranch(models.Model):
67+ # We originally assumed that branches would also live in LP,
68+ # well, we were wrong, but let's keep the name around. It's
69+ # no use having a schema/data migration just for this.
70 lp_origin = models.CharField(
71 max_length=200,
72- help_text=_('Launchpad branch location, ie: lp:snappy/15.04'))
73+ help_text=_('External branch location, ie: lp:snappy/15.04 or '
74+ 'git://github.com/ubuntu-core/snappy'))
75 docs_namespace = models.CharField(
76 max_length=120,
77 help_text=_('Path alias we want to use for the docs, '

Subscribers

People subscribed via source and target branches