1+ #!/usr/bin/env python3
2+ from pathlib import Path
3+ import subprocess
4+ from ruamel .yaml import YAML
5+ import shutil
6+ import os
7+
8+ yaml = YAML ()
9+
10+ DEMO_FOLDER = "demofiles"
11+
12+ def setup_talks ():
13+ """
14+ Reads yaml file talks.yml and moves files and folders specified in yaml
15+ file to the a folder matching the name of the talk Args: talk_name: name
16+ of talk in talks.yml Note: yaml file is assumed to be a dict of dicts of
17+ lists and dict with the following python format:
18+ {'talk_name':
19+ {'folders':
20+ {'src0': 'dest0', 'src1': 'dest1']
21+ 'files':
22+ ['file0', file1']
23+ 'rename':
24+ {'oldname': 'newname'}
25+ }
26+ }
27+ or in yaml format:
28+ talk_name:
29+ folders:
30+ src0: dest0
31+ src1: dest1
32+ files:
33+ - file0
34+ - file1
35+ rename:
36+ oldname: newname
37+ """
38+ with open ("talks.yml" , "r" ) as stream :
39+ talks = yaml .load (stream )
40+ for talk_name in talks :
41+ Path (talk_name ).mkdir (parents = True , exist_ok = True )
42+
43+ if "files" in talks [talk_name ]:
44+ for f in talks [talk_name ]["files" ]:
45+ copied_path = os .path .join (talk_name , os .path .basename (f ))
46+ shutil .copy (f , copied_path )
47+ assert os .path .isfile (copied_path ), f"{ f } failed to copy into { talk_name } "
48+
49+ if "folders" in talks [talk_name ]:
50+ for src , dst in talks [talk_name ]["folders" ].items ():
51+ dst = os .path .join (talk_name , dst )
52+ if not os .path .exists (dst ):
53+ shutil .copytree (src , dst )
54+
55+ if "rename" in talks [talk_name ]:
56+ for old_file , new_file in talks [talk_name ]["rename" ].items ():
57+ moved_file = os .path .join (talk_name , os .path .basename (old_file ))
58+ if os .path .isfile (moved_file ):
59+ os .rename (moved_file , os .path .join (talk_name , new_file ))
60+ elif os .path .isfile (old_file ):
61+ shutil .copy (old_file , os .path .join (talk_name , new_file ))
62+
63+ def setup_demofiles ():
64+ print ("creating demofolder" )
65+ demo_folder = Path ("demofiles" )
66+ demo_folder .mkdir (parents = True , exist_ok = True )
67+
68+ # list of repos used in demo
69+ print (f"cloning repos into demo folder { demo_folder } " )
70+ reponames = [
71+ "jakevdp/PythonDataScienceHandbook" ,
72+ "swissnexSF/Urban-Data-Challenge" ,
73+ "altair-viz/altair" ,
74+ "QuantEcon/QuantEcon.notebooks" ,
75+ "theandygross/TCGA" ,
76+ "aymericdamien/TensorFlow-Examples" ,
77+ "bloomberg/bqplot" ,
78+ ]
79+ for repo in reponames :
80+ target_path = demo_folder / Path (repo .split ("/" )[1 ])
81+ if not target_path .is_dir ():
82+ subprocess .check_call ([
83+ "git" , "clone" , "--depth" , "1" ,
84+ f"https://github.com/{ repo } .git"
85+ ], cwd = demo_folder )
86+ # This empty file and empty folder are for showing drag and drop in jupyterlab
87+ Path ("move_this_file.txt" ).touch ()
88+ Path ("move_it_here" ).mkdir (exist_ok = True )
89+
90+ def main ():
91+ setup_demofiles ()
92+ setup_talks ()
93+
94+
95+ if __name__ == "__main__" :
96+ main ()
0 commit comments