Selaa lähdekoodia

SVG 버그 수정

https://github.com/openNAMU/openNAMU/issues/2008
잉여개발기 (SPDV) 2 vuotta sitten
vanhempi
sitoutus
32db9c0925
4 muutettua tiedostoa jossa 80 lisäystä ja 71 poistoa
  1. 4 63
      app.py
  2. 68 4
      route/tool/func.py
  3. 7 3
      route/view_read.py
  4. 1 1
      version.json

+ 4 - 63
app.py

@@ -2,8 +2,6 @@
 import os
 import re
 import logging
-import shutil
-import datetime
 
 from route.tool.func import *
 from route import *
@@ -201,69 +199,12 @@ with get_db_connect() as conn:
 
         server_set[i] = server_set_val
 
-    # Init-DB_care
-    if data_db_set['type'] == 'sqlite':
-        def back_up(back_time, back_up_where, back_up_count = 0):
-            try:
-                if back_up_count != 0:
-                    file_dir = os.path.split(back_up_where)[0]
-                    file_dir = '.' if file_dir == '' else file_dir
-                    
-                    file_name = os.path.split(back_up_where)[1]
-                    file_name = re.sub(r'\.db$', '_[0-9]{14}.db', file_name)
-
-                    backup_file = [for_a for for_a in os.listdir(file_dir) if re.search('^' + file_name + '$', for_a)]
-                    backup_file = sorted(backup_file)
-                    
-                    if len(backup_file) >= back_up_count:
-                        remove_dir = os.path.join(file_dir, backup_file[0])
-                        os.remove(remove_dir)
-                        print('Back up : Remove (' + remove_dir + ')')
-
-                now_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
-                new_file_name = re.sub(r'\.db$', '_' + now_time + '.db', back_up_where)
-                shutil.copyfile(
-                    data_db_set['name'] + '.db', 
-                    new_file_name
-                )
-
-                print('Back up : OK (' + new_file_name + ')')
-            except Exception as e:
-                print('Back up : Error')
-                print(e)
-
-            threading.Timer(
-                60 * 60 * back_time, 
-                back_up,
-                [back_time, back_up_where, back_up_count]
-            ).start()
-
-        curs.execute(db_change('select data from other where name = "back_up"'))
-        back_time = curs.fetchall()
-        back_time = float(number_check(back_time[0][0], True)) if back_time and back_time[0][0] != '' else 0
-
-        curs.execute(db_change('select data from other where name = "backup_count"'))
-        back_up_count = curs.fetchall()
-        back_up_count = int(number_check(back_up_count[0][0])) if back_up_count and back_up_count[0][0] != '' else 0
-
-        if back_time != 0:
-            curs.execute(db_change('select data from other where name = "backup_where"'))
-            back_up_where = curs.fetchall()
-            back_up_where = back_up_where[0][0] if back_up_where and back_up_where[0][0] != '' else data_db_set['name'] + '.db'
-
-            print('Back up state : ' + str(back_time) + ' hours')
-            print('Back up directory : ' + back_up_where)
-            if back_up_count != 0:
-                print('Back up max number : ' + str(back_up_count))
-
-            back_up(back_time, back_up_where, back_up_count)
-        else:
-            print('Back up state : Turn off')
+        conn.commit()
 
-    print('Now running... http://localhost:' + server_set['port'])
-    
-    conn.commit()
+auto_do_something(data_db_set)
 
+print('Now running... http://localhost:' + server_set['port'])
+    
 # Init-custom
 if os.path.exists('custom.py'):
     from custom import custom_run

+ 68 - 4
route/tool/func.py

@@ -5,6 +5,8 @@ import platform
 import json
 import smtplib
 import random
+import shutil
+import datetime
 import ipaddress
 import subprocess
 
@@ -97,12 +99,13 @@ if sys.version_info < (3, 6):
 global_lang = {}
 global_wiki_set = {}
 
-global_db_set = ''
+global_db_set = {}
 
 # Func
 # Func-main
 def do_db_set(db_set):
     global global_db_set
+
     global_db_set = db_set
     
 # Func-init
@@ -142,6 +145,7 @@ def get_init_set_list(need = 'all'):
 class get_db_connect:
     def __init__(self, db_type = ''):
         global global_db_set
+        
         self.db_set = global_db_set
         if db_type != '':
            self.db_set['type'] = db_type 
@@ -346,6 +350,68 @@ def get_db_table_list():
     
     return create_data
 
