Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 52001f9

Browse files
committed
change code
1 parent ea7aefa commit 52001f9

File tree

7 files changed

+168
-1
lines changed

7 files changed

+168
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
*.so
44
*.egg
55
*.egg-info
6+
*.log
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<VirtualHost local2:80>
2+
ServerName test.com
3+
ServerAlias www.test.com
4+
DocumentRoot /data/www/wwwroot/zencart/www.test.com
5+
ErrorLog /var/log/web/www.test.com-error-log
6+
CustomLog /var/log/web/www.test.com-access-log combined
7+
DirectoryIndex index.html index.htm index.php index.php4 index.php5
8+
<Directory /data/www/wwwroot/zencart/www.test.com>
9+
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
10+
allow from all
11+
AllowOverride All
12+
RewriteEngine on
13+
</Directory>
14+
</VirtualHost>
15+
<VirtualHost 192.168.56.22:80>
16+
ServerName baidu.org
17+
ServerAlias www.baidu.org
18+
DocumentRoot /data/www/wwwroot/zencart/www.baidu.org
19+
ErrorLog /var/log/web/www.baidu.org-error-log
20+
CustomLog /var/log/web/www.baidu.org-access-log combined
21+
DirectoryIndex index.html index.htm index.php index.php4 index.php5
22+
<Directory /data/www/wwwroot/zencart/www.baidu.org>
23+
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
24+
allow from all
25+
AllowOverride All
26+
RewriteEngine on
27+
</Directory>
28+
</VirtualHost>
29+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<VirtualHost local2:80>
2+
ServerName test.com
3+
ServerAlias www.test.com
4+
DocumentRoot /data/www/wwwroot/zencart/www.test.com
5+
ErrorLog /var/log/web/www.test.com-error-log
6+
CustomLog /var/log/web/www.test.com-access-log combined
7+
DirectoryIndex index.html index.htm index.php index.php4 index.php5
8+
<Directory /data/www/wwwroot/zencart/www.test.com>
9+
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
10+
allow from all
11+
AllowOverride All
12+
RewriteEngine on
13+
</Directory>
14+
</VirtualHost>
15+
<VirtualHost 192.168.56.22:80>
16+
ServerName baidu.org
17+
ServerAlias www.baidu.org
18+
DocumentRoot /tmp
19+
ErrorLog /var/log/web/www.baidu.org-error-log
20+
CustomLog /var/log/web/www.baidu.org-access-log combined
21+
DirectoryIndex index.html index.htm index.php index.php4 index.php5
22+
<Directory /data/www/wwwroot/zencart/www.baidu.org>
23+
Options -Indexes +IncludesNOEXEC +FollowSymLinks +ExecCGI
24+
allow from all
25+
AllowOverride All
26+
RewriteEngine on
27+
</Directory>
28+
</VirtualHost>
29+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
#-*- coding: utf-8 -*-
3+
from cStringIO import StringIO
4+
import re
5+
6+
vhost_start = re.compile(r'<VirtualHost\s+(.*?)>')
7+
vhost_end = re.compile(r'</VirtualHost>')
8+
docroot_obj = re.compile(r'(DocumentRoot\s+)(.*)')
9+
10+
def replace_docroot(conf_string,vhost,new_docroot):
11+
12+
conf_file = StringIO(conf_string)
13+
in_vhost = False
14+
curr_vhost = None
15+
for line in conf_file:
16+
vhost_start_match = vhost_start.search(line)
17+
if vhost_start_match:
18+
curr_vhost = vhost_start_match.groups()[0]
19+
in_vhost = True
20+
if in_vhost and (curr_vhost == vhost):
21+
docroot_match = docroot_obj.search(line)
22+
if docroot_match:
23+
#re sub 模式匹配
24+
sub_line = docroot_obj.sub(r'\1%s' % new_docroot, line)
25+
line = sub_line
26+
vhost_end_match = vhost_end.search(line)
27+
if vhost_end_match:
28+
in_vhost = False
29+
yield line
30+
31+
32+
if __name__ == '__main__':
33+
import sys
34+
conf_file = sys.argv[1]
35+
vhost = sys.argv[2]
36+
docroot = sys.argv[3]
37+
conf_string = open(conf_file).read()
38+
for line in replace_docroot(conf_string,vhost,docroot):
39+
print line,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
5+
def dictify_logline(line):
6+
split_line = line.split()
7+
return {'remote_host': split_line[0],
8+
'status': split_line[8],
9+
'bytes_sent': split_line[9],
10+
}
11+
12+
13+
def generate_log_report(logfile):
14+
report_dict = {}
15+
for line in logfile:
16+
line_dict = dictify_logline(line)
17+
print line_dict
18+
try:
19+
bytes_sent = int(line_dict['bytes_sent'])
20+
except ValueError:
21+
continue
22+
report_dict.setdefault(line_dict['remote_host'],[]).append(bytes_sent)
23+
return report_dict
24+
25+
26+
if __name__ == '__main__':
27+
if not len(sys.argv) > 1:
28+
print __doc__
29+
sys.exit(1)
30+
infile_name = sys.argv[1]
31+
try:
32+
infile = open(infile_name,'r')
33+
except IOError:
34+
print 'you must specify a valid file to parse'
35+
print __doc__
36+
sys.exit(1)
37+
log_report = generate_log_report(infile)
38+
print log_report
39+
infile.close()

examples/func/test_mapreduce.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
3+
4+
5+
print map(lambda x: x*x,[1,2,3,4,5,6])
6+
7+
8+
9+
10+
11+
def add(x,y):
12+
return x + y
13+
14+
def fn(x,y):
15+
return x * 10 + y
16+
print reduce(add,[1,2,3,4,5])
17+
print reduce(fn,[1,2,3,4,5])
18+
19+
20+
#str to int
21+
def str2int(s):
22+
def fn(x,y):
23+
return x * 10 + y
24+
def char2num(s):
25+
return {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}[s]
26+
# return reduce(fn,map(char2num,s))
27+
return reduce(lambda x,y: x*10+y,map(char2num,s))
28+
29+
print type(str2int('12345'))

examples/thread/test_threadLocal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env python
2+
#-*- coding: utf-8 -*-
23

34
import threading
45

5-
6+
#全局变量
67
local_school = threading.local()
78

89
def process_student():

0 commit comments

Comments
 (0)