From b9e590423b6fb1e48cdd7c9d4482d0f30ef6a3c3 Mon Sep 17 00:00:00 2001 From: akonsu Date: Thu, 19 Jan 2012 14:41:27 -0500 Subject: [PATCH 1/2] added setup.py --- setup.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e318eea --- /dev/null +++ b/setup.py @@ -0,0 +1,25 @@ +from setuptools import setup, find_packages + + +setup( + name='mediafixtures', + version='1.0', + description='Collects media-files as fixtures from django apps.', + long_description=open('README.rst').read(), + author='Leander Hanwald', + author_email='leander@hanwald.de', + url='http://github.com/gamemine/mediafixtures/', + license='MIT', + packages=find_packages(), + include_package_data=True, + classifiers=[ + 'Development Status :: 4 - Beta', + 'Environment :: Web Environment', + 'Framework :: Django', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Topic :: Software Development :: Libraries :: Python Modules', + ], + ) From cb7e4347d6e781ce628b4a10b585fc3fcbe8e435 Mon Sep 17 00:00:00 2001 From: akonsu Date: Fri, 20 Jan 2012 14:24:27 -0500 Subject: [PATCH 2/2] at least one app name is required now, switched to distutils to copy directories. --- .../management/commands/use_media_fixtures.py | 92 +++---------------- 1 file changed, 11 insertions(+), 81 deletions(-) diff --git a/mediafixtures/management/commands/use_media_fixtures.py b/mediafixtures/management/commands/use_media_fixtures.py index 3b31824..58fa1fb 100644 --- a/mediafixtures/management/commands/use_media_fixtures.py +++ b/mediafixtures/management/commands/use_media_fixtures.py @@ -1,93 +1,23 @@ import os -import sys -import shutil -from shutil import Error, WindowsError, copy2, copystat +from distutils import dir_util from django.conf import settings -from django.utils.importlib import import_module -from django.core.management.base import NoArgsCommand +from django.core.management import base as management -class Command(NoArgsCommand): + +class Command(management.AppCommand): """ - Command that copies the media-fixtures from "fixtures/media/" form every app - to the media/ directory of the project. + Copy files from "fixtures/media/" directory of the given applications in to + the directory specified by the settings.MEDIA_ROOT. + Usefull alongside initial_data.* fixtures, so that you can have DB-fixtures and matching media-file fixtures. """ help = "TODO" - def handle(self, *args, **options): - self.apps = [] - - print "\nSearch for apps with media fixtures..." - - apps = settings.INSTALLED_APPS - for app in apps: - mod = import_module(app) - mod_path = os.path.dirname(mod.__file__) - location = os.path.join(mod_path, 'fixtures', 'media') - - if os.path.isdir(location): - print " - " + app - copytree(location, settings.MEDIA_ROOT) - - print "" - - -def copytree(src, dst, symlinks = False, ignore = None): - """ - Copied from Python 2.6 to add the following line: - - if not os.path.isdir(dst): - - this way, we can copy/overwrite existing directories. Very important here - - If anyone knows a better way, say it - """ - names = os.listdir(src) - if ignore is not None: - ignored_names = ignore(src, names) - else: - ignored_names = set() - - if not os.path.isdir(dst): - os.makedirs(dst) - - errors = [] - for name in names: - if name in ignored_names: - continue - srcname = os.path.join(src, name) - dstname = os.path.join(dst, name) - try: - if symlinks and os.path.islink(srcname): - linkto = os.readlink(srcname) - os.symlink(linkto, dstname) - elif os.path.isdir(srcname): - copytree(srcname, dstname, symlinks, ignore) - else: - copy2(srcname, dstname) - # XXX What about devices, sockets etc.? - except (IOError, os.error), why: - errors.append((srcname, dstname, str(why))) - # catch the Error from the recursive copytree so that we can - # continue with other files - except Error, err: - errors.extend(err.args[0]) - try: - copystat(src, dst) - except OSError, why: - if WindowsError is not None and isinstance(why, WindowsError): - # Copying file access times may fail on Windows - pass - else: - errors.extend((src, dst, str(why))) - if errors: - raise Error, errors - - - - - + def handle_app(self, app, **options): + path = os.path.join(os.path.dirname(app.__file__), 'fixtures', 'media') + if os.path.isdir(path): + dir_util.copy_tree(path, settings.MEDIA_ROOT)