+def auto_do_something(data_db_set):
+    with get_db_connect() as conn:
+        curs = conn.cursor()
+        
+        if data_db_set['type'] == 'sqlite':
+            def back_up(back_time, back_up_where, back_up_count = 0):
+                try:
+                    if back_up_count != 0:
+                        file_dir = os.path.split(back_up_where)[0]
+                        file_dir = '.' if file_dir == '' else file_dir
+                        
+                        file_name = os.path.split(back_up_where)[1]
+                        file_name = re.sub(r'\.db$', '_[0-9]{14}.db', file_name)
+
+                        backup_file = [for_a for for_a in os.listdir(file_dir) if re.search('^' + file_name + '$', for_a)]
+                        backup_file = sorted(backup_file)
+                        
+                        if len(backup_file) >= back_up_count:
+                            remove_dir = os.path.join(file_dir, backup_file[0])
+                            os.remove(remove_dir)
+                            print('Back up : Remove (' + remove_dir + ')')
+
+                    now_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
+                    new_file_name = re.sub(r'\.db$', '_' + now_time + '.db', back_up_where)
+                    shutil.copyfile(
+                        data_db_set['name'] + '.db', 
+                        new_file_name
+                    )
+
+                    print('Back up : OK (' + new_file_name + ')')
+                except Exception as e:
+                    print('Back up : Error')
+                    print(e)
+
+                threading.Timer(
+                    60 * 60 * back_time, 
+                    back_up,
+                    [back_time, back_up_where, back_up_count]
+                ).start()
+
+            curs.execute(db_change('select data from other where name = "back_up"'))
+            back_time = curs.fetchall()
+            back_time = float(number_check(back_time[0][0], True)) if back_time and back_time[0][0] != '' else 0
+
+            curs.execute(db_change('select data from other where name = "backup_count"'))
+            back_up_count = curs.fetchall()
+            back_up_count = int(number_check(back_up_count[0][0])) if back_up_count and back_up_count[0][0] != '' else 0
+
+            if back_time != 0:
+                curs.execute(db_change('select data from other where name = "backup_where"'))
+                back_up_where = curs.fetchall()
+                back_up_where = back_up_where[0][0] if back_up_where and back_up_where[0][0] != '' else data_db_set['name'] + '.db'
+
+                print('Back up state : ' + str(back_time) + ' hours')
+                print('Back up directory : ' + back_up_where)
+                if back_up_count != 0:
+                    print('Back up max number : ' + str(back_up_count))
+
+                back_up(back_time, back_up_where, back_up_count)
+            else:
+                print('Back up state : Turn off')
+
 def update(ver_num, set_data):
     with get_db_connect() as conn:
         curs = conn.cursor()
@@ -2251,9 +2317,7 @@ def do_edit_filter(data):
         curs = conn.cursor()
 
         if admin_check(1) != 1:
-            curs.execute(db_change(
-                "select plus, plus_t from html_filter where kind = 'regex_filter' and plus != ''"
-            ))
+            curs.execute(db_change("select plus, plus_t from html_filter where kind = 'regex_filter' and plus != ''"))
             for data_list in curs.fetchall():
                 match = re.compile(data_list[0], re.I)
                 if match.search(data):

+ 7 - 3
route/view_read.py

@@ -135,8 +135,12 @@ def view_read(name = 'Test', doc_rev = '', doc_from = '', do_type = ''):
             file_all_name = sha224_replace(file_name) + '.' + mime_type
             file_path_name = os.path.join(load_image_url(), file_all_name)
             if os.path.exists(file_path_name):
-                img = Image.open(file_path_name)
-                width, height = img.size
+                try:
+                    img = Image.open(file_path_name)
+                    width, height = img.size
+                    file_res = str(width) + 'x' + str(height)
+                except:
+                    file_res = 'Vector'
                 
                 file_size = str(round(os.path.getsize(file_path_name) / 1000, 1))
                 
@@ -146,7 +150,7 @@ def view_read(name = 'Test', doc_rev = '', doc_from = '', do_type = ''):
                     <table>
                         <tr><td>URL</td><td><a href="/image/''' + url_pas(file_all_name) + '''">''' + load_lang('link') + '''</a></td></tr>
                         <tr><td>''' + load_lang('volume') + '''</td><td>''' + file_size + '''KB</td></tr>
-                        <tr><td>''' + load_lang('resolution') + '''</td><td>''' + str(width) + 'x' + str(height) + '''</td></tr>
+                        <tr><td>''' + load_lang('resolution') + '''</td><td>''' + file_res + '''</td></tr>
                     </table>
                     <h2>''' + load_lang('content') + '''</h2>
                 '''

+ 1 - 1
version.json

@@ -1,6 +1,6 @@
 {
     "beta" : {
-        "r_ver" : "v3.4.6-RC5-dev62",
+        "r_ver" : "v3.4.6-RC5-dev63",
         "c_ver" : "3500373",
         "s_ver" : "3500112"
     }