devfixture.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:django-devfixtures 作者: dolphinkiss 项目源码 文件源码
def _create(self, fixture_file_path, less_verbose=0):
        try:
            self.write_info('Creating fixture %s' % fixture_file_path, 1+less_verbose)
            fixture_file_path = re.sub(r'\.zip$', '', fixture_file_path)  # we strip away .zip if given
            tmp_dir = tempfile.mkdtemp()
            # copy media root
            shutil.copytree(self._media_root, join(tmp_dir, 'MEDIA_ROOT'))
            # database dump
            with open(join(tmp_dir, 'db.sql'), 'w') as fp:
                return_code = subprocess.call(['pg_dump', '--clean', '--no-owner', self._database_name], stdout=fp)
                if return_code != 0:
                    raise CommandError('pg_dump failed with exit code {}'.format(return_code))
            # creating the fixture archive
            archive_name = shutil.make_archive(fixture_file_path, 'zip', root_dir=tmp_dir)
            self.write_debug(subprocess.check_output(['unzip', '-l', archive_name]))
        except:
            self.write_debug('Temporary directory %s kept due to exception.' % tmp_dir)
            raise
        else:
            self.write_info('... fixture created', 1+less_verbose)
            shutil.rmtree(tmp_dir)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号