Bladeren bron

diff 변경

Surplus_Up (2DU) 6 jaren geleden
bovenliggende
commit
8b3619bd2d
3 gewijzigde bestanden met toevoegingen van 31 en 60 verwijderingen
  1. 9 57
      route/tool/func.py
  2. 21 2
      route/view_diff_data.py
  3. 1 1
      version.json

+ 9 - 57
route/tool/func.py

@@ -4,6 +4,7 @@ import platform
 
 for i in range(0, 2):
     try:
+        from diff_match_patch import diff_match_patch
         import werkzeug.routing
         import werkzeug.debug
         import flask_compress
@@ -19,7 +20,6 @@ for i in range(0, 2):
         import smtplib
         import bcrypt
         import zipfile
-        import difflib
         import shutil
         import threading
         import logging
@@ -104,7 +104,7 @@ def send_email(who, title, data):
             elif smtp_security == 'starttls':
                 smtp = smtplib.SMTP(smtp_server, smtp_port)
                 smtp.starttls()
-            else: #if smtp_security == 'tls':
+            else: # if smtp_security == 'tls':
                 smtp = smtplib.SMTP_SSL(smtp_server, smtp_port)
             
             smtp.login(smtp_email, smtp_pass)
@@ -186,13 +186,14 @@ def update():
         num = 1
         curs.execute(db_change('select title, sub from topic where id = "1" order by date asc'))
         db_data = curs.fetchall()
-        for i in db_data:
-            curs.execute(db_change("update topic set code = ? where title = ? and sub = ? and id = '1'"), [str(num), i[0], i[1]])
-            num += 1
+        if db_data:
+            for i in db_data:
+                curs.execute(db_change("update topic set code = ? where title = ? and sub = ? and id = '1'"), [str(num), i[0], i[1]])
+                num += 1
 
-        print('----')
-        print('Add topic code')
-        print('----')
+            print('----')
+            print('Add topic code')
+            print('----')
     except:
         pass
 
@@ -554,55 +555,6 @@ def wiki_set(num = 1):
     else:
         return var_data
 
-def diff(seqm):
-    output = []
-
-    for opcode, a0, a1, b0, b1 in seqm.get_opcodes():
-        if opcode == 'equal':
-            output += [html.escape(seqm.a[a0:a1])]
-        elif opcode == 'insert':
-            output += ["<span style='background:#CFC;'>" + html.escape(seqm.b[b0:b1]) + "</span>"]
-        elif opcode == 'delete':
-            output += ["<span style='background:#FDD;'>" + html.escape(seqm.a[a0:a1]) + "</span>"]
-        elif opcode == 'replace':
-            output += ["<span style='background:#FDD;'>" + html.escape(seqm.a[a0:a1]) + "</span>"]
-            output += ["<span style='background:#CFC;'>" + html.escape(seqm.b[b0:b1]) + "</span>"]
-
-    end = ''.join(output)
-    end = end.replace('\r\n', '\n')
-    sub = ''
-
-    if not re.search('\n$', end):
-        end += '\n'
-
-    num = 0
-    left = 1
-    while 1:
-        data = re.search('((?:(?!\n).)*)\n', end)
-        if data:
-            data = data.groups()[0]
-
-            left += 1
-            if re.search('<span style=\'(?:(?:(?!\').)+)\'>', data):
-                num += 1
-                if re.search('<\/span>', data):
-                    num -= 1
-
-                sub += str(left) + ' : ' + re.sub('(?P<in>(?:(?!\n).)*)\n', '\g<in>', data, 1) + '<br>'
-            else:
-                if re.search('<\/span>', data):
-                    num -= 1
-                    sub += str(left) + ' : ' + re.sub('(?P<in>(?:(?!\n).)*)\n', '\g<in>', data, 1) + '<br>'
-                else:
-                    if num > 0:
-                        sub += str(left) + ' : ' + re.sub('(?P<in>.*)\n', '\g<in>', data, 1) + '<br>'
-
-            end = re.sub('((?:(?!\n).)*)\n', '', end, 1)
-        else:
-            break
-
-    return sub
-
 def admin_check(num = None, what = None, name = ''):
     if name == '':
         ip = ip_check()

+ 21 - 2
route/view_diff_data.py

@@ -21,9 +21,28 @@ def view_diff_data_2(conn, name):
         if second_raw_data:
             if first == second:
                 result = ''
+            elif first_raw_data == second_raw_data:
+                result = ''
             else:
-                diff_data = difflib.SequenceMatcher(None, first_raw_data[0][0], second_raw_data[0][0])
-                result = '<pre>' + diff(diff_data) + '</pre>'
+                i = 2
+                include_ins = 0
+                diff_data = '1 : ' + diff_match_patch().diff_prettyHtml(diff_match_patch().diff_main(first_raw_data[0][0], second_raw_data[0][0]))
+
+                re_data = re.findall('((?:(?!&para;<br>).)*)(?:&para;<br>|$)', diff_data)
+                for re_in_data in re_data:
+                    if re.search('(<\/ins>|<\/del>)', re_in_data):
+                        re_data[i - 2] = str(i) + ' : ' + re_data[i - 2] + '\n'
+                        include_ins = 0
+                    elif re.search('(<ins |<del )', re_in_data) or include_ins == 1:
+                        re_data[i - 2] = str(i) + ' : ' + re_data[i - 2] + '\n'
+                        include_ins = 1
+                    else:
+                        re_data[i - 2] = ''
+                        include_ins = 0
+
+                    i += 1
+                    
+                result = '<pre>' + ''.join(re_data) + '</pre>'
 
             return easy_minify(flask.render_template(skin_check(),
                 imp = [name, wiki_set(), custom(), other2([' (' + load_lang('compare') + ')', 0])],

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "master" : {
-        "r_ver" : "v3.1.6-master-24",
+        "r_ver" : "v3.1.6-master-25",
         "c_ver" : "400009",
         "s_ver" : "7"
     }, "stable" : {