def warn_role_kbd(fn, data_src): """ Report non-conforming uses of the :kbd: role. also possible to do replacements here. """ import rst_helpers valid_kbd = warn_role_kbd.valid_kbd index_prev = 0 for d in rst_helpers.role_iter(fn, "kbd", angle_brackets=False): # if d[1] == "Numpad-+": d[1] = "NumpadPlus" k_split = d[1].split("-") for i, k in enumerate(k_split): #if k == "Space": k = k_split[i] = "Spacebar" if k not in valid_kbd: # This is a guess! (and its slow!) i = data_src[index_prev:].find("".join(d)) assert(i != -1) i += index_prev line = data_src[:i].count("\n") + 1 print("%s:%d: %r" % (fn, line, k)) index_prev = i d[1] = "-".join(k_split) return None
def remap_finish(base_path): filepath_remap = os.path.join(base_path, RST_MAP_ID) if not os.path.exists(filepath_remap): fatal("Remap not started, run with 'start', (%r not found)" % filepath_remap) with open(filepath_remap, 'rb') as fh: import pickle remap_data_src = pickle.load(fh) remap_data_dst = remap_data_create(base_path) src_dst_map = {} for file_hash, file_rstpath_src in remap_data_src.items(): file_rstpath_dst = remap_data_dst.get(file_hash) if file_rstpath_dst is None: # shouldn't happen often. print("warning: source '%s.rst' not found!" % file_rstpath_src[1:]) file_rstpath_dst = file_rstpath_src src_dst_map[file_rstpath_src] = file_rstpath_dst if file_rstpath_src.endswith("/index") and file_rstpath_src != "/index": src_dst_map[file_rstpath_src[:-6]] = file_rstpath_dst[:-6] # now remap the doc links import rst_helpers for fn in rst_files(base_path): for d in rst_helpers.role_iter(fn, "doc", angle_brackets=True): file_rstpath_src = d[-2].strip() if "#" in file_rstpath_src: file_rstpath_src, tail = file_rstpath_src.split("#", 1) else: tail = None file_rstpath_dst = src_dst_map.get(file_rstpath_src) if file_rstpath_dst is not None: if tail is not None: file_rstpath_dst = file_rstpath_dst + "#" + tail d[-2] = file_rstpath_dst else: print("warning: unknown path %r" % file_rstpath_src) os.remove(filepath_remap)
def remap_finish_rst(base_path, remap_rst_src, remap_rst_dst): # Store: {source: dest}, without path prefix or extension, e.g: # /path/to/docs/manual/interface/introduction.rst, becomes... # /interface/introduction src_dst_map = {} for file_hash, file_rstpath_src in remap_rst_src.items(): file_rstpath_dst = remap_rst_dst.get(file_hash) if file_rstpath_dst is None: # shouldn't happen often. print("warning: source '%s.rst' not found!" % file_rstpath_src[1:]) file_rstpath_dst = file_rstpath_src src_dst_map[file_rstpath_src] = file_rstpath_dst if file_rstpath_src.endswith( "/index") and file_rstpath_src != "/index": src_dst_map[file_rstpath_src[:-6]] = file_rstpath_dst[:-6] # now remap the doc links import rst_helpers for fn in rst_files(base_path): for d in rst_helpers.role_iter(fn, "doc", angle_brackets=True): file_rstpath_src = d[-2].strip() if "#" in file_rstpath_src: file_rstpath_src, tail = file_rstpath_src.split("#", 1) else: tail = None file_rstpath_dst = src_dst_map.get(file_rstpath_src) if file_rstpath_dst is not None: if tail is not None: file_rstpath_dst = file_rstpath_dst + "#" + tail d[-2] = file_rstpath_dst else: print("warning: unknown path %r" % file_rstpath_src) # now move PO files if os.path.exists(LOCALE_DIR): import subprocess from subprocess import check_call, check_output # first check we have working svn installed try: # don't log to stdout (annoying) check_output(["svn", "help"]) has_svn = True except BaseException as ex: print("warning: command 'svn' not found in your PATH, error:" + str(srr) + " not updating translations!") has_svn = False if has_svn: translation_paths = [ os.path.join(LOCALE_DIR, d, "LC_MESSAGES") for d in os.listdir(LOCALE_DIR) if not d.startswith(".") ] for file_path_src, file_path_dst in src_dst_map.items(): if file_path_src != file_path_dst: file_path_src = file_path_src.lstrip("\\/") file_path_dst = file_path_dst.lstrip("\\/") for locale_dir in translation_paths: file_path_src_po = os.path.join( locale_dir, file_path_src) + ".po" if not os.path.exists(file_path_src_po): print("warning: PO file not found %r" % file_path_src_po) else: file_path_dst_po = os.path.join( locale_dir, file_path_dst) + ".po" if os.path.exists(file_path_dst_po): print("warning: PO file already exists %r" % file_path_dst_po) else: dir_path_dst_po = os.path.dirname( file_path_dst_po) # ensure the new directory exist os.makedirs(dir_path_dst_po, exist_ok=True) try: check_call( ["svn", "info", dir_path_dst_po], cwd=locale_dir) except subprocess.CalledProcessError: check_call([ "svn", "add", "--parents", dir_path_dst_po ], cwd=locale_dir) check_call([ "svn", "mv", file_path_src_po, file_path_dst_po ], cwd=locale_dir)