Completed
Push — master ( 343230...71ae82 )
by Thomas
01:57 queued 53s
created

doorpi.docs.service.parse_string()   A

Complexity

Conditions 3

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 5
rs 9.4285
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4
import doorpi.metadata as metadata
5
import os
6
import urllib2
7
8
def parse_string(raw_string):
9
    for meta_key in dir(metadata):
10
        if not meta_key.startswith('__'):
11
            raw_string = raw_string.replace('!!%s!!' % meta_key,  str(getattr(metadata, meta_key)))
12
    return raw_string
13
14
15
def create_daemon_file():
16
    print("start to create daemon file now...")
17
    print("start download and parse new daemon file:")
18
    print("URL:  "+metadata.daemon_online_template)
19
    print("FILE: "+metadata.daemon_file)
20
    with open(metadata.daemon_file, "w") as daemon_file:
21
        for line in urllib2.urlopen(metadata.daemon_online_template):
22
            daemon_file.write(parse_string(line))
23
        print("download successfully - change chmod to 0755 now")
24
        os.chmod(metadata.daemon_file, 0755)
25
        print "finished"
26
27
if __name__ == '__main__':
28
    create_daemon_file()
29