加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

帮同事写的一个切换数据库启动的小工具

发布时间:2020-05-25 00:37:22 所属栏目:Python 来源:互联网
导读:帮同事写的一个切换数据库启动的小工具

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。

脚本之家小编现在分享给大家,也给大家做个参考。

#!/usr/bin/env python
#coding=utf-8
import os

dir = '.'
dirApp = "%sData" % dir
file_type = ".app"
default_file = "default"
use_file = "AppData.mdb"

def re_file(file,tofile):
    os.renames('%s%s' % (dirApp,file),'%s%s' %(dirApp,tofile))
    return
  
def read_config():
    s = '%sconfig' % (dirApp)
    opfile = open(s,'r+')
    content = opfile.readline()
    contents = str.split(content,'=')
    return contents[1]
      
def write_config(file):
    s = '%sconfig' % (dirApp)
    opfile = open(s,'w')
    opfile.write('local_name=%s' % file)
  
def add_data():
    new_enter = input("请输入新建名称:")
    try:
        open('%s%s' % (dirApp,new_enter))
    except FileNotFoundError:
 #       re_file(use_file,'%s%s' % (new_enter,file_type))
        os_str = "copy %s%s %s%s%s" % (dirApp,default_file,dirApp,new_enter,file_type)
        os.system(os_str)
    return new_enter
     
def change_data(enter_name):
    try:
        open('%s%s' % (dirApp,use_file))
        re_file(use_file,'%s%s' % (read_config(),file_type))
    except FileNotFoundError:
        print(0)
    write_config(enter_name)
    re_file('%s%s' % (enter_name,file_type),use_file)
  
def start():
    os.system("EPPortal.exe")
    return
  
data_array = []
ff=tuple(os.walk(dirApp))
array = ff[0][2]
index = 1
  
local_file = read_config()
if local_file is '':
    print("当前未使用,直接按回车添加")
else:
    print("当前使用: %s(按回车继续使用)" % local_file)

print('')
print("使用其他请输入编号")
print("0 : 新添加")
for file in array:
    filetype = os.path.splitext(file)
    if file_type == filetype[1]:
        data_array.append(filetype[0])
        print('%i : %s' % (index,filetype[0],))
        index = index + 1
  
enter = input("请输入编号:")
 
if enter is '':
    if local_file is '':
        enter_name = add_data()
        write_config(enter_name)
        re_file('%s%s' % (enter_name,use_file)
else:
    ienter = int(enter)
    if ienter is 0:
        enter_name = add_data()
        change_data(enter_name)
    elif ienter > 0 and ienter < index:
        change_data(data_array[ienter - 1])
start()

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读