1
2
3
4
5
6
7
8
9
10
11
12
13 import os
14 import re
15 import string
16 import mimetypes
17 from itertools import chain
18 from deefuzzer.tools import *
19
20 mimetypes.add_type('application/x-yaml', '.yaml')
21
22
24 """ Return the word without excessive blank spaces, underscores and
25 characters causing problem to exporters"""
26 word = re.sub("^[^\w]+", "", word)
27 word = re.sub("[^\w]+$", "", word)
28 word = re.sub("_+", "_", word)
29 word = re.sub("^[^\w]+", "", word)
30
31
32 dict = '&[];"*:,'
33 for letter in dict:
34 word = string.replace(word, letter, '_')
35 return word
36
37
39 file_name = media.split(os.sep)[-1]
40 file_title = file_name.split('.')[:-1]
41 file_title = '.'.join(file_title)
42 file_ext = file_name.split('.')[-1]
43 return file_name, file_title, file_ext
44
45
47 return os.sep == path[0]
48
49
51 combined = {}
52 for key in set(chain(setting, default)):
53 if key in setting:
54 if key in default:
55 if isinstance(setting[key], dict) and isinstance(default[key], dict):
56 combined[key] = merge_defaults(setting[key], default[key])
57 else:
58 combined[key] = setting[key]
59 else:
60 combined[key] = setting[key]
61 else:
62 combined[key] = default[key]
63 return combined
64
65
67 if isinstance(option, list):
68 r = []
69 for i in option:
70 r.append(replace_all(i, repl))
71 return r
72 elif isinstance(option, dict):
73 r = {}
74 for key in option.keys():
75 r[key] = replace_all(option[key], repl)
76 return r
77 elif isinstance(option, str):
78 r = option
79 for key in repl.keys():
80 r = r.replace('[' + key + ']', repl[key])
81 return r
82 return option
83
84
86 mime_type = mimetypes.guess_type(file)[0]
87
88
89 if 'xml' in mime_type:
90 confile = open(file, 'r')
91 data = confile.read()
92 confile.close()
93 return xmltodict(data, 'utf-8')
94 elif 'yaml' in mime_type:
95 import yaml
96
97 def custom_str_constructor(loader, node):
98 return loader.construct_scalar(node).encode('utf-8')
99
100 yaml.add_constructor(u'tag:yaml.org,2002:str', custom_str_constructor)
101 confile = open(file, 'r')
102 data = confile.read()
103 confile.close()
104 return yaml.load(data)
105 elif 'json' in mime_type:
106 import json
107
108 confile = open(file, 'r')
109 data = confile.read()
110 confile.close()
111 return json.loads(data)
112
113 return False
114
115
117 files = os.listdir(folder)
118 for file in files:
119 filepath = os.path.join(folder, file)
120 if os.path.isfile(filepath):
121 mime_type = mimetypes.guess_type(filepath)[0]
122 if 'audio/mpeg' in mime_type or 'audio/ogg' in mime_type:
123 return True
124 return False
125