def extract_files(filename, includes):
<EOL>lines = open(filename).readlines()<EOL>files = {}<EOL>lines = [l.strip() for l in lines if '<STR_LIT>' in l]<EOL>for l in lines:<EOL><INDENT>matchedfile = re.search('<STR_LIT>', l)<EOL>if matchedfile is None:<EOL><INDENT>matchedfile = re.search('<STR_LIT>', l)<EOL><DEDENT>if matchedfile is None:<EOL><INDENT>continue<EOL><DEDENT>matchedfile = matchedfile.group(<NUM_LIT:1>)<EOL>if os.path.exists(matchedfile) and os.path.isfile(matchedfile):<EOL><INDENT>action = '<STR_LIT:input>' if '<STR_LIT>' in l else '<STR_LIT>'<EOL>matchedfile = os.path.relpath(matchedfile, "<STR_LIT:.>")<EOL>for i in includes:<EOL><INDENT>if fnmatch.fnmatch(matchedfile, i):<EOL><INDENT>if '<STR_LIT>' in matchedfile:<EOL><INDENT>continue<EOL><DEDENT>if matchedfile not in files:<EOL><INDENT>files[matchedfile] = [action]<EOL><DEDENT>else:<EOL><INDENT>if action not in files[matchedfile]:<EOL><INDENT>files[matchedfile].append(action)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>if len(files) == <NUM_LIT:0>:<EOL><INDENT>print("<STR_LIT>")<EOL>return []<EOL><DEDENT>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>filenames = list(files.keys())<EOL>filenames.sort()<EOL>with tempfile.NamedTemporaryFile(suffix="<STR_LIT>") as temp:<EOL><INDENT>temp.write(yaml.dump(filenames, default_flow_style=False).encode('<STR_LIT:utf-8>'))<EOL>temp.flush()<EOL>EDITOR = os.environ.get('<STR_LIT>','<STR_LIT>')<EOL>subprocess.call("<STR_LIT>" %(EDITOR,temp.name), shell=True)<EOL>temp.seek(<NUM_LIT:0>)<EOL>data = temp.read()<EOL>selected = yaml.load(data)<EOL><DEDENT>print("<STR_LIT>", len(selected), "<STR_LIT>")<EOL>if len(selected) == <NUM_LIT:0>:<EOL><INDENT>return []<EOL><DEDENT>filenames = [f for f in filenames if f in selected]<EOL>print('<STR_LIT>')<EOL>print('<STR_LIT>')<EOL>input('<STR_LIT>')<EOL>prefixes = {}<EOL>for f in filenames:<EOL><INDENT>dirname = os.path.dirname(f)<EOL>if dirname == "<STR_LIT>":<EOL><INDENT>dirname = "<STR_LIT:.>"<EOL><DEDENT>prefixes[dirname] = dirname<EOL><DEDENT>while True:<EOL><INDENT>with tempfile.NamedTemporaryFile(suffix="<STR_LIT>") as temp:<EOL><INDENT>temp.write(yaml.dump(prefixes, default_flow_style=False).encode('<STR_LIT:utf-8>'))<EOL>temp.flush()<EOL>EDITOR = os.environ.get('<STR_LIT>','<STR_LIT>')<EOL>subprocess.call("<STR_LIT>" %(EDITOR,temp.name), shell=True)<EOL>temp.seek(<NUM_LIT:0>)<EOL>data = temp.read()<EOL>try:<EOL><INDENT>revised = yaml.load(data)<EOL><DEDENT>except Exception as e:<EOL><INDENT>revised = {}<EOL><DEDENT>if set(list(revised.keys())) == set(list(prefixes.keys())):<EOL><INDENT>prefixes = revised<EOL>break<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>")<EOL>input("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>if "<STR_LIT:.>" in prefixes:<EOL><INDENT>prefixes["<STR_LIT>"] = prefixes["<STR_LIT:.>"]<EOL><DEDENT>result = []<EOL>ts = datetime.now().isoformat()<EOL>for f in filenames:<EOL><INDENT>relativepath = prefixes[os.path.dirname(f)]<EOL>if relativepath == "<STR_LIT:.>":<EOL><INDENT>relativepath = os.path.basename(f)<EOL><DEDENT>else:<EOL><INDENT>relativepath = os.path.join(relativepath, os.path.basename(f))<EOL><DEDENT>result.append(OrderedDict([<EOL>('<STR_LIT>', relativepath),<EOL>('<STR_LIT:type>', '<STR_LIT>'),<EOL>('<STR_LIT>', files[f]),<EOL>('<STR_LIT>', mimetypes.guess_type(f)[<NUM_LIT:0>]),<EOL>('<STR_LIT:content>', open(f).read(<NUM_LIT>)),<EOL>('<STR_LIT>', compute_sha256(f)),<EOL>('<STR_LIT>', ts),<EOL>('<STR_LIT>', os.path.relpath(f, "<STR_LIT:.>")),<EOL>('<STR_LIT>', os.path.abspath(f)),<EOL>]))<EOL><DEDENT>print(json.dumps(result, indent=<NUM_LIT:4>))<EOL>return result<EOL>
Extract the files to be added based on the includes