第一个python
import MySQLdb
import os,sys
import string
dto=os.getcwd()+"\\dto"
dao=os.getcwd()+"\\dao"
idao=os.getcwd()+"\\dao\\impl"
service=os.getcwd()+"\\service"
iservice=os.getcwd()+"\\service\\impl"
config=os.getcwd()+"\\config" def convertColum(name):
a="_"+name.replace("_", " ")
word=string.capwords(a).replace(" ", "").replace("_", "")
return word def changeType(type):
if(type=="varchar"):
return "String"
elif(type=="int"):
return "Integer"
return "String"
def changeName(name):
return name.lower().capitalize() def creatrFile(fileP,fileN,fileS):
if(os.path.exists(fileP)!=True):
os.makedirs(fileP)
f=file(fileP+"\\"+fileN,'w')
f.write(fileS)
f.close() print("begining to connect Mysql.")
try:
dbName='db'
connection = MySQLdb.connect(user="root",passwd="",host="127.0.0.1",db=dbName)
cursor = connection.cursor()
cursor.execute( "SELECT TABLE_NAME,TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='"+dbName+"' " ) filestr=[]
configstr=[]
for row in cursor.fetchall():
tableName=row[0]
filestr.append('package dto;\n'
'import java.util.Date;\n'
'import java.util.HashMap;\n'
'import java.util.Map;\n'
'import data.BaseDto;\n'
'public class '+ changeName(tableName)+'Info extends BaseDto {\n'
' public '+ changeName(tableName) +'Info(){\n'
' this.setTbName("'+tableName+'");\n'
' }\n') cursor1 = connection.cursor()
cursor1.execute( "SELECT COLUMN_NAME as ColumnName,DATA_TYPE as dataType FROM INFORMATION_SCHEMA.COLUMNS where table_name='"+tableName+"' and TABLE_SCHEMA='"+dbName+"'" )
getsetStr=[]
for row1 in cursor1.fetchall():
filestr.append(' private '+changeType(row1[1])+' '+convertColum(row1[0])+';\n')
getsetStr.append(' public String get'+changeName(convertColum(row1[0]))+'() {\n'
' return '+row1[0]+';\n'
' }\n'
' public void set'+changeName(convertColum(row1[0]))+'('+changeType(row1[1])+' '+convertColum(row1[0])+') {\n'
' this.'+convertColum(row1[0])+' = '+convertColum(row1[0])+';\n'
' }\n')
getsetStr.append('}')
creatrFile(dto,changeName(tableName)+".java",''.join(filestr)+''.join(getsetStr)) #dao
filestr=[]
filestr.append('package dao;\nimport data.BaseDao;\n'
'import dto.*;\n'
'public interface I'+changeName(tableName)+'Dao implements IRepository<'+ changeName(tableName)+'Info> { \n'
'}')
creatrFile(dao,"I"+changeName(tableName)+"Dao.java",''.join(filestr)) filestr=[]
filestr.append('package dao.impl;\nimport data.BaseDao;\n'
'import dto.*;\n'
'public class '+changeName(tableName)+'DaoImpl extends BaseDao<'+ changeName(tableName)+'Info> implements I'+changeName(tableName)+'Dao { \n'
'}')
creatrFile(idao,""+changeName(tableName)+"DaoImpl.java",''.join(filestr)) #service
filestr=[]
filestr.append('package Service;\n'
'import dto.*;\n'
'public interface I'+changeName(tableName)+'Service { \n'
'}')
creatrFile(service,"I"+changeName(tableName)+"Service.java",''.join(filestr))
filestr=[]
filestr.append('package Service.impl;\nimport data.BaseDao;\n'
'import Service.*;\nimport com.google.inject.Inject;\n'
'public class '+changeName(tableName)+'ServiceImpl { \n'
' @Inject\n'
' private I'+changeName(tableName)+'Dao '+changeName(tableName)+'Dao;\n'
'}')
creatrFile(iservice,""+changeName(tableName)+"ServiceImpl.java",''.join(filestr)) filestr=[]
filestr.append('package cn.uc.custom.wallpaper.config;\n'
'import com.google.inject.*;\n'
'import play.modules.guice.GuiceSupport;\n' 'public class GuicyDummy extends GuiceSupport {\n'
' protected Injector configure() {\n'
' Injector injector = Guice.createInjector(new GuicyDummyModel());\n'
' return injector;\n'
' }\n'
'}\n')
creatrFile(config,"GuicyDummy.java",''.join(filestr)) configstr.append(" bind(I"+changeName(tableName)+"Dao.class).to("+changeName(tableName)+"DaoImpl.class).in(Singleton.class);\n");
configstr.append(" bind(I"+changeName(tableName)+"Service.class).to("+changeName(tableName)+"ServiceImpl.class).in(Singleton.class);\n");
filestr=[]
filestr.append('package cn.uc.custom.wallpaper.config;\n'
'import com.google.inject.*;\n'
'import play.modules.guice.GuiceSupport;\n' 'public class GuicyDummy extends GuiceSupport {\n'
' protected Injector configure() {\n'
' Injector injector = Guice.createInjector(new GuicyDummyModel());\n'
' return injector;\n'
' }\n'
'}\n')
creatrFile(config,"GuicyDummy.java",''.join(filestr))
filestr=[]
filestr.append('package cn.uc.custom.wallpaper.config;\n'
'import com.google.inject.*;\n'
'import play.modules.guice.GuiceSupport;\n' 'public class GuicyDummyModel extends AbstractModule {\n'
' public void configure() {\n')
filestr.append(''.join(configstr))
filestr.append(' }\n'
'}\n')
creatrFile(config,"GuicyDummyModel.java",''.join(filestr))
cursor.close()
except MySQLdb.Error,e:
print "Mysql Error %d: %s" % (e.args[0], e.args[1])
欢迎访问我的新站:学习树教育的第二入口
第一个python的更多相关文章
- 第一个python程序
一个python程序的两种执行方式: 1.第一种方式是通过python解释器: cmd->python->进入python解释器->编写python代码->回车. 2.第二种方 ...
- 第一个python实例--监控cpu
#第一个python实例:监控cpu #/bin/bash/env Python from __future__ import print_function from collections impo ...
- 一个python爬虫小程序
起因 深夜忽然想下载一点电子书来扩充一下kindle,就想起来python学得太浅,什么“装饰器”啊.“多线程”啊都没有学到. 想到廖雪峰大神的python教程很经典.很著名.就想找找有木有pdf版的 ...
- Virtualenv: 一个Python环境管理工具(windown版本)
1.安装virtualenv 在安装virtualenv之前,我们需要安装至少有一个版本的python:因为virtualenv是python的一个第三方模块,必须基于python环境才能安装: 如果 ...
- 3.第一个python程序
学习任何一门语言的第一步,首先要写个'hello world',这算是程序员的一个传统.但在写之前,还有注意几个问题. 首先,python是一门脚本语言,而脚本语言的特点就是:我们写的代码会先由解释器 ...
- ipython, 一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数
一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数. 若用的是fish s ...
- 第一个 Python 程序 - Email Manager Demo
看了一些基础的 Python 新手教程后,深深感觉到 Python 的简洁与强大,这是我的第一个 Python Demo.下面是完整代码与执行截图. 代码: # encoding: utf-8 ''' ...
- 【Python脚本】Python创建删除文件-----------我的第一个Python脚本
Python相对C++和Java来说,是解释性语言,非常适合来编写脚本. 很久之前就开始学习Python的语法了,今天写了第一个Python的脚本,来简化我的一些日常工作. 我平时学习的时候喜欢新建一 ...
- Python学习笔记4-如何快速的学会一个Python的模块、方法、关键字
想要快速的学会一个Python的模块和方法,两个函数必须要知道,那就是dir()和help() dir():能够快速的以集合的型式列出该模块下的所有内容(类.常量.方法)例: #--encoding: ...
- 使用PyQt来编写第一个Python GUI程序
原文:使用PyQt来编写第一个Python GUI程序 本文由 伯乐在线 - Lane 翻译,Daetalus 校稿.未经许可,禁止转载!英文出处:pythonforengineers.com.欢迎加 ...
随机推荐
- 安装ruby on rail
安装: # nvm 安装, 两种方法 $ curl https://raw.githubusercontent.com/creationix/nvm/v0.8.0/install.sh | sh $ ...
- ios 设备基本信息检测
开发ios确实会让人身心愉悦(相对于deskop,android),ios app更多的让人集中注意力到它本身的体验,性能.这非常好,我非常喜欢相对完美的事物. 最近遇到一些乱七八糟的需求.需要获取一 ...
- c语言发挥帕斯卡三角
我们已经确定了帕斯卡三角的规则,下面是我的代码,非常实用哦! !! #include<stdio.h> void main() { int i,j,n,k; sca ...
- 客户端Webview重定向
今天在客户端的网页中写了句alert的代码,发现执行了两次,后来发现网页的地址写的是http://192.168.14.72/app 客户端Webview加载网页,对于不完全路径会重定向到完全路径,导 ...
- 命令行配置源和安装本地rpm包
因为Firefox的在写博客时提交代码会丢失缩进,所以打算安装Chrome来写博,还不错,学到了两条命令- [shell] sudo yum-config-manager --add-repo=htt ...
- 用批处理编译*.sln工程
原文:用批处理编译*.sln工程 批处理是直接调用Microsoft Visual Studio 8\Common7\IDE\ 目录内的 devenv.exe ,它启动后就是IDE,提供的参数如下: ...
- 图文解说PhpStorm 7.0版本新增内置工具
很多PHP开发者,都比较关心PhpStorm 7.0版本的内置工具.今天我们将测试内置的Vagrant工具和SSH远端控制台工具. Vagrant工具集成在PhpStorm 7.0版本中,提高了IDE ...
- 安装SQL Server 2005 - 初学者系列 - 学习者系列文章
初学者阶段,建议从数据库为基础入手进行学习. 下面介绍微软的SQL Server 2005数据库的安装. 首先,从下列地址获取SQL Server 2005的安装程序. ed2k://|file|cs ...
- 如何使用OPENQUERY访问另一个SQL Server
原文:如何使用OPENQUERY访问另一个SQL Server 在项目中,经常会遇到一个数据库访问另一个数据库,[CNVFERPDB]为服务器名,[CE3]为库名 SELECT Dtl.* FROM ...
- iis7 下配置MVC问题
HTTP 错误 404.0 - Not Found 您要找的资源已被删除.已更名或暂时不可用. 详细错误信息 模块 IIS Web Core 通知 MapRequestHandler 处理程序 Sta ...