- s = {}
- l = dict ([(tag, set()) for tag in TAGS])
- for f in glob.glob (os.path.join (src, '*.ly')):
- basename = os.path.basename (f)
- m = tags_re.search (open (f, 'r').read ())
- if m:
- file_tags = [tag.strip() for tag in m.group (1). split(',')]
- s[basename] = (src, file_tags)
- [l[tag].add (basename) for tag in file_tags if tag in TAGS]
- else:
- notags_files.append (f)
- return s, l
-
-
-def dump_file_list (file, list):
- f = open (file, 'w')
- f.write ('\n'.join (list) + '\n')
-
-## clean out existing lys and generated files
-map (os.remove, glob.glob (os.path.join (DEST, '*.ly')) +
- glob.glob (os.path.join (DEST, '*.snippet-list')))
-
-# read LSR source where tags are defined by subdirs
-snippets, tag_lists = read_source_with_dirs (in_dir)
-# read input/new where tags are directly
-s, l = read_source (NEW_LYS)
-snippets.update (s)
-for t in TAGS:
- tag_lists[t].update (l[t])
+ s = {}
+ l = dict ([(tag, set()) for tag in TAGS])
+ for f in glob.glob (os.path.join (src, '*.ly')):
+ basename = os.path.basename (f)
+ m = tags_re.search (open (f, 'r').read ())
+ if m:
+ file_tags = [tag.strip() for tag in m.group (1). split(',')]
+ s[basename] = (src, file_tags)
+ [l[tag].add (basename) for tag in file_tags if tag in TAGS]
+ else:
+ notags_files.append (f)
+ return s, l
+
+
+def dump_file_list (file, file_list, update=False):
+ if update:
+ old_list = set (open (file, 'r').read ().splitlines ())
+ old_list.update (file_list)
+ new_list = list (old_list)
+ else:
+ new_list = file_list
+ f = open (file, 'w')
+ f.write ('\n'.join (sorted (new_list)) + '\n')
+
+def update_ly_in_place (snippet_path):
+ visited_languages = []
+ contents = open (snippet_path).read ()
+ contents = texidoc_chunk_re.sub \
+ (lambda m: update_translated_texidoc (m,
+ snippet_path,
+ visited_languages),
+ contents)
+ for language_code in langdefs.LANGDICT:
+ if not language_code in visited_languages:
+ base = os.path.splitext (os.path.basename (snippet_path))[0]
+ texidoc_path = os.path.join ('Documentation', language_code,
+ 'texidocs', base + '.texidoc')
+ if os.path.isfile (texidoc_path):
+ texidoc_translation = open (texidoc_path).read ()
+ texidoc_translation = texidoc_translation.replace ('\\', '\\\\')
+ contents = begin_header_re.sub ('\\g<0>\n' + texidoc_translation, contents, 1)
+ contents = doctitle_re.sub (doctitle_sub, contents)
+ open (snippet_path, 'w').write (contents)
+
+if in_dir:
+ ## clean out existing lys and generated files
+ map (os.remove, glob.glob (os.path.join (DEST, '*.ly')) +
+ glob.glob (os.path.join (DEST, '*.snippet-list')))
+
+ # read LSR source where tags are defined by subdirs
+ snippets, tag_lists = read_source_with_dirs (in_dir)
+
+ # read input/new where tags are directly defined
+ s, l = read_source (NEW_LYS)
+ snippets.update (s)
+ for t in TAGS:
+ tag_lists[t].update (l[t])
+else:
+ snippets, tag_lists = read_source (NEW_LYS)
+ ## update texidocs of snippets that don't come from NEW_LYS
+ for snippet_path in glob.glob (os.path.join (DEST, '*.ly')):
+ if not os.path.basename (snippet_path) in snippets:
+ update_ly_in_place (snippet_path)