|
|
@ -9,16 +9,32 @@ site_name = cstr(frappe.local.site) |
|
|
|
base_path = os.path.expanduser( |
|
|
|
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|
|
|
|
|
|
|
base_url = os.path.expanduser( |
|
|
|
"~") + "/frappe-bench/sites/" + site_name + "/public/files" |
|
|
|
|
|
|
|
|
|
|
|
""" Working """ |
|
|
|
# @frappe.whitelist(allow_guest=1) |
|
|
|
# def delete_all_publish(): |
|
|
|
# try: |
|
|
|
# frappe.db.sql('delete from `tabPublish`;') |
|
|
|
# frappe.db.sql('delete from `tabPublish`;') |
|
|
|
# time.sleep(1) |
|
|
|
# frappe.db.sql('delete from `tabPublish_Docs`;') |
|
|
|
# except Exception as e: |
|
|
|
# return str(e) |
|
|
|
# return True |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=1) |
|
|
|
def reset_all_publish_assets(): |
|
|
|
try: |
|
|
|
frappe.db.sql( |
|
|
|
'update `tabSystem Mapping_System Assets` set published=0;') |
|
|
|
except Exception as e: |
|
|
|
return str(e) |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
@frappe.whitelist(allow_guest=1) |
|
|
|
def change_star_data(): |
|
|
|
count = frappe.db.sql(''' |
|
|
@ -66,3 +82,285 @@ def change_star_data(): |
|
|
|
pass |
|
|
|
return content_file |
|
|
|
|
|
|
|
|
|
|
|
def change_file_type(): |
|
|
|
folder_path = base_url |
|
|
|
count = 0 |
|
|
|
for root, dirs, files in os.walk(folder_path): |
|
|
|
for file in files: |
|
|
|
if file.split('.')[-1] == 'PNG': |
|
|
|
count += 1 |
|
|
|
f1 = os.path.join(root, file) |
|
|
|
f2 = f1[:-3] + 'png' |
|
|
|
os.rename(f1, f2) |
|
|
|
|
|
|
|
if file.split('.')[-1] == 'JPG': |
|
|
|
count += 1 |
|
|
|
f1 = os.path.join(root, file) |
|
|
|
f2 = f1[:-3] + 'jpg' |
|
|
|
os.rename(f1, f2) |
|
|
|
|
|
|
|
return count |
|
|
|
|
|
|
|
|
|
|
|
def change_procedure_ext(): |
|
|
|
try: |
|
|
|
frappe.db.sql(''' |
|
|
|
update tabProcedure_Details set file = concat(substring(file,1,length(file)-3),lower(substring(file,length(file)-2))) |
|
|
|
where substring(file,length(file)-2) REGEXP BINARY '[A-Z]'; |
|
|
|
''') |
|
|
|
frappe.db.commit() |
|
|
|
return True |
|
|
|
except: |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def change_file_ext(): |
|
|
|
try: |
|
|
|
""" File URL Change """ |
|
|
|
frappe.db.sql(''' |
|
|
|
update tabFile set file_url = concat(substring(file_url,1,length(file_url)-3),lower(substring(file_url,length(file_url)-2))) |
|
|
|
where substring(file_url,length(file_url)-2) REGEXP BINARY '[A-Z]'; |
|
|
|
''') |
|
|
|
frappe.db.commit() |
|
|
|
|
|
|
|
""" File Name """ |
|
|
|
frappe.db.sql(''' |
|
|
|
update tabFile set file_name = concat(substring(file_name,1,length(file_name)-3),lower(substring(file_name,length(file_name)-2))) |
|
|
|
where substring(file_name,length(file_name)-2) REGEXP BINARY '[A-Z]'; |
|
|
|
''') |
|
|
|
frappe.db.commit() |
|
|
|
except: |
|
|
|
return False |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def delete_file_ext(): |
|
|
|
try: |
|
|
|
frappe.db.sql(''' |
|
|
|
Delete from tabFile where substring(file_url,length(file_url)-2) REGEXP BINARY '[A-Z]'; |
|
|
|
''') |
|
|
|
frappe.db.commit() |
|
|
|
except: |
|
|
|
return False |
|
|
|
return True |
|
|
|
|
|
|
|
|
|
|
|
def append_size_file(): |
|
|
|
try: |
|
|
|
data = frappe.db.sql( |
|
|
|
""" SELECT * FROM `tabFile` where file_size = 0 and is_folder!=1; """, as_dict=1) |
|
|
|
for d in data: |
|
|
|
try: |
|
|
|
file_path = base_url + d.get("file_url") |
|
|
|
file_size = os.path.getsize(file_path) |
|
|
|
frappe.db.sql( |
|
|
|
f'''UPDATE `tabFile` SET file_size = '{file_size}' WHERE name = '{d['name']}'; ''', as_dict=1) |
|
|
|
frappe.db.commit() |
|
|
|
except: |
|
|
|
pass |
|
|
|
return data |
|
|
|
except Exception as e: |
|
|
|
frappe.log_error("FIle size ", str(e)) |
|
|
|
return e |
|
|
|
|
|
|
|
|
|
|
|
def asset_to_files_path(): |
|
|
|
try: |
|
|
|
count = frappe.db.sql(''' |
|
|
|
select count(*) from tabProcedure_Details where content_type = 'File' and file like '%Asset/%';''') |
|
|
|
frappe.db.sql(''' |
|
|
|
update tabProcedure_Details set file =concat('/files/',SUBSTRING_INDEX(file,'/',-1)) where content_type = 'File' and file like '%Asset/%'; |
|
|
|
''') |
|
|
|
frappe.db.commit() |
|
|
|
return count |
|
|
|
except: |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def change_file_dir(): |
|
|
|
|
|
|
|
base_path = os.path.expanduser( |
|
|
|
"~") + "/frappe-bench/sites/" + site_name + "/public" |
|
|
|
file_data = frappe.db.sql(''' |
|
|
|
select name,file from tabProcedure_Details where content_type = 'File' ;''', as_dict=1) |
|
|
|
changed_file_list = [] |
|
|
|
for d in file_data: |
|
|
|
frappe.log_error("File data :", str(d)) |
|
|
|
path = d['file'] |
|
|
|
isExist = os.path.exists(base_path + path) |
|
|
|
|
|
|
|
frappe.log_error("Path exists :", str(isExist)) |
|
|
|
if not isExist: |
|
|
|
ext = path[-3:] |
|
|
|
path = path[:-3] |
|
|
|
|
|
|
|
extension = '' |
|
|
|
if ext == 'png': |
|
|
|
extension = 'jpg' |
|
|
|
|
|
|
|
if ext == 'jpg': |
|
|
|
extension = 'png' |
|
|
|
|
|
|
|
new_full_path = path + extension |
|
|
|
|
|
|
|
frappe.log_error("New path:", str(new_full_path)) |
|
|
|
|
|
|
|
new_file_dir = base_path + new_full_path |
|
|
|
if os.path.exists(new_file_dir): |
|
|
|
changed_file_list.append(str(new_full_path)) |
|
|
|
frappe.db.sql(f''' |
|
|
|
update tabProcedure_Details set file = '{new_full_path}' where content_type = 'File' and name = '{d['name']}'; |
|
|
|
''') |
|
|
|
frappe.db.commit() |
|
|
|
|
|
|
|
frappe.log_error("ALL updated files", str(changed_file_list)) |
|
|
|
if file_data: |
|
|
|
return file_data |
|
|
|
else: |
|
|
|
return "Done" |
|
|
|
|
|
|
|
|
|
|
|
def file_not_exists(): |
|
|
|
file_data = frappe.db.sql( |
|
|
|
'''select parent,step_name,file,name from tabProcedure_Details where content_type = 'File' order by parent;''', as_dict=1) |
|
|
|
|
|
|
|
changed_file_list = [] |
|
|
|
count = 1 |
|
|
|
for d in file_data: |
|
|
|
|
|
|
|
path = d['file'] |
|
|
|
is_exist = os.path.exists(base_path + path) |
|
|
|
|
|
|
|
if not is_exist: |
|
|
|
print(d) |
|
|
|
d['id'] = count |
|
|
|
changed_file_list.append(d) |
|
|
|
count += 1 |
|
|
|
|
|
|
|
file_path_not_exists = base_path + "/files/json_files/1.json" |
|
|
|
with open(file_path_not_exists, 'w') as outfile: |
|
|
|
try: |
|
|
|
outfile.write(json.dumps(changed_file_list)) |
|
|
|
except Exception as e: |
|
|
|
pass |
|
|
|
|
|
|
|
|
|
|
|
def remove_extra_spaces_in_file_path(): |
|
|
|
import re |
|
|
|
file_path_not_exists = base_path + "/files/json_files/1.json" |
|
|
|
with open(file_path_not_exists, 'r') as outfile: |
|
|
|
data = json.load(outfile) |
|
|
|
|
|
|
|
for d in data: |
|
|
|
print(d['file']) |
|
|
|
res_str = re.sub("/files/ ", "/files/", d['file']) |
|
|
|
# res_str = re.sub("/files/ ", "/files/", res_str) |
|
|
|
print(res_str) |
|
|
|
|
|
|
|
frappe.db.sql(f''' |
|
|
|
update tabProcedure_Details set file = '{res_str}' where name = '{d['name']}'; |
|
|
|
''') |
|
|
|
frappe.db.commit() |
|
|
|
|
|
|
|
|
|
|
|
def return_star_data(): |
|
|
|
data = frappe.db.sql(''' |
|
|
|
select content_type,content,name,parent,replace(content,'*','abcxyz ') as new_content from tabProcedure_Details where content like "%*%"; |
|
|
|
''', as_dict=1) |
|
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
def change_star_data(): |
|
|
|
count = frappe.db.sql(''' |
|
|
|
select count(*) from tabProcedure_Details where content like '%**%'; |
|
|
|
''', as_dict=1) |
|
|
|
print(count) |
|
|
|
updated_list = [] |
|
|
|
error_list = [] |
|
|
|
data = frappe.db.sql(''' |
|
|
|
select step_name,content_type,content,name,parent,replace(content,'**','abcxyz ') as new_content from tabProcedure_Details where content like '%**%'; |
|
|
|
''', as_dict=1) |
|
|
|
for v in data: |
|
|
|
try: |
|
|
|
result = re.split(r"abcxyz ", v['new_content'], flags=0) |
|
|
|
FLAG = 0 |
|
|
|
sts = '' |
|
|
|
if len(result) > 1: |
|
|
|
sts += result[0] |
|
|
|
for r in range(1, len(result)): |
|
|
|
if FLAG == 0: |
|
|
|
sts += '<b>' + result[r] + '</b>' |
|
|
|
FLAG = 1 |
|
|
|
else: |
|
|
|
sts += result[r] |
|
|
|
FLAG = 0 |
|
|
|
frappe.db.sql( |
|
|
|
f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''') |
|
|
|
v['new_content'] = sts |
|
|
|
except Exception as e: |
|
|
|
error_list.append({v['name']: e}) |
|
|
|
updated_list.append(v) |
|
|
|
|
|
|
|
content_file = base_path + "/files/json_files/content_update.json" |
|
|
|
error_file = base_path + "/files/json_files/content_error.json" |
|
|
|
|
|
|
|
with open(error_file, 'w') as outfile: |
|
|
|
try: |
|
|
|
outfile.write(json.dumps(error_list)) |
|
|
|
except: |
|
|
|
pass |
|
|
|
with open(content_file, 'w') as outfile: |
|
|
|
try: |
|
|
|
outfile.write(json.dumps(updated_list)) |
|
|
|
except: |
|
|
|
pass |
|
|
|
return content_file |
|
|
|
|
|
|
|
|
|
|
|
def change_single_star_data(): |
|
|
|
count = frappe.db.sql(''' |
|
|
|
select count(*) from tabProcedure_Details where content like "%* %";''', as_dict=1) |
|
|
|
print(count) |
|
|
|
updated_list = [] |
|
|
|
error_list = [] |
|
|
|
data = frappe.db.sql(''' |
|
|
|
select name,parent,step_name,content_type,content,replace(content,'* ','abcxyz ') as new_content from tabProcedure_Details where content like "%* %"; |
|
|
|
''', as_dict=1) |
|
|
|
for v in data: |
|
|
|
try: |
|
|
|
result = re.split(r"abcxyz ", v['new_content'], flags=0) |
|
|
|
sts = '<ul>' |
|
|
|
if len(result) > 1: |
|
|
|
for a in range(1, len(result)): |
|
|
|
sts += '<li>' + result[a] + '</li> ' |
|
|
|
sts += '</ul>' |
|
|
|
frappe.db.sql( |
|
|
|
f'''update tabProcedure_Details set content = "{sts}" where name = '{v['name']}'; ''') |
|
|
|
frappe.db.commit() |
|
|
|
v['new_content'] = sts |
|
|
|
updated_list.append(v) |
|
|
|
|
|
|
|
except Exception as e: |
|
|
|
error_list.append({v['name']: e}) |
|
|
|
|
|
|
|
content_file = base_path + "/files/json_files/content_single_star_update.json" |
|
|
|
error_file = base_path + "/files/json_files/content_error_single_star.json" |
|
|
|
|
|
|
|
with open(error_file, 'w') as outfile: |
|
|
|
try: |
|
|
|
outfile.write(json.dumps(error_list)) |
|
|
|
except: |
|
|
|
pass |
|
|
|
with open(content_file, 'w') as outfile: |
|
|
|
try: |
|
|
|
outfile.write(json.dumps(updated_list)) |
|
|
|
except: |
|
|
|
pass |
|
|
|
return content_file |
|
|
|
|
|
|
|
|
|
|
|
def get_single_star_data(): |
|
|
|
count = frappe.db.sql(''' |
|
|
|
select count(*) from tabProcedure_Details where content like "%*%";''', as_dict=1) |
|
|
|
print(count) |
|
|
|