Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

class FileSource(object): 

def __init__(self, filename, place): 

self.filename = filename 

self.place = place 

 

class Collection(object): 

def __init__(self, cid, files, name="", description=""): 

self.cid = cid 

self.files = files 

self.name = name 

self.desctiption = description 

 

 

def collection_from_dict(cid, data, default_place="primary"): 

name = data.get("name", "") 

description = data.get("description", "") 

files = [parse_filesource(filesource, default_place) 

for filesource in data["files"]] 

return Collection(cid, files, name, description) 

 

 

def parse_filesource(filesource, default_place="primary"): 

if isinstance(filesource, dict): 

return FileSource(filesource["filename"], 

filesource.get("place", default_place)) 

else: 

return FileSource(filesource, default_place) 

 

 

def find_collections_in_folder(folder, default_place="primary"): 

import yaml 

import re 

import os 

collfile_re = re.compile(r"collection_([0-9]+)\.yaml") 

collection_data = [] 

for dirpath, dirnames, filenames in os.walk(folder): 

for filename in filenames: 

match = collfile_re.match(filename) 

39 ↛ 40line 39 didn't jump to line 40, because the condition on line 39 was never true if match is None: 

continue 

cid = int(match.group(1)) 

with open(os.path.join(dirpath, filename)) as collection_file: 

collection = collection_from_dict(cid, 

yaml.load(collection_file), 

default_place) 

collection_data.append(collection) 

return collection_data