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的更多相关文章

  1. 第一个python程序

    一个python程序的两种执行方式: 1.第一种方式是通过python解释器: cmd->python->进入python解释器->编写python代码->回车. 2.第二种方 ...

  2. 第一个python实例--监控cpu

    #第一个python实例:监控cpu #/bin/bash/env Python from __future__ import print_function from collections impo ...

  3. 一个python爬虫小程序

    起因 深夜忽然想下载一点电子书来扩充一下kindle,就想起来python学得太浅,什么“装饰器”啊.“多线程”啊都没有学到. 想到廖雪峰大神的python教程很经典.很著名.就想找找有木有pdf版的 ...

  4. Virtualenv: 一个Python环境管理工具(windown版本)

    1.安装virtualenv 在安装virtualenv之前,我们需要安装至少有一个版本的python:因为virtualenv是python的一个第三方模块,必须基于python环境才能安装: 如果 ...

  5. 3.第一个python程序

    学习任何一门语言的第一步,首先要写个'hello world',这算是程序员的一个传统.但在写之前,还有注意几个问题. 首先,python是一门脚本语言,而脚本语言的特点就是:我们写的代码会先由解释器 ...

  6. ipython, 一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数

    一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数. 若用的是fish s ...

  7. 第一个 Python 程序 - Email Manager Demo

    看了一些基础的 Python 新手教程后,深深感觉到 Python 的简洁与强大,这是我的第一个 Python Demo.下面是完整代码与执行截图. 代码: # encoding: utf-8 ''' ...

  8. 【Python脚本】Python创建删除文件-----------我的第一个Python脚本

    Python相对C++和Java来说,是解释性语言,非常适合来编写脚本. 很久之前就开始学习Python的语法了,今天写了第一个Python的脚本,来简化我的一些日常工作. 我平时学习的时候喜欢新建一 ...

  9. Python学习笔记4-如何快速的学会一个Python的模块、方法、关键字

    想要快速的学会一个Python的模块和方法,两个函数必须要知道,那就是dir()和help() dir():能够快速的以集合的型式列出该模块下的所有内容(类.常量.方法)例: #--encoding: ...

  10. 使用PyQt来编写第一个Python GUI程序

    原文:使用PyQt来编写第一个Python GUI程序 本文由 伯乐在线 - Lane 翻译,Daetalus 校稿.未经许可,禁止转载!英文出处:pythonforengineers.com.欢迎加 ...

随机推荐

  1. 使用WebBrowser控件时在网页元素上绘制文本或其他自定义内容

    原文:使用WebBrowser控件时在网页元素上绘制文本或其他自定义内容 第一次在CNBlogs上发Post是提出一个有关使用WebBrowser控件时对SELECT网页元素操作的疑惑,这个问题至今也 ...

  2. Windows 注册和取消注册一个dll或者ocx

    原文:Windows 注册和取消注册一个dll或者ocx 一.DLL是什么        DLL,是Dynamic Link Library 的缩写形式,中文名称为动态链接库.        DLL是 ...

  3. asp.net 给按钮 增加事件

    一个页面,有查询,审核,删除,取消审核 按钮,每次结尾 处都要 调用 Initdata方法,重新刷新数据 繁琐哇,我的解决方法是 protected void Page_Load(object sen ...

  4. MS SQL Server递归查询

    原文:MS SQL Server递归查询 刚才在论坛上看到网友一个要求.参考如下,Insus.NET分析一下,可以使用MS SQL Server的递归查询,得到结果.准备一张表: 根据网友提供的数据, ...

  5. Write the code.Change the world.---WWDC2014

  6. ExtJs--15--Ext.is*各种类型推断的方法,简单看源代码就能够明确了

    /** * Returns true if the passed value is empty, false otherwise. The value is deemed to be empty if ...

  7. 关于jquery mobile 页面闪烁与抖动问题

    1.闪烁:在用a链接跳转到另一个页面的时候,页面总会抖动几下,其实就是页面切换时的transition特效,jqm貌似默认了这项. 解决方案:在a链接添加transition:none; 属性就可以啦 ...

  8. IOS开发中怎样验证邮箱的合法性

    IOS开发中怎样验证邮箱的合法性 文章参考:http://www.codes51.com/article/detail_94157.html 代码: - (void)viewDidLoad { [su ...

  9. R - 变化plot字形,嵌入字体以pdf

    近期使用R绘图遇到两个问题 1. 使用不同的字体 2. 保存 plot 至 pdf 当字体嵌入pdf (embed the font) 使用extrafont和Ghostscript能够解决这两个问题 ...

  10. MFC 界面编程 可参考资料

    http://www.codeproject.com/Articles/26887/A-user-draw-button-that-supports-PNG-files-with-tr http:// ...