def purge_data(self, which_sites=None, never_delete=False):
<EOL>if not exists(self.datadir + '<STR_LIT>'):<EOL><INDENT>format_version = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>with open(self.datadir + '<STR_LIT>') as f:<EOL><INDENT>format_version = int(f.read().strip())<EOL><DEDENT><DEDENT>if format_version == <NUM_LIT:1>:<EOL><INDENT>print('<STR_LIT>')<EOL>datadirs = ['<STR_LIT>', '<STR_LIT>']<EOL>if is_boot2docker():<EOL><INDENT>remove_container('<STR_LIT>'.format(self.name))<EOL>remove_container('<STR_LIT>'.format(self.name))<EOL><DEDENT>else:<EOL><INDENT>datadirs += ['<STR_LIT>', '<STR_LIT>']<EOL><DEDENT>web_command(<EOL>command=['<STR_LIT>']<EOL>+ ['<STR_LIT>' + d for d in datadirs],<EOL>ro={scripts.get_script_path('<STR_LIT>'): '<STR_LIT>'},<EOL>rw={self.datadir: '<STR_LIT>'},<EOL>)<EOL>shutil.rmtree(self.datadir)<EOL><DEDENT>elif format_version == <NUM_LIT:2>:<EOL><INDENT>if not which_sites:<EOL><INDENT>which_sites = self.sites<EOL><DEDENT>datadirs = []<EOL>boot2docker = is_boot2docker()<EOL>if which_sites:<EOL><INDENT>if self.target:<EOL><INDENT>cp = SafeConfigParser()<EOL>cp.read([self.target + '<STR_LIT>'])<EOL><DEDENT>for site in which_sites:<EOL><INDENT>if boot2docker:<EOL><INDENT>remove_container(self._get_container_name('<STR_LIT>'))<EOL><DEDENT>else:<EOL><INDENT>datadirs += [site + '<STR_LIT>']<EOL><DEDENT>datadirs += [site, site + '<STR_LIT>', site + '<STR_LIT>']<EOL>if self.target:<EOL><INDENT>cp.remove_section('<STR_LIT>' + site)<EOL>self.sites.remove(site)<EOL><DEDENT><DEDENT>if self.target:<EOL><INDENT>with open(self.target + '<STR_LIT>', '<STR_LIT:w>') as conf:<EOL><INDENT>cp.write(conf)<EOL><DEDENT><DEDENT><DEDENT>datadirs = ['<STR_LIT>' + datadir for datadir in datadirs]<EOL>if not self.sites and not never_delete:<EOL><INDENT>datadirs.append('<STR_LIT>')<EOL><DEDENT>web_command(<EOL>command=['<STR_LIT>']<EOL>+ ['<STR_LIT>' + d for d in datadirs],<EOL>ro={scripts.get_script_path('<STR_LIT>'): '<STR_LIT>'},<EOL>rw={self.datadir: '<STR_LIT>'},<EOL>)<EOL>if not self.sites and not never_delete:<EOL><INDENT>shutil.rmtree(self.datadir)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise DatacatsError('<STR_LIT>'.format(format_version))<EOL><DEDENT>
Remove uploaded files, postgres db, solr index, venv