2 # -*- coding: utf-8 -*-
4 """ This script download the latest git version of e-cidadania, compiles
5 the documentation and places it in the documentation website
14 __author__
= "Oscar Carballal Prego"
17 __email__
= "oscar.carballal@cidadania.coop"
18 __status__
= "Stable/Production"
30 self
.cwd
= os
.getcwd()
31 self
.langs
= ["es", "en", "gl"]
32 self
.formats
= ["html", "latex", "latexpdf"]
34 # We don't include cidadania's server repository because it
35 # needs authentication and some specific settings.
37 "git://github.com/cidadania/e-cidadania.git",
38 "git://github.com/oscarcp/e-cidadania.git",
39 "git://gitorious.org/e-cidadania/mainline.git",
40 "git://repo.or.cz/e_cidadania.git",
43 def download_code(self
, branch
='master'):
46 Download the latest code from the e-cidadania repositories. It the
47 clone fails it will try with the next repository until it finds
51 print "\n >> Getting e-cidadania codebase from %s..." % self
.repos
[i
].split('/')[2]
52 print "DEBUG: BRANCH=%s" % branch
55 if i
<= (len(self
.repos
) - 1):
57 get_code
= subprocess
.check_call('git clone -b ' + branch
+ ' ' + self
.repos
[i
] + ' ../ecidadania > /dev/null 2>&1', shell
=True)
60 print " -- Couldn't get the code from %s" % self
.repos
[i
].split('/')[2]
64 print "\n EE Couldn't get the e-cidadania codebase. This can be caused by an old copy of the codebase."
65 print " -- Trying to delete the old codebase..."
68 shutil
.rmtree('ecidadania/')
69 print " -- Code succesfully deleted. Please run the application again.\n"
72 print " -- There was some error trying to delete the old codebase. Exiting.\n"
75 def compile_docs(self
):
78 Compile all the documentation and languages at once.
80 os
.chdir(self
.cwd
+ '/../ecidadania/docs/')
81 sys
.stdout
.write("\n >> Compiling documentation... ")
87 if i
< (len(self
.formats
) - 1):
89 sys
.stdout
.write('(%s) ' % self
.formats
[i
])
91 gen_docs
= subprocess
.check_call('make ' + self
.formats
[i
] + ' > /dev/null 2>&1', shell
=True)
95 print " -- Couldn't compile the %s documentation." % self
.formats
[i
]
97 elif i
== (len(self
.formats
) - 1):
99 sys
.stdout
.write('(%s) ' % self
.formats
[i
])
101 gen_docs
= subprocess
.check_call('make ' + self
.formats
[i
] + ' > /dev/null 2>&1', shell
=True)
106 print " -- Couldn't compile the %s documentation." % self
.formats
[i
]
109 sys
.exit("\n EE Couldn't generate documentation. Exiting.\n")
112 def pack_latex(self
):
115 Package the LaTeX documentation into a tar.gz
117 print " >> Packaging the LaTeX files..."
120 os
.chdir(os
.getcwd() + '/build/latex/')
122 while i
<= (len(self
.langs
) - 1):
123 tar
= tarfile
.open(os
.getcwd() + "/../../%s/latest-%s.tar.gz" % (self
.langs
[i
], self
.langs
[i
]), "w:gz")
124 tar
.add(self
.langs
[i
])
132 Copy the generated documentation into their respective directories.
137 while c
<= (len(self
.formats
) - 1):
138 print " >> Copying the %s documentation..." % self
.formats
[c
]
139 sys
.stdout
.write(" >> done ")
143 while i
<= (len(self
.langs
) - 1):
144 if self
.formats
[c
] == 'latexpdf':
146 copy_latexpdf
= subprocess
.check_call('cp -R build/latex/' + self
.langs
[i
] + '/e-cidadania.pdf ../../' + self
.langs
[i
] + '/latest-' + self
.langs
[i
] + '.pdf', shell
=True)
148 print " -- Couldn't copy the " + self
.langs
[i
] + " documentation."
150 sys
.stdout
.write("(%s) " % self
.langs
[i
])
153 elif self
.formats
[c
] == 'html':
155 copy_html
= subprocess
.check_call('cp -R build/' + self
.formats
[c
] + '/' + self
.langs
[i
] + '/* ../../' + self
.langs
[i
] + '/latest', shell
=True)
157 print " -- Couldn't copy the " + self
.langs
[i
] + " documentation."
159 sys
.stdout
.write("(%s) " % self
.langs
[i
])
162 elif self
.formats
[c
] == 'latex':
164 copy_latex
= subprocess
.check_call('cp -R ' + self
.langs
[i
] + '/latest-' + self
.langs
[i
] + '.tar.gz' + ' ../../' + self
.langs
[i
], shell
=True)
166 print " -- Couldn't copy the " + self
.langs
[i
] + " documentation."
167 print " EE Couldn't copy one or all the documentation! Exiting."
169 sys
.stdout
.write("(%s) " % self
.langs
[i
])
175 def make_all(self
, branch
):
176 if len(sys
.argv
) == 1:
177 self
.download_code(branch
)
179 self
.download_code(sys
.argv
[1])
185 if len(sys
.argv
) == 1:
186 doc
.make_all('master')
188 doc
.make_all(sys
.argv
[1])