def validate_libs_files(self): validation_failed = False result = {} rfdocs_manifest = settings.rfdocs_manifest if not os.path.exists(rfdocs_manifest): return sublime.error_message(no_manifest_file(rfdocs_manifest)) rfdocs_dir = settings.rfdocs_dir if not os.path.exists(rfdocs_dir): return sublime.error_message(no_libs_dir(rfdocs_dir)) with open(rfdocs_manifest, 'r') as f: content = json.loads(f.read()) for item in content: url = item['url'] if not url: continue dir_name = os.path.splitext(url2name(item['url']))[0] full_dir_path = os.path.join(rfdocs_dir, dir_name) if os.path.exists(full_dir_path) and os.path.isdir(full_dir_path): result[dir_name] = [] for f in item['content']: file_name = f['file'] file_md5 = f['md5'] file_path = os.path.join(full_dir_path, file_name) if os.path.exists(file_path) and os.path.isfile(file_path): md5_is_correct = self.calc_md5(file_path) == file_md5 if not md5_is_correct: validation_failed = True result[dir_name].append({ file_name: "correct md5" if md5_is_correct else "wrong md5" }) else: validation_failed = True result[dir_name].append( {file_name: "No such file: {0}".format(file_path)}) else: validation_failed = True result[dir_name] = 'No such directory: {0}'.format( full_dir_path) result[ 'validation_result'] = "Validation failed" if validation_failed else "Validation passed" json_res = json.dumps(result, indent=4) self.window.new_file() self.window.run_command("rfa_insert_into_view", {"json_res": json_res}) self.window.focus_group(0)
def validate_libs_files(self): validation_failed = False result = {} rfdocs_manifest = settings.rfdocs_manifest if not os.path.exists(rfdocs_manifest): return sublime.error_message(no_manifest_file(rfdocs_manifest)) rfdocs_dir = settings.rfdocs_dir if not os.path.exists(rfdocs_dir): return sublime.error_message(no_libs_dir(rfdocs_dir)) with open(rfdocs_manifest, 'r') as f: content = json.loads(f.read()) for item in content: url = item['url'] if not url: continue dir_name = os.path.splitext(url2name(item['url']))[0] full_dir_path = os.path.join(rfdocs_dir, dir_name) if os.path.exists(full_dir_path) and os.path.isdir(full_dir_path): result[dir_name] = [] for f in item['content']: file_name = f['file'] file_md5 = f['md5'] file_path = os.path.join(full_dir_path, file_name) if os.path.exists(file_path) and os.path.isfile(file_path): md5_is_correct = self.calc_md5(file_path) == file_md5 if not md5_is_correct: validation_failed = True result[dir_name].append( {file_name: "correct md5" if md5_is_correct else "wrong md5"} ) else: validation_failed = True result[dir_name].append({file_name: "No such file: {0}".format(file_path)}) else: validation_failed = True result[dir_name] = 'No such directory: {0}'.format(full_dir_path) result['validation_result'] = "Validation failed" if \ validation_failed else "Validation passed" json_res = json.dumps(result, indent=4) self.window.new_file() self.window.run_command("rfa_insert_into_view", {"json_res": json_res}) self.window.focus_group(0)
def run(self, *args, **kwargs): rfdocs_dir = settings.rfdocs_dir if not os.path.exists(rfdocs_dir): return sublime.error_message(no_libs_dir(rfdocs_dir)) self.window.run_command('open_dir', {"dir": rfdocs_dir})