#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import ftplib
import ConfigParser
import datetime
import os
import MySQLdb
#localhost
#10.4.211.158
def connect_mysql():
db_config = dict(host="10.4.211.158", port=3306, db="ci_data", charset="utf8", user="root", passwd="123456")
try:
cnx = MySQLdb.connect(**db_config)
except Exception as err:
raise err
return cnx
print connect_mysql()
time=datetime.datetime.now().strftime('%Y%m%d_%H%M%S_')
conf = ConfigParser.ConfigParser()
conf.read('setting.ini')
host = conf.get("FTP", "host")
username = conf.get("FTP", "username")
password = '123456'
employee_id = conf.get("CFG", "id")
tfs= conf.get("CFG", "tfs").replace('"', "")
comment = conf.get("CFG", "comment").replace('"', "")
branch = conf.get("CFG", "branch").replace('"', "")
fileName = time + tfs + '.txt'
def ftp_upload():
file_remote = fileName
file_local = fileName
bufsize = 1024 # 设置缓冲器大小
fp = open(file_local, 'rb')
f.storbinary('STOR ' + file_remote, fp, bufsize)
fp.close()
f = ftplib.FTP(host)
f.login(username, password)
pwd_path = f.pwd()
f.cwd(pwd_path+'/CI')
a = f.dir()
try:
f.cwd(employee_id)
except:
f.mkd(employee_id)
f.cwd(employee_id)
def check_list():
pass
#a = raw_input("input:")
checkDic = {}
rules = []
rules.append( '01. 1!')
rules.append( '02. 2!')
rules.append('''03. 3''')
print '*'*100
for rule in rules:
while 1:
print ''
print rule
print "\n0: q, 1: w"
res = str(sys.stdin.readline()).replace("\n", "")
if (res != '0') and (res != '1'):
print "Error input:", res
continue
else:
checkDic[rule] = res
break
checkList=sorted(checkDic.iteritems(),key=lambda abs:abs[0],reverse=False)
out=open(fileName,'w')
for dic in checkList:
key, value = dic
print value.replace("\n", "") + ' | ' + key + '\n'
out.write(value.replace("\n", "") + ' | ' + key + '\n')
out.write('-'*100+'\n')
out.close()
ftp_upload()
if os.path.exists(fileName):
os.remove(fileName)