移动test文件到test目录

This commit is contained in:
HKS 2024-02-20 13:54:44 +08:00
parent 822e18e6a5
commit 35344439b6
8 changed files with 25 additions and 11 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/log/
/NEWGDB/
/NEWMDO/

View File

@ -6,5 +6,6 @@
<file url="file://$PROJECT_DIR$/log/2023-05-27 15-11-29-Translate2Old.txt" charset="GBK" />
<file url="file://$PROJECT_DIR$/log/2023-05-27 15-20-40-Translate2Old.txt" charset="GBK" />
<file url="file://$PROJECT_DIR$/log/2023-05-27 15-32-50-SdeSynchronous.txt" charset="GBK" />
<file url="file://$PROJECT_DIR$/log/2023-05-29 17-11-32-SdeSynchronous.txt" charset="GBK" />
</component>
</project>

View File

@ -1,3 +0,0 @@
{
"python.pythonPath": "c:\\Python27\\ArcGIS10.2\\python.exe"
}

View File

@ -21,8 +21,10 @@ if __name__ == '__main__':
curr_sync_time = time.strftime("%H-%M-%S", time.localtime())
# 设置当前工作路径
config = SysConfig()
config.pathname = work_pathname
config.pathname = work_pathname.decode('gb2312')
config.curr_sync_datetime = curr_sync_date + " " + curr_sync_time
print(work_pathname.decode('gb2312'))
# 日志记录
create_dir(work_pathname + "\\log")
config.logfile_name = work_pathname + "\\log\\" + config.curr_sync_datetime + "-SdeSynchronous.txt"

4
run.bat Normal file
View File

@ -0,0 +1,4 @@
@echo off
cd /d %~dp0
C:/Python27/ArcGIS10.2/python.exe main.py
pause

View File

@ -28,12 +28,12 @@ class SdeSynchronous:
def run(self):
"""同步的主函数"""
# 1.连接SDE数据库
self.src_sde = self.get_connection(str(u"源库SDE连接"))
self.src_sde = self.get_connection(str(u"源库SDE连接")).encode('gb2312')
if self.src_sde == "" or self.src_sde is None:
self.logger.error("src_sde Connection file not exist!")
else:
self.create_gdb_files()
txt_path = self.out_gdb_path + "\\" + str(u"图层数量统计.txt").encode("gb2312")
txt_path = self.out_gdb_path + "\\" + u"图层数量统计.txt"
self.txt_ct_file = open(txt_path, "wb+", buffering=0)
# 开始编辑SDE
edit = self.start_edit()
@ -90,7 +90,7 @@ class SdeSynchronous:
if bool_save:
# 开始输出mdo
# self.copy_to_mdo(str(self.out_gdb_path).encode('gbk'))
# self.copy_to_mdo(self.out_gdb_path)
# 转换到旧标准的gdb
self.trans_to_old()
# 输出保密的gdb
@ -121,15 +121,15 @@ class SdeSynchronous:
def get_connection(self, sub_path):
"""获取SDE连接"""
for fileName in os.listdir(self.config.pathname + "\\" + sub_path.encode("gb2312")):
for fileName in os.listdir(self.config.pathname.encode('gb2312') + "\\" + sub_path.encode("gb2312")):
if fnmatch.fnmatch(fileName, '*.sde'):
return self.config.pathname + "\\" + sub_path.encode('gb2312') + "\\" + fileName
return self.config.pathname + "\\" + sub_path + "\\" + fileName
return ""
def start_edit(self):
"""开始编辑"""
arcpy.env.workspace = self.src_sde
print(self.src_sde.decode("gb2312"))
print(self.src_sde)
edit = arcpy.da.Editor(self.src_sde)
edit.startEditing(False, False)
edit.startOperation()

6
test/test.py Normal file
View File

@ -0,0 +1,6 @@
import unittest
if __name__ == "__main__":
test_suite = unittest.TestLoader().discover('.')
runner = unittest.TextTestRunner(verbosity=2)
runner.run(test_suite)

View File

@ -35,6 +35,7 @@ class TestSdeSynchronous(unittest.TestCase):
arcpy.env.workspace = self.sde_db_sync.src_sde
self.sde_db_sync.config.last_sync_datetime = self.sde_db_sync.get_last_sync_datetime()
self.edit = self.sde_db_sync.start_edit()
self.sde_db_sync.create_gdb_files()
def tearDown(self):
self.sde_db_sync.stop_edit(self.edit, False)
@ -53,7 +54,6 @@ class TestSdeSynchronous(unittest.TestCase):
print(self.sde_db_sync.get_projects_info())
def test_create_gdb_files(self):
self.sde_db_sync.create_gdb_files()
self.assertTrue(os.path.exists(self.sde_db_sync.out_gdb_path))
self.assertTrue(os.path.exists(self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Add"]))
self.assertTrue(os.path.exists(self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Edit"]))
@ -95,6 +95,9 @@ class TestSdeSynchronous(unittest.TestCase):
self.sde_db_sync.create_gdb_files()
self.sde_db_sync.featureclass_to_featureclass("Building_A", self.sde_db_sync.out_gdb_path + "\\" + self.sde_db_sync.out_gdb_files["Add"], "Building_A", "ObjectID>0")
def test_copy_to_mdo(self):
self.sde_db_sync.copy_to_mdo(self.sde_db_sync.out_gdb_path)
if __name__ == '__main__':
unittest.main()