How to use get_file_tree method in localstack

Best Python code snippet using localstack_python

server.py

Source:server.py Github

copy

Full Screen

...6import os7app = Flask(__name__, template_folder='templates', static_url_path='/static')8working_dir1 = constants['working_dir']9working_dir2 = constants['working_dir']10tree = get_file_tree(working_dir1)11root1 = tree[0]12root2 = tree[0]13html_code1 = create_html_list(1, tree[0])14html_code2 = create_html_list(2, tree[0])15selected = []16to_copy = []17index = -118@app.route('/')19def home():20 """21 home routes main html page22 :return: template23 """24 global working_dir125 global tree26 return render_template('template.html',27 list={'list1': html_code1, 'list2': html_code2, 'working_dir': working_dir1})28@app.route('/media/<path:path>')29def send_png(path):30 """31 send_png routes .png files32 :param path: path33 :return: .png file34 """35 return send_from_directory('static/media', path)36@app.route('/style/<filename>')37def send_css(filename):38 """39 send_css routes .css files40 :param filename: filename41 :return: .css files42 """43 return send_from_directory('static/style', filename)44@app.route('/editor.html')45def send_editor():46 """47 send_path_editor routes html48 :return: template49 """50 file = get_file_by_name(selected[0][:-1], tree)51 return render_template('editor.html', text=file.read())52@app.route('/path.html')53def send_path_editor():54 """55 send_path_editor routes html56 :return: template57 """58 file = get_file_by_name(selected[0][:-1], tree)59 return render_template('path.html', old_path=os.path.relpath(file.path, constants['working_dir']))60@app.route('/scripts/<filename>')61def send_py(filename):62 """63 send_py routes .py files64 :param filename: filename65 :return: .py file66 """67 return send_from_directory('scripts', filename)68@app.route('/selected', methods=['POST'])69def add_selected():70 """71 add_selected retrieves the files selected by the user72 :return: log message73 """74 global selected75 selected = request.json["selected"]76 return request.json77@app.route('/expand', methods=['POST'])78def expand():79 """80 expand returns the html code corresponding to the children of current root81 :return: html code82 """83 global html_code1, html_code2, working_dir1, working_dir2, root1, root284 to_expand = request.json['expand']85 file = get_file_by_name(to_expand[:-1], tree)86 if to_expand[-1] == '1':87 working_dir1 = root1 = file88 html_code1 = create_html_list(1, file)89 return html_code190 else:91 working_dir2 = root2 = file92 html_code2 = create_html_list(2, file)93 return html_code294@app.route('/back', methods=['POST'])95def go_back():96 """97 go_back sets the current roots at a previous level and returns the corresponding html code98 :return: html code99 """100 global html_code1, html_code2, working_dir1, working_dir2, root1, root2101 index = request.json['index']102 if str(index) == '1':103 html_code1 = create_html_list(1, root1.parent)104 working_dir1 = root1 = root1.parent105 if html_code1 is not None:106 return html_code1107 else:108 html_code2 = create_html_list(2, root2.parent)109 working_dir2 = root2 = root2.parent110 if html_code2 is not None:111 return html_code2112 return ""113@app.route('/copy', methods=['POST'])114def copy():115 """116 copy receives the files selected to be copied117 :return: log message118 """119 global html_code1, html_code2, working_dir1, working_dir2, root1, root2, to_copy120 index = request.json['index']121 to_copy = selected122 return "success"123@app.route('/delete-file', methods=['POST'])124def delete_file():125 """126 delete_file deletes all files to be deleted and returns new html list-file structure127 :return: new html code128 """129 global tree, selected, html_code1, html_code2, root1, root2130 to_delete = selected131 index = request.json['index']132 for file_name in to_delete:133 file_name = file_name[:-1]134 if str(index) == '1':135 file = get_file_by_name_ancestor(file_name, tree, root1)136 else:137 file = get_file_by_name_ancestor(file_name, tree, root2)138 file.delete()139 tree = get_file_tree(constants['working_dir'])140 new_root1 = get_file_by_name(root1.name, tree)141 root1 = new_root1142 html_code1 = create_html_list(1, new_root1)143 new_root2 = get_file_by_name(root2.name, tree)144 root2 = new_root2145 html_code2 = create_html_list(2, new_root2)146 return {"html1": html_code1, "html2": html_code2}147@app.route('/paste', methods=['POST'])148def paste():149 """150 paste copies the files to_copy to specified destination151 :return: new html code152 """153 global html_code1, html_code2, working_dir1, working_dir2, root1, root2, to_copy, tree154 index = request.json['index']155 if str(index) == '1':156 copy_paste(to_copy, root1.path, tree)157 tree = get_file_tree(constants['working_dir'])158 new_root1 = get_file_by_name(root1.name, tree)159 root1 = new_root1160 html_code1 = create_html_list(1, new_root1)161 return html_code1162 elif str(index) == '2':163 copy_paste(to_copy, root2.path, tree)164 tree = get_file_tree(constants['working_dir'])165 new_root2 = get_file_by_name(root2.name, tree)166 root2 = new_root2167 html_code2 = create_html_list(2, new_root2)168 return html_code2169@app.route('/cwd', methods=['POST'])170def cwd():171 """172 cwd returns current working directory173 :return: path of cwd174 """175 start = constants['working_dir']176 index = request.json['index']177 if str(index) == '1':178 return os.path.join('\\', os.path.relpath(root1.path, start))179 else:180 return os.path.join('\\', os.path.relpath(root2.path, start))181@app.route('/add', methods=['POST'])182def add():183 """184 add retrieves the index of the panel (1,2 - left, right) where the add operation has been triggered185 :return: log message186 """187 global index188 index = request.json['index']189 return "ok"190@app.route('/new-file', methods=['POST'])191def add_new_file():192 """193 add_new_file creates a new file at the location provided by user194 :return: json containing new html195 """196 global index, tree, html_code1, html_code2, root1, root2197 new_file = request.json["file"]198 add_file(os.path.join(root1.path, new_file))199 tree = get_file_tree(constants['working_dir'])200 new_root1 = get_file_by_name(root1.name, tree)201 root1 = new_root1202 html_code1 = create_html_list(1, new_root1)203 new_root2 = get_file_by_name(root2.name, tree)204 root2 = new_root2205 html_code2 = create_html_list(2, new_root2)206 return {"html1": html_code1, "html2": html_code2}207@app.route('/edit', methods=['POST'])208def edit():209 """210 edit writes the selected file with the new text provided by user211 :return: log message212 """213 global tree, root1, root2, html_code1, html_code2214 text = request.json["text"]215 file = get_file_by_name(selected[0][:-1], tree)216 file.write(text)217 tree = get_file_tree(constants['working_dir'])218 new_root1 = get_file_by_name(root1.name, tree)219 root1 = new_root1220 html_code1 = create_html_list(1, new_root1)221 new_root2 = get_file_by_name(root2.name, tree)222 root2 = new_root2223 html_code2 = create_html_list(2, new_root2)224 return "ok"225@app.route("/new-path", methods=['POST'])226def move_rename():227 """228 move_rename moves file selected to path sent in json229 :return: log message230 """231 new_path = request.json['text']232 file_name = selected[0][:-1]233 file = get_file_by_name(file_name, tree)234 file.move(os.path.join(constants['working_dir'], new_path))235 return "ok"236@app.route("/update", methods=['POST'])237def update():238 """239 update send to frontend the updated file structure240 :return: json containing new file structure241 """242 global tree, root1, root2, html_code1, html_code2243 tree = get_file_tree(constants['working_dir'])244 new_root1 = get_file_by_name(root1.name, tree)245 root1 = new_root1246 html_code1 = create_html_list(1, new_root1)247 new_root2 = get_file_by_name(root2.name, tree)248 root2 = new_root2249 html_code2 = create_html_list(2, new_root2)250 return {"html1": html_code1, "html2": html_code2}251if __name__ == '__main__':...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...17 file_list = drive.ListFile({18 'q': "title='{}' and mimeType contains 'application/vnd.google-apps.folder' and trashed=false".format(fldname)19 }).GetList()20 return file_list21def get_file_tree(parent_name):22 parent_id = find_folders(parent_name)[0]23 print(parent_id)24 input()25 overall_tree_list = []26 file_list = drive.ListFile({'q': "'%s' in parents and trashed=false" % parent_id}).GetList()27 for f in file_list:28 if f['mimeType'] == 'application/vnd.google-apps.folder': # if folder29 overall_tree_list.append({"id": f['id'], "title": f['title'], "list": get_file_tree(f['id'])})30 else:31 overall_tree_list.append(f['title'])32 return overall_tree_list33def upload_files_to_folder(fname, folder):34 nfile = drive.CreateFile({'title': os.path.basename(fname),35 'parents': [{u'id': folder['id']}]})36 nfile.SetContentFile(fname)37 nfile.Upload()38def upload_file(filename, folder):39# try:40 upload_folder = find_folders(folder)[0]41 nfile = drive.CreateFile({'title': os.path.basename(filename), 'parents': [{u'id': upload_folder['id']}]})42 nfile.SetContentFile(filename)43 nfile.Upload()44 return 145# except Exception as e:46# print("upload failed: " + str(e))47# return 048print(str(len(get_file_tree("data"))))49#input()...

Full Screen

Full Screen

get_file_tree.py

Source:get_file_tree.py Github

copy

Full Screen

...22class get_tree_list():23 def __init__(self):24 pass25 def get_tree_ls(self,myPath = "C:\\Users\\rick\\Desktop"):26 gt = get_file_tree()27 gt.find_treee(myPath)28 return gt.path_list#返回目录下的所有文件绝对地址29# a = get_tree_list()30# print str(a.get_tree_ls("C:\\Users\\rick\\Desktop")).__len__()31 # print get_tree_list()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful