コード例 #1
0
def main_patch(cfFile, projName, table):

    passKey = input('input the decrypt key:')
    assert len(passKey) == 16 or len(passKey) == 24 or len(passKey) == 32
    if not isinstance(passKey, bytes):
        passKey = passKey.encode()
    b = ''
    try:
        with open('../../info_file.txt', 'r') as pf:
            b = pf.read()
    except:
        print('read raw info fail')
        return

    b = b.rstrip('\r\n ')
    myCrypt().decryptFile(b,
                          passKey,
                          '../../data.out.zip',
                          outFormat='qr',
                          table=table)
    print('recreate zip file from raw string')

    outFileList = myZipFile().myUnzipFile('../../data.out.zip')
    print('unzip file and get file:')
    print(outFileList)
    os.remove('../../data.out.zip')

    assert len(outFileList) == 1

    old_dir = ''

    cf = configparser.ConfigParser()
    cf.read(cfFile)  #读取配置文件
    old_dir = cf.get(projName + '_patch', "old_dir")
    old_dir = "/".join(old_dir.split("\\"))

    while True:
        print('Old Dir: ' + old_dir)
        a = input('Is Directory OK?(y/n)')
        if a == 'Y' or a == 'y':
            break
        elif a == 'N' or a == 'n':
            old_dir = input('input old dir:')
        else:
            continue

    if not os.path.isabs(old_dir):
        old_dir = os.path.join(os.getcwd(), old_dir)

    #由于制作补丁时都是基于linux格式的(dos2unix),所以这里要将old_dir转换为linux格式
    bdu = batch_dos2unix()
    if bdu.checkEnv():
        bdu.setProcFileType(['py', 'txt', 'bat', 'sh'])
        bdu.dos2unix_dir(old_dir)
    else:
        print('ERROR: can not do dos2unix')

    diff_patch('patch', old_dir, None, outFileList[0])
    os.remove(outFileList[0])
コード例 #2
0
ファイル: tools.py プロジェクト: abednego1979/tipster
def main_patch():

    pw = datetime.date.today().day * 3 + datetime.date.today().month
    b = ""
    try:
        with open("info_file.txt", "r") as pf:
            b = pf.read()
    except:
        print "read raw info fail"
        return

    b.rstrip("\n\r ")
    myCrypt().decrypt(b, pw, "data.out.zip")
    print "recreate zip file from raw string"

    outFileList = myZipFile().myUnzipFile("data.out.zip")
    print "unzip file and get file:"
    print outFileList
    os.remove("data.out.zip")

    assert len(outFileList) == 1

    old_dir = ""

    cf = ConfigParser.ConfigParser()
    cf.read("diffpatch.conf")  # 读取配置文件
    old_dir = cf.get("patch", "old_dir")
    old_dir = "/".join(old_dir.split("\\"))

    while True:
        print "Old Dir: " + old_dir
        a = raw_input("Is Directory OK?(y/n)")
        if a == "Y" or a == "y":
            break
        elif a == "N" or a == "n":
            old_dir = raw_input("input old dir:")
        else:
            continue

    if not os.path.isabs(old_dir):
        old_dir = os.path.join(os.getcwd(), old_dir)

    # 由于制作补丁时都是基于linux格式的(dos2unix),所以这里要将old_dir转换为linux格式
    bdu = batch_dos2unix()
    if bdu.checkEnv():
        bdu.setProcFileType(["py", "txt", "bat", "sh"])
        bdu.dos2unix_dir(old_dir)
    else:
        print "ERROR: can not do dos2unix"

    diff_patch("patch", old_dir, None, outFileList[0])
    os.remove(outFileList[0])
