db2text 0.2.4__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. {db2text-0.2.4 → db2text-0.3.2}/MANIFEST.in +1 -0
  2. db2text-0.3.2/PKG-INFO +38 -0
  3. {db2text-0.2.4 → db2text-0.3.2}/db2text/data.py +5 -4
  4. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/dbtmanual.md +13 -3
  5. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/dot.mb +28 -26
  6. db2text-0.3.2/db2text/datafile/sample/oceanbase/all.txt +41 -0
  7. db2text-0.3.2/db2text/datafile/sample/oceanbase/sjbf.txt +20 -0
  8. db2text-0.3.2/db2text/datafile/sample/oracle/cc.txt +25 -0
  9. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/sample/oracle/crmrpt.txt +1 -1
  10. db2text-0.3.2/db2text/datafile/sample/oracle/sms.txt +21 -0
  11. {db2text-0.2.4/database2text → db2text-0.3.2/db2text/db}/dm.py +4 -4
  12. {db2text-0.2.4/database2text → db2text-0.3.2/db2text/db}/mssql.py +5 -3
  13. {db2text-0.2.4/database2text → db2text-0.3.2/db2text/db}/mysql.py +5 -2
  14. db2text-0.3.2/db2text/db/ob_oracle.py +148 -0
  15. {db2text-0.2.4/database2text → db2text-0.3.2/db2text/db}/opengauss.py +2 -2
  16. {db2text-0.2.4/database2text → db2text-0.3.2/db2text/db}/oracle11.py +8 -3
  17. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/dbt.py +6 -6
  18. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/tool.py +4 -6
  19. {db2text-0.2.4 → db2text-0.3.2}/db2text/util.py +8 -2
  20. db2text-0.3.2/db2text.egg-info/PKG-INFO +38 -0
  21. db2text-0.3.2/db2text.egg-info/SOURCES.txt +37 -0
  22. db2text-0.3.2/db2text.egg-info/entry_points.txt +4 -0
  23. {db2text-0.2.4 → db2text-0.3.2}/db2text.egg-info/not-zip-safe +0 -0
  24. db2text-0.3.2/db2text.egg-info/top_level.txt +1 -0
  25. {db2text-0.2.4 → db2text-0.3.2}/setup.py +3 -3
  26. db2text-0.2.4/PKG-INFO +0 -37
  27. db2text-0.2.4/db2text/db/__init__.py +0 -1
  28. db2text-0.2.4/db2text.egg-info/PKG-INFO +0 -37
  29. db2text-0.2.4/db2text.egg-info/SOURCES.txt +0 -33
  30. db2text-0.2.4/db2text.egg-info/entry_points.txt +0 -3
  31. db2text-0.2.4/db2text.egg-info/top_level.txt +0 -2
  32. {db2text-0.2.4 → db2text-0.3.2}/LICENSE +0 -0
  33. {db2text-0.2.4 → db2text-0.3.2}/README.md +0 -0
  34. {db2text-0.2.4 → db2text-0.3.2}/db2text/__init__.py +0 -0
  35. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/sample/dbt_dot_mssql.txt +0 -0
  36. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/sample/dm/all.txt +0 -0
  37. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/sample/mysql/all.txt +0 -0
  38. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/sample/mysql/wiki.txt +0 -0
  39. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/sample/opengauss/all.txt +0 -0
  40. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/sample/oracle/all.txt +0 -0
  41. {db2text-0.2.4/database2text → db2text-0.3.2/db2text}/datafile/sample/sqlserver/all.txt +0 -0
  42. {db2text-0.2.4/database2text → db2text-0.3.2/db2text/db}/__init__.py +0 -0
  43. {db2text-0.2.4 → db2text-0.3.2}/db2text.egg-info/dependency_links.txt +0 -0
  44. {db2text-0.2.4 → db2text-0.3.2}/db2text.egg-info/requires.txt +0 -0
  45. {db2text-0.2.4 → db2text-0.3.2}/setup.cfg +0 -0
@@ -1 +1,2 @@
1
1
  recursive-include database2text/datafile *
2
+ recursive-include db2text/datafile *
db2text-0.3.2/PKG-INFO ADDED
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.1
2
+ Name: db2text
3
+ Version: 0.3.2
4
+ Summary: database to text
5
+ Home-page: https://gitee.com/chenc224/dbt
6
+ Author: Chen chuan
7
+ Author-email: kcchen@139.com
8
+ License: UNKNOWN
9
+ Description: # database to text
10
+
11
+ 数据库结构等导出到文本的工具。
12
+
13
+ 可以用来对数据库结构进行比较,检查变更,做版本控制等工作。
14
+
15
+ 也可以用来根据数据库结构自动生成文档,自动更新源代码等。
16
+
17
+ # 使用方法
18
+
19
+ ## 安装
20
+
21
+ 使用pip install db2text即可安装执行。注意这个工具在linux下开发调试,在windows使用如果有异常,请告知我。
22
+
23
+ ## 使用
24
+
25
+ 在命令行执行dbt即可。可以带参数指定命令文件,如果未指定,则使用当前目录下的dbt.txt文件。
26
+
27
+ 如果dbt跟系统内其它软件冲突,可以使用db2text,效果是相同的。
28
+
29
+ 详细的使用手册请参考
30
+
31
+ https://gitee.com/chenc224/dbt/blob/master/database2text/datafile/dbtmanual.md
32
+
33
+ Platform: UNKNOWN
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: OS Independent
37
+ Requires-Python: >=3.5
38
+ Description-Content-Type: text/markdown
@@ -4,10 +4,11 @@ __all__=["gd"]
4
4
 
5
5
  class gd(object): #全局数据
6
6
  #以下为设置项
