示例#1
0
    def handle_label(self, app=None, **options):
        if app is None:
            raise CommandError("Specify at least one app")
        if app not in settings.INSTALLED_APPS:
            raise CommandError("%s not found at INSTALLED_APPS" % app)
        MEDIA_ROOT = os.path.abspath(options['media_root'])

        dst = os.path.join(MEDIA_ROOT, app)
        if os.path.exists(MEDIA_ROOT):
            if not os.path.isdir(MEDIA_ROOT):
                raise CommandError("%s is not a directory" % MEDIA_ROOT)
            if os.path.exists(dst) and options['force'] is False:
                raise CommandError("%s already exists" % dst)
        else:
            os.mkdir(MEDIA_ROOT)
        try:
            app_module = import_module(app)
        except ImportError:
            raise CommandError("Cannot find app %s" % app)
        app_path = app_module.__path__[0]
        app_dir = os.path.basename(app_path)
        app_media_dir = os.path.abspath(os.path.join(app_path, 'media'))
        _inner = os.path.join(app_media_dir, app_dir)
        if os.path.isdir(_inner):
            #logging.debug("Seems that %s has main media subdirectory, will "
            #    "use it (%s)" % (app_module.__name__, _inner))
            app_media_dir = _inner

        if not os.path.isdir(app_media_dir) and \
            options['fail_siltently'] is False:
            raise CommandError("Specified app '%s' has no 'media' directory!"
                % app)
        copy_dir_helper(app_media_dir, dst, force=options['force'])
        make_writeable(MEDIA_ROOT)
示例#2
0
def init(target_dir, profile):
    """
    Copies templates profile from templates_profiles
    located within richtemplates source directory
    into target_dir. If target_dir exists CommandError
    is raised.
    """
    profile_dir = os.path.join(rt_templates_profiles_dir, profile)
    copy_dir_helper(profile_dir, target_dir)
示例#3
0
def init_media(target_dir):
    """
    Copies richtemplates media file into target_dir/richtemplates.
    """
    if not os.path.isdir(target_dir):
        logging.debug("Will create %s directory." % target_dir)
        os.mkdir(target_dir)
    dst = os.path.abspath(os.path.join(target_dir, 'richtemplates'))
    copy_dir_helper(rt_media_dir, dst)