# -*- coding: utf-8 -*-class data:
def __init__(self, a="", b=""):
self.a = a
self.b = b
def return_data(self):
return self.a, self.b
class createobject:
def __init__(self, class_name="null", class_type=-1, class_length=0, class_param=):
self.class_name = class_name
self.classtype = class_type
self.classlength = class_length
self.classparam = class_param
class inte***ce:
def __init__(self, result_name=0, error_mag=0):
self.result_name = result_name
self.error_mag = error_mag
def compare_files(p, c):
# 從比較檔案中獲取乙個方法
msg_list =
for i in range(len(c)):
itf = inte***ce()
for j in range(len(p)):
# 如果方法名一致
if p[j].classname == c[i].classname:
# 如果 返回型別一致
if p[j].classtype == c[i].classtype:
# 引數長度
if p[j].classlength == c[i].classlength:
# 遍歷引數列表
for m in range(len(c[i].classparam)):
for n in range(len(p[j].classparam)):
# 找出引數依次比較
if c[i].classparam[m].paramname == p[j].classparam[n].paramname:
if c[i].classparam[m].paramtype == p[j].classparam[n].paramtype:
itf.result_name = c[i].classname
itf.error_mag = "success"
else:
print("classlength i = ", i, "j = ", j, "m =", m, "n = ", n)
if m == len(c[i].classparam) and n == len(p[j].classparam):
itf.result_name = c.classname
itf.error_mag = "wrong param type"
else:
print("classlength i = ", i, "j = ", j, "m =", m, "n = ", n)
if m == len(c[i].classparam) and n == len(p[j].classparam):
itf.result_name = c.classname
itf.error_mag = "paramname not exist"
else:
print("classlength i = ", i, "j = ", j)
# 如果是最後一條資料
if j == len(p):
itf.result_name = c.classname
itf.error_mag = "wrong param number"
else:
print("classtype i = ", i, "j = ", j)
# 如果是最後一條資料
if j == len(p):
itf.result_name = c.classname
itf.error_mag = "wrong return type"
else:
print ("classname i = ", i, "j = ", j)
# 如果是最後一條資料
if j == len(p):
itf.result_name = c.classname
itf.error_mag = "classname not exist"
return msg_list
if __name__ == "__main__":
lis1 = [
, ]},
, ]},
, , ]
},, , ]}]
lis2 = [
, ]},
, ]},
, , ]
},, , ]}]
data_obj = createobject()
cf = compare_files(lis1, lis2)
for inner in cf:
if inner.result_name is not 'success':
print inner.result_name + ":" + inner.error_mag
批量檔案比對
前幾天就有研發人員發現了相同網元的兩台機器的配置檔案有些不同的地方,今天無聊就幫研發人員將這些差異比對出來。研發自己有比較工具,這個指令碼太複雜,而且為了配合使用這個指令碼還寫了9頁的指導文件,因為懶得看文件和熟悉那個超複雜的指令碼,就用我自己的方式來比對。本著懶人原則,用最簡單的語句,搞定最複雜的...
python 指令碼檢視比對檔案許可權
安全基線要求中大多數都要求檢測 etc passwd,etc shadow等目錄的許可權。我嘗試用python 編寫相關指令碼進行檢測,遇到了幾個難點,記錄一下。從python指令碼輸入shell指令並取得返回值,這個我用匯入的subprocess模組中的check output方法解決了 返回的字...
Git檔案內容的比對
git status 只能檢視區域狀態的不同,不能檢視檔案的內容不同之處 root git git test git status on branch master changes not staged for commit use git add to update what will be co...