7
- coding="utf8" #字符集,默认为utf8
8
- linebreak="\n" #检测到换行符,则替换掉这个,没检测到,使用这个默认的
9
- infolevel=1 #设置提示信息级别
10
- localinfolevel=1 #局部消息级别
7
+ coding="utf8" #字符集,默认为utf8
8
+ linebreak="\n" #检测到换行符,则替换掉这个,没检测到,使用这个默认的
9
+ infolevel=1 #设置提示信息级别
10
+ localinfolevel=1 #局部消息级别
11
+ replacelinebreak=":" #替换注释里的回车、回车换行和换行
11
12
 
12
13
  #以下为数据项
13
14
  oritext=[] #保存文本的初始值
@@ -28,6 +28,8 @@ struct stru_note_request {//消息请求队列 note_request
28
28
  | tjsj | datetime | | | 提交时间 |
29
29
  | clff | varchar(50) | 可 | | 处理方法 |
30
30
 
31
+ * 根据指定格式,把数据库结构等更新到mediawiki中,几乎无成本的使文档可以跟踪最新的结构变化。
32
+
31
33
  还有一个部分就是提供一个库,方便大家解析数据库,获取数据结构,进行一些自己的处理。dbt命令行工具可以认为就是用这个库写出来的一个应用吧。
32
34
 
33
35
  ## 安装
@@ -79,11 +81,15 @@ table= + abcd.*
79
81
 
80
82
  指定连接到哪种数据库,根据数据库的不同,后续的参数会有差异。具体参数可以参考样例文件。样例文件可以在https://gitee.com/chenc224/dbt/tree/master/database2text/datafile/sample 下察看。
81
83
 
82
- 增加使用dbcfg方法,这里的配置就容易一些,只用一行比如
84
+ 建议使用dbcfg方法,这里的配置就容易一些,只用一行比如
83
85
 
84
86
  `dbcfg=mysql234`
85
87
 
86
- 就可以了,后续会自动使用dbcfg来进行数据库连接。注意如果没有设置driver,则使用dbcfg设置中的db内容来作为driver使用。
88
+ 就可以了,后续会自动使用dbcfg来进行数据库连接。
89
+
90
+ 使用dbcfg可以不用设置driver,会用dbcfg设置中的db内容来作为driver使用。
91
+
92
+ dbcfg相关设置参考https://gitee.com/chenc224/dbcfg/blob/master/README.md
87
93
 
88
94
  ## readdata段
89
95
  读入数据库结构,具体数据格式细节随驱动器不同会有差异。
@@ -149,6 +155,10 @@ page设置的是页名称列表,每个页名称对应一个设置项,other
149
155
 
150
156
  每个页名称会生成一页pdf,最终合成得到一个多页的pdf。如果不需要多页pdf,可以不用设置page语句。
151
157
 
158
+ autosplit= 50
159
+
160
+ 自动分页设置,每多少个字段则自动分下一页
161
+
152
162
  ## wiki段
153
163
 
154
164
  生成wiki里的表格。如果指定wiki,可以直接用wiki机器人自动更新wiki内容。如果不指定wiki,则输出文本内容供粘贴。
@@ -196,7 +206,7 @@ level = 2 如果是一张新表,会在内容的最后增加这个表格,在
196
206
 
197
207
  # 设计思路
198
208
 
199
- dbt执行时根据dbt.txt里的内容执行相应处理。主要流程就是连接数据库、读取数据库结构、导出结构或者根据结构调整文本。这里连接数据库、读取数据库结构考虑设计成模块化的,这样可以方便替换不同的数据库。后续导出结构或者根据结构调整文本其实不同的数据库是基本类似的,差异可能只是数据结构有不同,所以这一部分设计成通用的。
209
+ dbt执行时根据dbt.txt里的内容执行相应处理。主要流程就是连接数据库、读取数据库结构、导出结构或者根据结构调整文本。这里连接数据库、读取数据库结构考虑设计成模块化的,方便替换不同的数据库。后续导出结构或者根据结构调整文本其实不同的数据库是基本类似的,差异可能只是数据结构有不同,所以这一部分设计成通用的。
200
210
 
201
211
  ## db2text 模块
202
212
 
@@ -1,26 +1,28 @@
1
- graph 表结构 {
2
- size = "8.5,11";
3
- margin=0;
4
- pad=0.1;
5
- page="8.5,11";
6
- # charset=utf8;
7
- ratio="fill"
8
- # dpi = 300
9
- # rankdir = "TR"
10
- # node[shape=record fontname="wqy-zenhei" size="30,30"]
11
- node[shape=plaintext fontname="wqy-zenhei"]
12
-
13
- {% for t in TABLE %}
14
- {{ t.tname }} [
15
- label=<
16
- <table border="1" cellborder="0">
17
- <tr><td colspan="3">{{ t.tdesc }} {{ t.tname }}</td></tr>
18
- {%- for c in t.md %}
19
- <tr><td align="left">{{ c.desc }}</td><td align="left">{{ c.pk and '<u>' or ''}}{{ c.name }}{{ c.pk and '</u>' or ''}}</td><td align="left">{{ c.ts }}</td></tr>
20
- {%- endfor %}
21
- </table>
22
- >
23
- ]
24
- {% endfor %}
25
-
26
- }
1
+ #模板文件,用于生成graphviz文件,再生成pdf
2
+
3
+ graph 表结构 {
4
+ size = "8.27,11.69";
5
+ margin=0;
6
+ pad=0.1;
7
+ page="8.27,11.69";
8
+ # charset=utf8;
9
+ ratio="fill"
10
+ # dpi = 300
11
+ # rankdir = "TR"
12
+ # node[shape=record fontname="wqy-zenhei" size="30,30"]
13
+ node[shape=plaintext fontname="wqy-zenhei"]
14
+
15
+ {% for t in TABLE %}
16
+ {{ t.tname }} [
17
+ label=<
18
+ <table border="1" cellborder="0">
19
+ <tr><td colspan="3">{{ t.tdesc }} {{ t.tname }}</td></tr>
20
+ {%- for c in t.md %}
21
+ <tr><td align="left">{{ c.desc }}</td><td align="left">{{ c.pk and '<u>' or ''}}{{ c.name }}{{ c.pk and '</u>' or ''}}</td><td align="left">{{ c.ts }}</td></tr>
22
+ {%- endfor %}
23
+ </table>
24
+ >
25
+ ]
26
+ {% endfor %}
27
+
28
+ }
@@ -0,0 +1,41 @@
1
+ #基础说明可参考https://gitee.com/chenc224/dbt/blob/master/database2text/datafile/usermenual.md
2
+ #sample for oceanbase
3
+ #oceanbase的样例文件
4
+ #号开头的行为注释,并不需要处理
5
+ #冒号开头的行表示一段内容的开始,直到另外一个冒号或者是文件尾
6
+ #执行时扫描配置文件,把每一段的内容传递给相应的处理函数处理
7
+ :connect
8
+
9
+ dbcfg=sms2
10
+
11
+ :readdata
12
+
13
+ :export
14
+ #export段设置导出数据库里的相应内容为文本文件
15
+ datadir=local/oceanbase/export
16
+
17
+ :render
18
+ file=local/oceanbase/all.md
19
+ help=n
20
+ #使用help=y可以打印出传入模板的数据,方便写模板的时候使用
21
+ #下面是模板样例,jinja2模板库,这个样例是根据表定义一个c语言的结构,用于pro*c使用
22
+ start=## {{ tname }}
23
+ ## {{ tname }} {{ tdesc }}
24
+ | 字段名 | 类型 | 长度 | 空 | 默认值 | 说明 |
25
+ | :---- | :---- | ----: | :---- | :---- | :---- |
26
+ {% for c in ori %}| {{ c.COLUMN_NAME }} | {{ c.DATA_TYPE }} | {{ c.DATA_LENGTH }} | {% if c.NULLABLE == "Y" %}可{% endif %} | {{ c.DATA_DEFAULT or "" }} | {{ c.COLUMN_COMMENT }} |
27
+ {% endfor %}
28
+ end=
29
+
30
+ #根据模板生成dot文件,调用neato生成pdf文件
31
+ :dot
32
+ #cmd=neato -Tpdf test/oracle/all.dot -o local/oracle/alldot.pdf
33
+ dotdir=test/oceanbase
34
+ pdfdir=local/oceanbase
35
+ filename=all
36
+ dotcmd=neato
37
+ #可以选择dot,neato,twopi,circo,fdp,sfdp,patchwork和osage指定graphviz布局算法
38
+
39
+ #dot生成多页pdf的例子
40
+
41
+ :end
@@ -0,0 +1,20 @@
1
+ # 数据备份相关表
2
+ :connect
3
+
4
+ dbcfg=sjbf
5
+
6
+ :readdata
7
+
8
+ :dot
9
+ dotdir=test/oceanbase
10
+ pdfdir=local/oceanbase
11
+ filename=sjbf
12
+ dotcmd=neato
13
+
14
+ :wiki
15
+ title = name:字段名 desc:注释 ts:类型 default:默认值 :说明
16
+ wiki=wiki
17
+ page=数据备份脚本
18
+ level=2
19
+
20
+ :end
@@ -0,0 +1,25 @@
1
+ #cc库模板文件
2
+
3
+ :connect
4
+
5
+ dbcfg=cc@cc
6
+
7
+ :readdata
8
+
9
+ # 系统监控用户
10
+ owner=XTJK
11
+
12
+
13
+ #根据模板生成dot文件,调用fdp生成pdf文件
14
+ :dot
15
+ dotdir=test/oracle
16
+ pdfdir=local/oracle
17
+ page=备份 其它
18
+ 备份= .*BF.*
19
+ filename=xtjk
20
+ dotcmd=fdp
21
+ #可以选择dot,neato,twopi,circo,fdp,sfdp,patchwork和osage指定graphviz布局算法
22
+ autosplit = 50
23
+ #每50行分一页
24
+
25
+ :end
@@ -1,4 +1,4 @@
1
- #基础说明可参考https://gitee.com/chenc224/dbt/blob/master/database2text/datafile/usermenual.md
1
+ #基础说明可参考https://gitee.com/chenc224/dbt/blob/master/db2text/datafile/dbtmanual.md
2
2
  #sample for oracle 11
3
3
  #oracle11的样例文件
4
4
  #号开头的行为注释,并不需要处理
@@ -0,0 +1,21 @@
1
+ #cc库sms用户
2
+
3
+ :connect
4
+
5
+ dbcfg=cc@cc
6
+
7
+ :readdata
8
+
9
+ table= + .* - rtyg .*ygxx.* ye jjjkwj sztwj jjjkzd hm1231 hm2 rsts ygzj dxx20.*
10
+
11
+ #根据模板生成dot文件,调用fdp生成pdf文件
12
+ :dot
13
+ dotdir=test/oracle
14
+ pdfdir=local/oracle
15
+ filename=sms
16
+ dotcmd=fdp
17
+ #可以选择dot,neato,twopi,circo,fdp,sfdp,patchwork和osage指定graphviz布局算法
18
+ autosplit = 50
19
+ #每50行分一页
20
+
21
+ :end
@@ -2,8 +2,8 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  import sys,cx_Oracle,json
5
- import database2text.tool as dbtt
6
- from database2text.tool import *
5
+ import db2text.tool as dbtt
6
+ from db2text.tool import *
7
7
 
8
8
  class dm(object):
9
9
  def ana_TABLE(otype):
@@ -17,7 +17,7 @@ class dm(object):
17
17
  md=[] #markdown等用的字段数据,每字段一个字典,包括 "name": 字段名,"desc": 注释,"type": 数据类型,"size":字段长度,"null":True of False,是否可为空,"default":默认值
18
18
  maxcsize=db.res1("select max(length(column_name)) from all_tab_cols where owner='%s' and table_name='%s'" %(owner,oname))
19
19
  tdesc=db.res1("select comments from all_tab_comments where owner=:1 and table_name=:2",[owner,oname])
20
- if not tdesc:tdesc=""
20
+ tdesc=dt.replacelinebreak(tdesc)
21
21
  oridata=[]
22
22
  for col in db.exec2("select * from all_tab_cols where owner='%s' and table_name='%s' order by column_id" %(owner,oname)):
23
23
  col["COLUMN_COMMENT"]=db.res1("select comments from all_col_comments where table_name=:1 and column_name=:2 and owner=:3",[oname,col["COLUMN_NAME"],owner])
@@ -28,7 +28,7 @@ class dm(object):
28
28
  odata=odata+" %s%*s" %(column_name,maxcsize-len(column_name)+1," ")
29
29
  ctype="char"
30
30
  desc=db.res1("select comments from all_col_comments where table_name=:1 and column_name=:2 and owner=:3",[oname,column_name,owner])
31
- if not desc:desc=""
31
+ desc=dt.replacelinebreak(desc)
32
32
  if data_type in ("NUMBER","NUMERIC"):
33
33
  if data_precision is not None and data_scale is not None:
34
34
  if data_scale==0:
@@ -2,8 +2,9 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  import sys
5
- import database2text.tool as dbtt
6
- from database2text.tool import *
5
+ import db2text.tool as dbtt
6
+ from db2text.tool import *
7
+ import db2text as dt
7
8
 
8
9
  __all__=["connect","readdata"]
9
10
 
@@ -24,6 +25,7 @@ class mssql(object):
24
25
  print(f"{catalog}.{schema}.{表名} 找不到表id")
25
26
  continue
26
27
  表注释=db.res1(f"select value from sys.extended_properties where major_id={表id} and class=1 and name='MS_Description'") or ""
28
+ 表注释=dt.replacelinebreak(表注释)
27
29
  主键名=db.res1(f"SELECT k.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS c JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS k ON c.CONSTRAINT_TYPE = 'PRIMARY KEY' AND c.CONSTRAINT_NAME = k.CONSTRAINT_NAME WHERE c.TABLE_NAME = '{表名}'")
28
30
  主键列=[]
29
31
  if 主键名:
@@ -34,6 +36,7 @@ class mssql(object):
34
36
  for i in db.exec2(f"select * from sys.columns where object_id={表id} order by column_id"):
35
37
  原始信息.append(i)
36
38
  字段描述=db.res1(f"select value from sys.extended_properties where major_id={i['object_id']} and minor_id={i['column_id']}")
39
+ 字段描述=dt.replacelinebreak(字段描述 or "")
37
40
  字段类型=db.res1(f"select name from sys.types where system_type_id={i['system_type_id']} and user_type_id={i['user_type_id']}")
38
41
  if i["precision"]==0: #字符型
39
42
  ts=f"{字段类型}({i['max_length']})"
@@ -67,4 +70,3 @@ def connect(arg):
67
70
  return db.conn
68
71
  else:
69
72
  return dbtt.connect(arg,"pytds")
70
-
@@ -2,8 +2,9 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  import sys,pymysql,dbcfg
5
- import database2text.tool as dbtt
6
- from database2text.tool import *
5
+ import db2text.tool as dbtt
6
+ from db2text.tool import *
7
+ import db2text as dt
7
8
 
8
9
  class mysql(object):
9
10
  def ana_TABLE(otype):
@@ -15,6 +16,7 @@ class mysql(object):
15
16
  oridata=[]
16
17
  coldata=[]
17
18
  tdesc=db.res1("SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME ='%s' AND TABLE_SCHEMA = '%s'" %(oname,database))
19
+ tdesc=dt.replacelinebreak(tdesc)
18
20
  主键列=[]
19
21
  for pkcol, in db.exec(f"select column_name from information_schema.key_column_usage where TABLE_SCHEMA='{database}' and table_name='{oname}' and constraint_name='PRIMARY'"):
20
22
  主键列.append(pkcol)
@@ -33,6 +35,7 @@ class mysql(object):
33
35
  oridata=[]
34
36
  coldata=[]
35
37
  tdesc=db.res1("SELECT TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME ='%s' AND TABLE_SCHEMA = '%s'" %(oname,database))
38
+ tdesc=dt.replacelinebreak(tdesc)
36
39
  md=[] #markdown等用的字段数据,每字段一个字典
37
40
  for i in db.exec2(f"select * from information_schema.COLUMNS where TABLE_SCHEMA='{database}' and table_name='{oname}' order by ORDINAL_POSITION"):
38
41
  oridata.append(i)
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+
4
+ import sys,json
5
+ import db2text.tool as dbtt
6
+ from db2text.tool import *
7
+ import db2text as dt
8
+
9
+ class oracle(object):
10
+ def ana_TABLE(otype):
11
+ for oname, in db.exec("select object_name from all_objects where object_type=:ot and owner=:owner order by 1",ot=otype,owner=owner):
12
+ if 检查匹配(otype,oname):
13
+ continue
14
+ if oname.startswith("SYS_EXPORT_TABLE"):
15
+ continue
16
+ odata="create table %s\n(\n" %(oname)
17
+ coldata=[] #记录列数据,包括type类型,name列名,desc注释信息,size长度,ns名称+长度如name[5]这样
18
+ md=[] #markdown等用的字段数据,每字段一个字典,包括 "name": 字段名,"desc": 注释,"type": 数据类型,"size":字段长度,"null":True of False,是否可为空,"default":默认值
19
+ maxcsize=db.res1("select max(length(column_name)) from all_tab_cols where owner='%s' and table_name='%s'" %(owner,oname))
20
+ tdesc=db.res1("select comments from all_tab_comments where owner=:1 and table_name=:2",[owner,oname])
21
+ if not tdesc:tdesc=""
22
+ tdesc=dt.replacelinebreak(tdesc)
23
+ oridata=[]
24
+ for col in db.exec2("select * from all_tab_cols where owner='%s' and table_name='%s' order by column_id" %(owner,oname)):
25
+ col["COLUMN_COMMENT"]=db.res1("select comments from all_col_comments where table_name=:1 and column_name=:2 and owner=:3",[oname,col["COLUMN_NAME"],owner])
26
+ if col["DATA_DEFAULT"]!=None:
27
+ col["DATA_DEFAULT"]=col["DATA_DEFAULT"].strip()
28
+ oridata.append(col)
29
+ for column_name,data_type,char_length,data_precision,data_scale,nullable,default_length,data_default in db.exec("select column_name,data_type,char_length,data_precision,data_scale,nullable,default_length,data_default from all_tab_cols where owner='%s' and table_name='%s' order by column_id" %(owner,oname)):
30
+ if data_default:
31
+ data_default=data_default.strip()
32
+ odata=odata+" %s%*s" %(column_name,maxcsize-len(column_name)+1," ")
33
+ ctype="char"
34
+ desc=db.res1("select comments from all_col_comments where table_name=:1 and column_name=:2 and owner=:3",[oname,column_name,owner])
35
+ if not desc:desc=""
36
+ desc=dt.replacelinebreak(desc)
37
+ if data_type=="NUMBER":
38
+ if data_precision is not None and data_scale is not None:
39
+ if data_scale==0:
40
+ if data_precision<8:ctype="int"
41
+ else:ctype="long"
42
+ odata=odata+"NUMBER(%d)" %(data_precision)
43
+ ts=f"NUMBER({data_precision})"
44
+ else:
45
+ ctype="double"
46
+ odata=odata+"NUMBER(%d,%d)" %(data_precision,data_scale)
47
+ ts=f"NUMBER({data_precision}.{data_scale})"
48
+ elif data_precision is None and data_scale==0:
49
+ ctype="long"
50
+ odata=odata+"INTEGER"
51
+ ts="INTEGER"
52
+ elif char_length==0:
53
+ ctype="long"
54
+ odata=odata+"NUMBER"
55
+ ts="INTEGER"
56
+ else:
57
+ print("table %s column %s type %s length %s %s %s" %(oname,column_name,data_type,char_length,data_precision,data_scale))
58
+ sys.exit(-1)
59
+ cns=column_name
60
+ elif data_type in ("VARCHAR2","VARCHAR","CHAR","NVARCHAR2","NVARCHAR"):
61
+ if char_length==1:
62
+ ts=data_type
63
+ else:
64
+ ts=f"{data_type}({char_length})"
65
+ cns="%s[%d]" %(column_name,char_length+1)
66
+ odata=odata+"%s(%d)" %(data_type,char_length)
67
+ elif data_type.startswith("TIMESTAMP"):
68
+ cns="%s[20]" %(column_name)
69
+ odata=odata+"%s" %(data_type)
70
+ ts=data_type
71
+ elif data_type in("DATE"):
72
+ cns="%s[20]" %(column_name)
73
+ odata=odata+"%s" %(data_type)
74
+ ts=data_type
75
+ elif data_type in("CLOB","BLOB","NCLOB","LONG","RAW"):
76
+ cns="%s[2000]" %(column_name)
77
+ odata=odata+"%s" %(data_type)
78
+ ts=data_type
79
+ elif data_type in ("FLOAT"):
80
+ ctype="double"
81
+ odata=odata+"FLOAT(%d)" %(data_precision)
82
+ ts=data_type
83
+ elif data_type in ("ROWID"):
84
+ cns="%s[100]" %(column_name)
85
+ odata=odata+"%s" %(data_type)
86
+ ts=data_type
87
+ else:
88
+ print("table %s column %s type %s length %s %s %s" %(oname,column_name,data_type,char_length,data_precision,data_scale))
89
+ sys.exit(-1)
90
+ if default_length:
91
+ odata=odata+" default %s" %(data_default)
92
+ if nullable=="N":
93
+ odata=odata+" not null"
94
+ odata=odata+",\n"
95
+ cns2=cns
96
+ if data_type in ("VARCHAR2","VARCHAR","CHAR","NVARCHAR2","NVARCHAR") and char_length==1:
97
+ cns=column_name
98
+ coldata.append({"type":ctype,"name":column_name,"ns":cns,"ns2":cns2,"desc":desc})
99
+ 主键列=[]
100
+ for pkcol, in db.exec(f"SELECT cols.column_name FROM user_constraints cons, user_cons_columns cols WHERE cons.constraint_type = 'P' AND cons.constraint_name = cols.constraint_name AND cons.owner = cols.owner and cons.owner = '{owner}' AND cols.table_name = '{oname}'"):
101
+ 主键列.append(pkcol)
102
+ md.append({"name":column_name,"desc":desc,"type":data_type,"size":char_length, "null":nullable=="N", "default":data_default,"ts":ts, "pk":column_name in 主键列})
103
+ odata=odata[:-2]
104
+ odata=odata+"\n);"
105
+ dbdata["sql"]["TABLE"][oname]=odata
106
+ dbdata["exp"]["TABLE"].append({"tname":oname,"tdesc":tdesc,"ori":oridata,"c":coldata,"md":md})
107
+
108
+ def ana_VIEW(otype):
109
+ for oname, in db.exec("select object_name from user_objects where object_type=:ot",ot=otype):
110
+ if "view" in stdata and oname.lower() not in stdata["view"].split() and oname not in stdata["view"].split():
111
+ continue
112
+ dbdata["sql"][otype][oname]=oracle.getobjtext(otype,oname)
113
+
114
+ def getobjtext(otype,oname):
115
+ c=db.conn.cursor()
116
+ try:
117
+ c.callproc('DBMS_METADATA.SET_TRANSFORM_PARAM',(-1, 'TABLESPACE',False))
118
+ c.callproc("DBMS_METADATA.SET_TRANSFORM_PARAM",(-1,'STORAGE',False))
119
+ c.callproc("DBMS_METADATA.SET_TRANSFORM_PARAM",(-1,'SEGMENT_ATTRIBUTES',False))
120
+ c.callproc("DBMS_METADATA.SET_TRANSFORM_PARAM",(-1,'PRETTY',False))
121
+ except:
122
+ pass
123
+ ssql=db.res1("SELECT dbms_metadata.get_ddl(:otype,:oname) FROM DUAL",otype=otype,oname=oname).read()
124
+ return ssql
125
+
126
+ def readdata(arg):
127
+ global owner
128
+ dbdata["sql"]={}
129
+ dbdata["exp"]={}
130
+ if "owner" in arg:
131
+ owner=arg["owner"]
132
+ for i in vars(oracle):
133
+ if i.startswith("ana_"):
134
+ otype=i[4:]
135
+ dbdata["sql"][otype]={}
136
+ dbdata["exp"][otype]=[]
137
+ getattr(oracle,i)(otype)
138
+
139
+ def connect(arg):
140
+ global owner
141
+ if "dbcfg" in stdata:
142
+ db.conn=dbtt.dbc.connect()
143
+ if "owner" in stdata:
144
+ owner=stdata["owner"]
145
+ else:
146
+ owner=db.res1("select user from dual")
147
+
148
+ __all__=[]
@@ -2,8 +2,8 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  import sys,dbcfg
5
- import database2text.tool as dbtt
6
- from database2text.tool import *
5
+ import db2text.tool as dbtt
6
+ from db2text.tool import *
7
7
 
8
8
  字段类型={}
9
9
 
@@ -2,8 +2,9 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  import sys,cx_Oracle,json
5
- import database2text.tool as dbtt
6
- from database2text.tool import *
5
+ import db2text.tool as dbtt
6
+ from db2text.tool import *
7
+ import db2text as dt
7
8
 
8
9
  class oracle(object):
9
10
  def ana_TABLE(otype):
@@ -18,6 +19,7 @@ class oracle(object):
18
19
  maxcsize=db.res1("select max(length(column_name)) from all_tab_cols where owner='%s' and table_name='%s'" %(owner,oname))
19
20
  tdesc=db.res1("select comments from all_tab_comments where owner=:1 and table_name=:2",[owner,oname])
20
21
  if not tdesc:tdesc=""
22
+ tdesc=dt.replacelinebreak(tdesc)
21
23
  oridata=[]
22
24
  for col in db.exec2("select * from all_tab_cols where owner='%s' and table_name='%s' order by column_id" %(owner,oname)):
23
25
  col["COLUMN_COMMENT"]=db.res1("select comments from all_col_comments where table_name=:1 and column_name=:2 and owner=:3",[oname,col["COLUMN_NAME"],owner])
@@ -25,10 +27,13 @@ class oracle(object):
25
27
  col["DATA_DEFAULT"]=col["DATA_DEFAULT"].strip()
26
28
  oridata.append(col)
27
29
  for column_name,data_type,char_length,data_precision,data_scale,nullable,default_length,data_default in db.exec("select column_name,data_type,char_length,data_precision,data_scale,nullable,default_length,data_default from all_tab_cols where owner='%s' and table_name='%s' order by column_id" %(owner,oname)):
30
+ if data_default:
31
+ data_default=data_default.strip()
28
32
  odata=odata+" %s%*s" %(column_name,maxcsize-len(column_name)+1," ")
29
33
  ctype="char"
30
34
  desc=db.res1("select comments from all_col_comments where table_name=:1 and column_name=:2 and owner=:3",[oname,column_name,owner])
31
35
  if not desc:desc=""
36
+ desc=dt.replacelinebreak(desc)
32
37
  if data_type=="NUMBER":
33
38
  if data_precision is not None and data_scale is not None:
34
39
  if data_scale==0:
@@ -83,7 +88,7 @@ class oracle(object):
83
88
  print("table %s column %s type %s length %s %s %s" %(oname,column_name,data_type,char_length,data_precision,data_scale))
84
89
  sys.exit(-1)
85
90
  if default_length:
86
- odata=odata+" default %s" %(data_default.strip())
91
+ odata=odata+" default %s" %(data_default)
87
92
  if nullable=="N":
88
93
  odata=odata+" not null"
89
94
  odata=odata+",\n"
@@ -2,8 +2,8 @@
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
4
  import sys,importlib,os,shutil,dbcfg
5
- import database2text.tool as dbtt
6
- from database2text.tool import *
5
+ import db2text.tool as dbtt
6
+ from db2text.tool import *
7
7
  import db2text as dt
8
8
 
9
9
  def 读文件():
@@ -12,8 +12,8 @@ def 读文件():
12
12
  if len(sys.argv)>1:
13
13
  fn=sys.argv[1]
14
14
  if not os.path.isfile(fn):
15
- print("can't open %s. you must create it or tell us another file name." %(fn))
16
- print("for help, you may need the file in %s" %(os.path.join(os.path.dirname(os.path.abspath(dbtt.__file__)),"datafile")))
15
+ print(f"无法打开文件{fn}. 你可以生成一个模块文件或者在命令行指定一个模板文件")
16
+ print("可以在目录%s下查看帮助和模板文件样例" %(os.path.join(os.path.dirname(os.path.abspath(dt.__file__)),"datafile")))
17
17
  sys.exit(-1)
18
18
  f=open(fn,"rb")
19
19
  if fn.endswith("md"):
@@ -43,12 +43,12 @@ def main():
43
43
  if section=="global":
44
44
  文件编码=stdata.get("code") or stdata.get("coding") or 文件编码
45
45
  if section in ["connect","global"] and "driver" in stdata:
46
- dbt=importlib.import_module('database2text.%s' %(stdata["driver"]))
46
+ dbt=importlib.import_module('db2text.db.%s' %(stdata["driver"]))
47
47
  if section == "connect" and "dbcfg" in stdata:
48
48
  dbtt.dbc=dbcfg.use(stdata["dbcfg"],ehm=2)
49
49
  dbtt.cfg=dbtt.dbc.cfg()
50
50
  if "driver" not in stdata:
51
- dbt=importlib.import_module('database2text.%s' %(驱动表.get(dbtt.cfg["db"],dbtt.cfg["db"])))
51
+ dbt=importlib.import_module('db2text.db.%s' %(驱动表.get(dbtt.cfg["db"],dbtt.cfg["db"])))
52
52
  if section!="global":
53
53
  if not dbt:
54
54
  print("需要在配置文件里设置driver")
@@ -5,7 +5,7 @@ import sys,os,difflib,jinja2,re,json,datetime,importlib,pathlib
5
5
  import db2text as dt
6
6
  from pprint import pprint
7
7
 
8
- __all__=["db","ckd","dbdata","storidata","stdata","检查匹配","cpt"]
8
+ __all__=["db","ckd","dbdata","storidata","stdata","检查匹配"]
9
9
 
10
10
  def mkdir(dirname):
11
11
  if not os.path.isdir(dirname):
@@ -15,10 +15,6 @@ def quit(errinfo,exitcode=0):
15
15
  print(errinfo)
16
16
  sys.exit(exitcode)
17
17
 
18
- def cpt(t):
19
- import json
20
- print(json.dumps(t,ensure_ascii=False,skipkeys=False,indent=2))
21
-
22
18
  class ComplexEncoder(json.JSONEncoder):
23
19
  def default(self, obj):
24
20
  if isinstance(obj, datetime.datetime):
@@ -118,7 +114,7 @@ class export(object):
118
114
 
119
115
  class dot(object):
120
116
  def __init__(self,arg):
121
- 模板文件=pathlib.Path.joinpath(pathlib.Path(__file__).parent,"datafile","dot.mb")
117
+ 模板文件=os.path.join(os.path.dirname(os.path.abspath(dt.__file__)),"datafile","dot.mb")
122
118
  模板=open(模板文件,encoding="utf8").read()
123
119
  分页数据=[]
124
120
  for page in arg.get("page","其它").split():
@@ -163,6 +159,8 @@ class dot(object):
163
159
  pdfname=os.path.join(arg.get("pdfdir","."),f"{arg['filename']}.pdf")
164
160
  with open(pdfname,"wb") as fout:
165
161
  pdfout.write(fout)
162
+ for i in pdf列表:
163
+ os.unlink(i)
166
164
 
167
165
  class render(object):
168
166
  def __init__(self,arg):
@@ -1,7 +1,7 @@
1
- __all__=["inittext","p","capture","mergecolumndata","createcolumndata","replacenewdata","analydata","printdiff"]
1
+ __all__=["inittext","p","capture","mergecolumndata","createcolumndata","replacenewdata","analydata","printdiff","replacelinebreak"]
2
2
 
3
3
  import db2text as dt
4
- import time,copy,difflib
4
+ import time,copy,difflib,re
5
5
  from pprint import pprint
6
6
 
7
7
  def inittext(text):
@@ -111,3 +111,9 @@ def printdiff(t1,t2):
111
111
  '显示t1和t2这两个列表之间的文本差异'
112
112
  diff=difflib.Differ()
113
113
  print("\n".join(difflib.context_diff(t1,t2)))
114
+
115
+ def replacelinebreak(t):
116
+ '替换回车、回车换行、换行为dt.gd.replacelinebreak'
117
+ if not t: #如果t为空,返回空串
118
+ return ""
119
+ return re.sub(r"\r\n|\r|\n", dt.gd.replacelinebreak, t)
@@ -0,0 +1,38 @@
1
+ Metadata-Version: 2.1
2
+ Name: db2text
3
+ Version: 0.3.2
4
+ Summary: database to text
5
+ Home-page: https://gitee.com/chenc224/dbt
6
+ Author: Chen chuan
7
+ Author-email: kcchen@139.com
8
+ License: UNKNOWN
9
+ Description: # database to text
10
+
11
+ 数据库结构等导出到文本的工具。
12
+
13
+ 可以用来对数据库结构进行比较,检查变更,做版本控制等工作。
14
+
15
+ 也可以用来根据数据库结构自动生成文档,自动更新源代码等。
16
+
17
+ # 使用方法
18
+
19
+ ## 安装
20
+
21
+ 使用pip install db2text即可安装执行。注意这个工具在linux下开发调试,在windows使用如果有异常,请告知我。
22
+
23
+ ## 使用
24
+
25
+ 在命令行执行dbt即可。可以带参数指定命令文件,如果未指定,则使用当前目录下的dbt.txt文件。
26
+
27
+ 如果dbt跟系统内其它软件冲突,可以使用db2text,效果是相同的。
28
+
29
+ 详细的使用手册请参考
30
+
31
+ https://gitee.com/chenc224/dbt/blob/master/database2text/datafile/dbtmanual.md
32
+
33
+ Platform: UNKNOWN
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Operating System :: OS Independent
37
+ Requires-Python: >=3.5
38
+ Description-Content-Type: text/markdown
@@ -0,0 +1,37 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ setup.py
5
+ db2text/__init__.py
6
+ db2text/data.py
7
+ db2text/dbt.py
8
+ db2text/tool.py
9
+ db2text/util.py
10
+ db2text.egg-info/PKG-INFO
11
+ db2text.egg-info/SOURCES.txt
12
+ db2text.egg-info/dependency_links.txt
13
+ db2text.egg-info/entry_points.txt
14
+ db2text.egg-info/not-zip-safe
15
+ db2text.egg-info/requires.txt
16
+ db2text.egg-info/top_level.txt
17
+ db2text/datafile/dbtmanual.md
18
+ db2text/datafile/dot.mb
19
+ db2text/datafile/sample/dbt_dot_mssql.txt
20
+ db2text/datafile/sample/dm/all.txt
21
+ db2text/datafile/sample/mysql/all.txt
22
+ db2text/datafile/sample/mysql/wiki.txt
23
+ db2text/datafile/sample/oceanbase/all.txt
24
+ db2text/datafile/sample/oceanbase/sjbf.txt
25
+ db2text/datafile/sample/opengauss/all.txt
26
+ db2text/datafile/sample/oracle/all.txt
27
+ db2text/datafile/sample/oracle/cc.txt
28
+ db2text/datafile/sample/oracle/crmrpt.txt
29
+ db2text/datafile/sample/oracle/sms.txt
30
+ db2text/datafile/sample/sqlserver/all.txt
31
+ db2text/db/__init__.py
32
+ db2text/db/dm.py
33
+ db2text/db/mssql.py
34
+ db2text/db/mysql.py
35
+ db2text/db/ob_oracle.py
36
+ db2text/db/opengauss.py
37
+ db2text/db/oracle11.py
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ db2text = db2text.dbt:main
3
+ dbt = db2text.dbt:main
4
+
@@ -0,0 +1 @@
1
+ db2text
@@ -8,7 +8,7 @@ with open("README.md", "r",encoding='utf-8') as fh:
8
8
 
9
9
  setuptools.setup(
10
10
  name="db2text",
11
- version="0.2.4",
11
+ version="0.3.2",
12
12
  author="Chen chuan",
13
13
  author_email="kcchen@139.com",
14
14
  description="database to text",
@@ -30,8 +30,8 @@ setuptools.setup(
30
30
  include_package_data = True,
31
31
  entry_points={
32
32
  'console_scripts': [
33
- 'dbt=database2text.dbt:main',
34
- 'db2text=database2text.dbt:main',
33
+ 'dbt=db2text.dbt:main',
34
+ 'db2text=db2text.dbt:main',
35
35
  ],
36
36
  },
37
37
  )
db2text-0.2.4/PKG-INFO DELETED
@@ -1,37 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: db2text
3
- Version: 0.2.4
4
- Summary: database to text
5
- Home-page: https://gitee.com/chenc224/dbt
6
- Author: Chen chuan
7
- Author-email: kcchen@139.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.5
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
-
15
- # database to text
16
-
17
- 数据库结构等导出到文本的工具。
18
-
19
- 可以用来对数据库结构进行比较,检查变更,做版本控制等工作。
20
-
21
- 也可以用来根据数据库结构自动生成文档,自动更新源代码等。
22
-
23
- # 使用方法
24
-
25
- ## 安装
26
-
27
- 使用pip install db2text即可安装执行。注意这个工具在linux下开发调试,在windows使用如果有异常,请告知我。
28
-
29
- ## 使用
30
-
31
- 在命令行执行dbt即可。可以带参数指定命令文件,如果未指定,则使用当前目录下的dbt.txt文件。
32
-
33
- 如果dbt跟系统内其它软件冲突,可以使用db2text,效果是相同的。
34
-
35
- 详细的使用手册请参考
36
-
37
- https://gitee.com/chenc224/dbt/blob/master/database2text/datafile/dbtmanual.md
@@ -1 +0,0 @@
1
- print("util.init")
@@ -1,37 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: db2text
3
- Version: 0.2.4
4
- Summary: database to text
5
- Home-page: https://gitee.com/chenc224/dbt
6
- Author: Chen chuan
7
- Author-email: kcchen@139.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.5
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
-
15
- # database to text
16
-
17
- 数据库结构等导出到文本的工具。
18
-
19
- 可以用来对数据库结构进行比较,检查变更,做版本控制等工作。
20
-
21
- 也可以用来根据数据库结构自动生成文档,自动更新源代码等。
22
-
23
- # 使用方法
24
-
25
- ## 安装
26
-
27
- 使用pip install db2text即可安装执行。注意这个工具在linux下开发调试,在windows使用如果有异常,请告知我。
28
-
29
- ## 使用
30
-
31
- 在命令行执行dbt即可。可以带参数指定命令文件,如果未指定,则使用当前目录下的dbt.txt文件。
32
-
33
- 如果dbt跟系统内其它软件冲突,可以使用db2text,效果是相同的。
34
-
35
- 详细的使用手册请参考
36
-
37
- https://gitee.com/chenc224/dbt/blob/master/database2text/datafile/dbtmanual.md
@@ -1,33 +0,0 @@
1
- LICENSE
2
- MANIFEST.in
3
- README.md
4
- setup.py
5
- database2text/__init__.py
6
- database2text/dbt.py
7
- database2text/dm.py
8
- database2text/mssql.py
9
- database2text/mysql.py
10
- database2text/opengauss.py
11
- database2text/oracle11.py
12
- database2text/tool.py
13
- database2text/datafile/dbtmanual.md
14
- database2text/datafile/dot.mb
15
- database2text/datafile/sample/dbt_dot_mssql.txt
16
- database2text/datafile/sample/dm/all.txt
17
- database2text/datafile/sample/mysql/all.txt
18
- database2text/datafile/sample/mysql/wiki.txt
19
- database2text/datafile/sample/opengauss/all.txt
20
- database2text/datafile/sample/oracle/all.txt
21
- database2text/datafile/sample/oracle/crmrpt.txt
22
- database2text/datafile/sample/sqlserver/all.txt
23
- db2text/__init__.py
24
- db2text/data.py
25
- db2text/util.py
26
- db2text.egg-info/PKG-INFO
27
- db2text.egg-info/SOURCES.txt
28
- db2text.egg-info/dependency_links.txt
29
- db2text.egg-info/entry_points.txt
30
- db2text.egg-info/not-zip-safe
31
- db2text.egg-info/requires.txt
32
- db2text.egg-info/top_level.txt
33
- db2text/db/__init__.py
@@ -1,3 +0,0 @@
1
- [console_scripts]
2
- db2text = database2text.dbt:main
3
- dbt = database2text.dbt:main
@@ -1,2 +0,0 @@
1
- database2text
2
- db2text
File without changes
File without changes
File without changes
File without changes