def parseTemplate(target=template_file, force=False): global parsed_groups if not parsed_groups or force: print('\nCaching image list from template (Ctrl+C to cancel) ...') text = fileio.read(target) BUFFER = text while '[' in BUFFER and ']' in BUFFER: start = BUFFER.index('[') + 1 end = BUFFER.index(']') g_name = BUFFER[start:end] BUFFER = BUFFER[end + 1:] if '[' in BUFFER: group = tuple( BUFFER[:BUFFER.index('[')].rstrip(' \t\r\n').split('\n')) else: group = tuple(BUFFER.rstrip(' \t\r\n').split('\n')) t_groups[g_name] = cleanList(group) parsed_groups = True return t_groups
def copyTemplate(target_dir): template = fileio.read(template_file) target = appendPath(target_dir, 'theme') # ignore lines beginning with "#!" lines = template.split('\n') for idx in reversed(range(len(lines))): if lines[idx].startswith('#!'): lines.pop(idx) template = '\n'.join(lines) fileio.write(target, template)
# images that should be removed from release if found remove_images = () if not include_all: remove_images = getImagesToRemove() print('{} images will be included in release.'.format(img_count)) # images that will be overwritten if found in release (default is to not overwrite any, use --overwrite to set) overwrite_images = None if args.contains('overwrite-png'): overwrite_images = args.getValue('overwrite-png') if ',' in overwrite_images: overwrite_images = tuple(overwrite_images.split(',')) # prepare README for inclusion in release readme_text = fileio.read(file_readme) # don't include export section if '### Creating/Exporting Theme' in readme_text: readme_text = readme_text.split('### Creating/Exporting Theme')[0] readme_text = markdownToText(readme_text) grp_count = len(sizes) grp_idx = 0 for S in sizes: converted_count = 0 replaced_count = 0 removed_count = 0 grp_idx += 1 print('\nProcessing {}x{} images (group {}/{}) (Ctrl+C to cancel) ...'. format(S, S, grp_idx, grp_count))
source = appendPath(dir_svg, SVG) target = appendPath(dir_export, '{}.png'.format(os.path.basename(SVG).split('.')[0])) convertToPNG(source, target) # newline after converting files print() theme_file = appendPath(dir_root, 'theme.txt') groups = {} if os.path.isfile(theme_file): print('Reading existing theme file ...') theme_text = fileio.read(theme_file) BUFFER = theme_text while '[' in BUFFER and ']' in BUFFER: start = BUFFER.index('[') + 1 end = BUFFER.index(']') g_name = BUFFER[start:end] BUFFER = BUFFER[end + 1:] if '[' in BUFFER: group = tuple( BUFFER[:BUFFER.index('[')].rstrip(' \t\r\n').split('\n')) else: group = tuple(BUFFER.rstrip(' \t\r\n').split('\n')) groups[g_name] = cleanList(group)
from os.path import isfile from py import fileio from py.paths import appendPath from py.paths import root info = {} info_file = appendPath(root, 'INFO') # parse the INFO file lines = () if isfile(info_file): lines = tuple(fileio.read(info_file).split('\n')) else: print('\nWARNING: INFO file not found: {}'.format(info_file)) # only recognize lines with "=" for idx in reversed(range(len(lines))): L = lines[idx] if L.startswith('#') or '=' not in L: continue key = L.split('=') value = key[1].strip(' \t') key = key[0].strip(' \t').lower() if key and value: info[key] = value