コード例 #3
0
def main_diff(cfFile, projName, table):
    old_dir = ''
    new_dir = ''

    cf = configparser.ConfigParser()
    cf.read(cfFile)  #读取配置文件
    old_dir = '..\\' + cf.get(projName + '_diff', "old_dir")
    new_dir = '..\\' + cf.get(projName + '_diff', "new_dir")

    while True:
        print('Old Dir: ' + old_dir)
        print('New Dir: ' + new_dir)
        a = input('Are Directorys OK?(y/n)')
        if a == 'Y' or a == 'y':
            break
        elif a == 'N' or a == 'n':
            old_dir = input('input old dir:')
            new_dir = input('input new dir:')
        else:
            continue

    if not os.path.isabs(old_dir):
        old_dir = os.path.join(os.getcwd(), old_dir)
    if not os.path.isabs(new_dir):
        new_dir = os.path.join(os.getcwd(), new_dir)

    #对要比较的目录内的文件统一变换为linux格式
    bdu = batch_dos2unix()
    if bdu.checkEnv():
        bdu.setProcFileType(['py', 'txt', 'bat', 'sh'])
        bdu.dos2unix_dir(old_dir)
        bdu.dos2unix_dir(new_dir)
    else:
        print('ERROR: can not do dos2unix')

    temp_patchName = 'patch' + datetime.date.today().strftime('%Y%m%d')
    temp_patchName = os.path.join(os.getcwd(), temp_patchName)

    #开始打补丁
    diff_patch('diff', old_dir, new_dir, temp_patchName)

    if not os.path.isfile(temp_patchName):
        print('patch file is not created')
        return
    else:
        print('patch file is created')

    #对生成的补丁文件进行压缩

    myZipFile().myZipFile([temp_patchName.split('\\')[-1]], 'data.zip')
    if not os.path.isfile('data.zip'):
        print('patch file is not ziped')
        print('a probable reason is the system date time set error')
        print('run "sudo date -s yyyy/mm/dd" to set date.')
        return
    else:
        print('patch file is ziped')

    os.remove(temp_patchName)

    passKey = input('input the decrypt key:')
    assert len(passKey) == 16 or len(passKey) == 24 or len(passKey) == 32
    if not isinstance(passKey, bytes):
        passKey = passKey.encode()
    b = myCrypt().encryptFile("data.zip", passKey, outFormat="qr", table=table)
    print('trans zip file to string:')
    print(b)

    os.remove('data.zip')
コード例 #4
0
ファイル: tools.py プロジェクト: abednego1979/tipster
def main_diff():
    old_dir = ""
    new_dir = ""

    cf = ConfigParser.ConfigParser()
    cf.read("diffpatch.conf")  # 读取配置文件
    old_dir = cf.get("diff", "old_dir")
    new_dir = cf.get("diff", "new_dir")

    while True:
        print "Old Dir: " + old_dir
        print "New Dir: " + new_dir
        a = raw_input("Are Directorys OK?(y/n)")
        if a == "Y" or a == "y":
            break
        elif a == "N" or a == "n":
            old_dir = raw_input("input old dir:")
            new_dir = raw_input("input new dir:")
        else:
            continue

    if not os.path.isabs(old_dir):
        old_dir = os.path.join(os.getcwd(), old_dir)
    if not os.path.isabs(new_dir):
        new_dir = os.path.join(os.getcwd(), new_dir)

    # 对要比较的目录内的文件统一变换为linux格式
    bdu = batch_dos2unix()
    if bdu.checkEnv():
        bdu.setProcFileType(["py", "txt", "bat", "sh"])
        bdu.dos2unix_dir(old_dir)
        bdu.dos2unix_dir(new_dir)
    else:
        print "ERROR: can not do dos2unix"

    temp_patchName = "patch" + datetime.date.today().strftime("%Y%m%d")
    temp_patchName = os.path.join(os.getcwd(), temp_patchName)

    # 开始打补丁
    diff_patch("diff", old_dir, new_dir, temp_patchName)

    if not os.path.isfile(temp_patchName):
        print "patch file is not created"
        return
    else:
        print "patch file is created"

    # 对生成的补丁文件进行压缩

    myZipFile().myZipFile([temp_patchName.split("\\")[-1]], "data.zip")
    if not os.path.isfile("data.zip"):
        print "patch file is not ziped"
        print "a probable reason is the system date time set error"
        print 'run "sudo date -s yyyy/mm/dd" to set date.'
        return
    else:
        print "patch file is ziped"

    os.remove(temp_patchName)

    pw = datetime.date.today().day * 3 + datetime.date.today().month
    b = myCrypt().encrypt("data.zip", pw)
    print "trans zip file to string:"
    print b

    os.remove("data.zip")