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