Merge branch 'gh-pages' into add-version-to-footer
[rnaseq-cwl-training.git] / bin / lesson_initialize.py
1 #!/usr/bin/env python
2
3 """Initialize a newly-created repository."""
4
5
6 import sys
7 import os
8
9 ROOT_AUTHORS = '''\
10 FIXME: list authors' names and email addresses.
11 '''
12
13 ROOT_CITATION = '''\
14 FIXME: describe how to cite this lesson.
15 '''
16
17 ROOT_CONTRIBUTING_MD = '''\
18 # Contributing
19
20 [Software Carpentry][swc-site] and [Data Carpentry][dc-site] are open source projects,
21 and we welcome contributions of all kinds:
22 new lessons,
23 fixes to existing material,
24 bug reports,
25 and reviews of proposed changes are all welcome.
26
27 ## Contributor Agreement
28
29 By contributing,
30 you agree that we may redistribute your work under [our license](LICENSE.md).
31 In exchange,
32 we will address your issues and/or assess your change proposal as promptly as we can,
33 and help you become a member of our community.
34 Everyone involved in [Software Carpentry][swc-site] and [Data Carpentry][dc-site]
35 agrees to abide by our [code of conduct](CONDUCT.md).
36
37 ## How to Contribute
38
39 The easiest way to get started is to file an issue
40 to tell us about a spelling mistake,
41 some awkward wording,
42 or a factual error.
43 This is a good way to introduce yourself
44 and to meet some of our community members.
45
46 1.  If you do not have a [GitHub][github] account,
47     you can [send us comments by email][email].
48     However,
49     we will be able to respond more quickly if you use one of the other methods described below.
50
51 2.  If you have a [GitHub][github] account,
52     or are willing to [create one][github-join],
53     but do not know how to use Git,
54     you can report problems or suggest improvements by [creating an issue][issues].
55     This allows us to assign the item to someone
56     and to respond to it in a threaded discussion.
57
58 3.  If you are comfortable with Git,
59     and would like to add or change material,
60     you can submit a pull request (PR).
61     Instructions for doing this are [included below](#using-github).
62
63 ## Where to Contribute
64
65 1.  If you wish to change this lesson,
66     please work in <https://github.com/swcarpentry/FIXME>,
67     which can be viewed at <https://swcarpentry.github.io/FIXME>.
68
69 2.  If you wish to change the example lesson,
70     please work in <https://github.com/swcarpentry/lesson-example>,
71     which documents the format of our lessons
72     and can be viewed at <https://swcarpentry.github.io/lesson-example>.
73
74 3.  If you wish to change the template used for workshop websites,
75     please work in <https://github.com/swcarpentry/workshop-template>.
76     The home page of that repository explains how to set up workshop websites,
77     while the extra pages in <https://swcarpentry.github.io/workshop-template>
78     provide more background on our design choices.
79
80 4.  If you wish to change CSS style files, tools,
81     or HTML boilerplate for lessons or workshops stored in `_includes` or `_layouts`,
82     please work in <https://github.com/swcarpentry/styles>.
83
84 ## What to Contribute
85
86 There are many ways to contribute,
87 from writing new exercises and improving existing ones
88 to updating or filling in the documentation
89 and submitting [bug reports][issues]
90 about things that don't work, aren't clear, or are missing.
91 If you are looking for ideas, please see the 'Issues' tab for
92 a list of issues associated with this repository,
93 or you may also look at the issues for [Data Carpentry][dc-issues]
94 and [Software Carpentry][swc-issues] projects.
95
96 Comments on issues and reviews of pull requests are just as welcome:
97 we are smarter together than we are on our own.
98 Reviews from novices and newcomers are particularly valuable:
99 it's easy for people who have been using these lessons for a while
100 to forget how impenetrable some of this material can be,
101 so fresh eyes are always welcome.
102
103 ## What *Not* to Contribute
104
105 Our lessons already contain more material than we can cover in a typical workshop,
106 so we are usually *not* looking for more concepts or tools to add to them.
107 As a rule,
108 if you want to introduce a new idea,
109 you must (a) estimate how long it will take to teach
110 and (b) explain what you would take out to make room for it.
111 The first encourages contributors to be honest about requirements;
112 the second, to think hard about priorities.
113
114 We are also not looking for exercises or other material that only run on one platform.
115 Our workshops typically contain a mixture of Windows, Mac OS X, and Linux users;
116 in order to be usable,
117 our lessons must run equally well on all three.
118
119 ## Using GitHub
120
121 If you choose to contribute via GitHub, you may want to look at
122 [How to Contribute to an Open Source Project on GitHub][how-contribute].
123 To manage changes, we follow [GitHub flow][github-flow].
124 Each lesson has two maintainers who review issues and pull requests or encourage others to do so.
125 The maintainers are community volunteers and have final say over what gets merged into the lesson.
126 To use the web interface for contributing to a lesson:
127
128 1.  Fork the originating repository to your GitHub profile.
129 2.  Within your version of the forked repository, move to the `gh-pages` branch and
130 create a new branch for each significant change being made.
131 3.  Navigate to the file(s) you wish to change within the new branches and make revisions as required.
132 4.  Commit all changed files within the appropriate branches.
133 5.  Create individual pull requests from each of your changed branches
134 to the `gh-pages` branch within the originating repository.
135 6.  If you receive feedback, make changes using your issue-specific branches of the forked
136 repository and the pull requests will update automatically.
137 7.  Repeat as needed until all feedback has been addressed.
138
139 When starting work, please make sure your clone of the originating `gh-pages` branch is up-to-date
140 before creating your own revision-specific branch(es) from there.
141 Additionally, please only work from your newly-created branch(es) and *not*
142 your clone of the originating `gh-pages` branch.
143 Lastly, published copies of all the lessons are available in the `gh-pages` branch of the originating
144 repository for reference while revising.
145
146 ## Other Resources
147
148 General discussion of [Software Carpentry][swc-site] and [Data Carpentry][dc-site]
149 happens on the [discussion mailing list][discuss-list],
150 which everyone is welcome to join.
151 You can also [reach us by email][email].
152
153 [email]: mailto:admin@software-carpentry.org
154 [dc-issues]: https://github.com/issues?q=user%3Adatacarpentry
155 [dc-lessons]: http://datacarpentry.org/lessons/
156 [dc-site]: http://datacarpentry.org/
157 [discuss-list]: http://lists.software-carpentry.org/listinfo/discuss
158 [github]: https://github.com
159 [github-flow]: https://guides.github.com/introduction/flow/
160 [github-join]: https://github.com/join
161 [how-contribute]: https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github
162 [issues]: https://guides.github.com/features/issues/
163 [swc-issues]: https://github.com/issues?q=user%3Aswcarpentry
164 [swc-lessons]: https://software-carpentry.org/lessons/
165 [swc-site]: https://software-carpentry.org/
166 '''
167
168 ROOT_CONFIG_YML = '''\
169 #------------------------------------------------------------
170 # Values for this lesson.
171 #------------------------------------------------------------
172
173 # Which carpentry is this ("swc", "dc", or "lc")?
174 carpentry: "swc"
175
176 # Overall title for pages.
177 title: "Lesson Title"
178
179 # Contact.  This *must* include the protocol: if it's an email
180 # address, it must look like "mailto:lessons@software-carpentry.org",
181 # or if it's a URL, "https://gitter.im/username/ProjectName".
182 email: "mailto:lessons@software-carpentry.org"
183
184 #------------------------------------------------------------
185 # Generic settings (should not need to change).
186 #------------------------------------------------------------
187
188 # What kind of thing is this ("workshop" or "lesson")?
189 kind: "lesson"
190
191 # Magic to make URLs resolve both locally and on GitHub.
192 # See https://help.github.com/articles/repository-metadata-on-github-pages/.
193 repository: <USERNAME>/<PROJECT>
194
195 # Sites.
196 amy_site: "https://amy.software-carpentry.org/workshops"
197 carpentries_github: "https://github.com/carpentries"
198 carpentries_pages: "https://carpentries.github.io"
199 carpentries_site: "https://carpentries.org/"
200 dc_site: "http://datacarpentry.org"
201 example_repo: "https://github.com/swcarpentry/lesson-example"
202 example_site: "https://swcarpentry.github.com/lesson-example"
203 lc_site: "https://librarycarpentry.github.io/"
204 swc_github: "https://github.com/swcarpentry"
205 swc_pages: "https://swcarpentry.github.io"
206 swc_site: "https://software-carpentry.org"
207 template_repo: "https://github.com/swcarpentry/styles"
208 training_site: "https://swcarpentry.github.io/instructor-training"
209 workshop_repo: "https://github.com/swcarpentry/workshop-template"
210 workshop_site: "https://swcarpentry.github.io/workshop-template"
211
212 # Surveys.
213 pre_survey: "https://www.surveymonkey.com/r/swc_pre_workshop_v1?workshop_id="
214 post_survey: "https://www.surveymonkey.com/r/swc_post_workshop_v1?workshop_id="
215 training_post_survey: "https://www.surveymonkey.com/r/post-instructor-training"
216
217 # Start time in minutes (0 to be clock-independent, 540 to show a start at 09:00 am).
218 start_time: 0
219
220 # Specify that things in the episodes collection should be output.
221 collections:
222   episodes:
223     output: true
224     permalink: /:path/index.html
225   extras:
226     output: true
227     permalink: /:path/index.html
228
229 # Set the default layout for things in the episodes collection.
230 defaults:
231   - values:
232       root: ..
233   - scope:
234       path: ""
235       type: episodes
236     values:
237       layout: episode
238
239 # Files and directories that are not to be copied.
240 exclude:
241   - Makefile
242   - bin
243
244 # Turn on built-in syntax highlighting.
245 highlighter: rouge
246 '''
247
248 ROOT_INDEX_MD = '''\
249 ---
250 layout: lesson
251 root: .
252 permalink: index.html  # Is the only page that don't follow the partner /:path/index.html
253 ---
254 FIXME: home page introduction
255
256 > ## Prerequisites
257 >
258 > FIXME
259 {: .prereq}
260 '''
261
262 ROOT_REFERENCE_MD = '''\
263 ---
264 layout: reference
265 root: .
266 ---
267
268 ## Glossary
269
270 FIXME
271 '''
272
273 ROOT_SETUP_MD = '''\
274 ---
275 layout: page
276 title: Setup
277 root: .
278 ---
279 FIXME
280 '''
281
282 ROOT_AIO_MD = '''\
283 ---
284 layout: page
285 root: .
286 ---
287 <script>
288   window.onload = function() {
289     var lesson_episodes = [
290     {% for episode in site.episodes %}
291     "{{ episode.url}}"{% unless forloop.last %},{% endunless %}
292     {% endfor %}
293     ];
294     var xmlHttp = [];  /* Required since we are going to query every episode. */
295     for (i=0; i < lesson_episodes.length; i++) {
296       xmlHttp[i] = new XMLHttpRequest();
297       xmlHttp[i].episode = lesson_episodes[i];  /* To enable use this later. */
298       xmlHttp[i].onreadystatechange = function() {
299       if (this.readyState == 4 && this.status == 200) {
300         var article_here = document.getElementById(this.episode);
301         var parser = new DOMParser();
302         var htmlDoc = parser.parseFromString(this.responseText,"text/html");
303         var htmlDocArticle = htmlDoc.getElementsByTagName("article")[0];
304         article_here.innerHTML = htmlDocArticle.innerHTML;
305         }
306       }
307       episode_url = "{{ page.root }}" + lesson_episodes[i];
308       xmlHttp[i].open("GET", episode_url);
309       xmlHttp[i].send(null);
310     }
311   }
312 </script>
313 {% comment %}
314 Create anchor for each one of the episodes.
315 {% endcomment %}
316 {% for episode in site.episodes %}
317 <article id="{{ episode.url }}"></article>
318 {% endfor %}
319 '''
320
321 EPISODES_INTRODUCTION_MD = '''\
322 ---
323 title: "Introduction"
324 teaching: 0
325 exercises: 0
326 questions:
327 - "Key question"
328 objectives:
329 - "First objective."
330 keypoints:
331 - "First key point."
332 ---
333 '''
334
335 EXTRAS_ABOUT_MD = '''\
336 ---
337 layout: page
338 title: About
339 ---
340 {% include carpentries.html %}
341 '''
342
343 EXTRAS_DISCUSS_MD = '''\
344 ---
345 layout: page
346 title: Discussion
347 ---
348 FIXME
349 '''
350
351 EXTRAS_FIGURES_MD = '''\
352 ---
353 layout: page
354 title: Figures
355 ---
356 <script>
357   window.onload = function() {
358     var lesson_episodes = [
359     {% for episode in site.episodes %}
360     "{{ episode.url}}"{% unless forloop.last %},{% endunless %}
361     {% endfor %}
362     ];
363     var xmlHttp = [];  /* Required since we are going to query every episode. */
364     for (i=0; i < lesson_episodes.length; i++) {
365       xmlHttp[i] = new XMLHttpRequest();
366       xmlHttp[i].episode = lesson_episodes[i];  /* To enable use this later. */
367       xmlHttp[i].onreadystatechange = function() {
368         if (this.readyState == 4 && this.status == 200) {
369           var article_here = document.getElementById(this.episode);
370           var parser = new DOMParser();
371           var htmlDoc = parser.parseFromString(this.responseText,"text/html");
372           var htmlDocArticle = htmlDoc.getElementsByTagName("article")[0];
373           article_here.appendChild(htmlDocArticle.getElementsByTagName("h1")[0]);
374           for (let image of htmlDocArticle.getElementsByTagName("img")) {
375             article_here.appendChild(image);
376           }
377         }
378       }
379       episode_url = "{{ page.root }}" + lesson_episodes[i];
380       xmlHttp[i].open("GET", episode_url);
381       xmlHttp[i].send(null);
382     }
383   }
384 </script>
385 {% comment %}
386 Create anchor for each one of the episodes.
387 {% endcomment %}
388 {% for episode in site.episodes %}
389 <article id="{{ episode.url }}"></article>
390 {% endfor %}
391 '''
392
393 EXTRAS_GUIDE_MD = '''\
394 ---
395 layout: page
396 title: "Instructor Notes"
397 ---
398 FIXME
399 '''
400
401 BOILERPLATE = (
402     ('AUTHORS', ROOT_AUTHORS),
403     ('CITATION', ROOT_CITATION),
404     ('CONTRIBUTING.md', ROOT_CONTRIBUTING_MD),
405     ('_config.yml', ROOT_CONFIG_YML),
406     ('index.md', ROOT_INDEX_MD),
407     ('reference.md', ROOT_REFERENCE_MD),
408     ('setup.md', ROOT_SETUP_MD),
409     ('aio.md', ROOT_AIO_MD),
410     ('_episodes/01-introduction.md', EPISODES_INTRODUCTION_MD),
411     ('_extras/about.md', EXTRAS_ABOUT_MD),
412     ('_extras/discuss.md', EXTRAS_DISCUSS_MD),
413     ('_extras/figures.md', EXTRAS_FIGURES_MD),
414     ('_extras/guide.md', EXTRAS_GUIDE_MD),
415 )
416
417
418 def main():
419     """Check for collisions, then create."""
420
421     # Check.
422     errors = False
423     for (path, _) in BOILERPLATE:
424         if os.path.exists(path):
425             print('Warning: {0} already exists.'.format(path), file=sys.stderr)
426             errors = True
427     if errors:
428         print('**Exiting without creating files.**', file=sys.stderr)
429         sys.exit(1)
430
431     # Create.
432     for (path, content) in BOILERPLATE:
433         with open(path, 'w') as writer:
434             writer.write(content)
435
436
437 if __name__ == '__main__':
438     main()