Example #1
0
    def handle(self, *args, **kwargs):
        UpdateTracker.start()
        print "Updating tendenci package"
        os.system("pip install tendenci --upgrade")

        print "Updating tendenci site"
        os.system("python deploy.py")

        print "Restarting Server"
        os.system("sudo reload %s" % os.path.basename(settings.PROJECT_ROOT))

        UpdateTracker.end()
        call_command("clear_cache")
Example #2
0
def update_tendenci_process(request, template_name="base/update_process.html"):
    tracker = UpdateTracker.get_or_create_instance()
    if not tracker.is_updating:
        messages.add_message(request, messages.SUCCESS, "Update complete.")
        return redirect("dashboard")

    return render_to_response(template_name, context_instance=RequestContext(request))
Example #3
0
def get_themes(request, template_name="theme_editor/get_themes.html"):
    if not request.user.profile.is_superuser:
        raise Http403

    if request.is_ajax():
        tracker = UpdateTracker.get_or_create_instance()
        return HttpResponse(tracker.is_updating)

    if request.method == 'POST':
        process = SubProcessManager.set_process(["python", "manage.py", "install_theme", "--all"])
        return render_to_response(template_name, context_instance=RequestContext(request))

    raise Http404
Example #4
0
def get_themes(request, template_name="theme_editor/get_themes.html"):
    if not request.user.profile.is_superuser:
        raise Http403

    if request.is_ajax():
        tracker = UpdateTracker.get_or_create_instance()
        return HttpResponse(tracker.is_updating)

    if request.method == 'POST':
        process = SubProcessManager.set_process(["python", "manage.py", "install_theme", "--all"])
        return render_to_response(template_name, context_instance=RequestContext(request))

    raise Http404
Example #5
0
    def handle(self, theme_name=None, theme_url=None, **options):
        """
        Downloads a theme to be installed on the site and sets
        it as the active theme.
        """
        from tendenci.core.base.models import UpdateTracker

        UpdateTracker.start()
        all_themes = options.get('all', False)

        if not theme_url:
            theme_url = "https://github.com/tendenci/tendenci-themes/archive/master.zip"

        if not (theme_name or all_themes):
            raise CommandError(
                'Specify a theme name, or add --all for all themes')

        themes_dir_path = os.path.join(settings.PROJECT_ROOT, "themes")
        if theme_name:
            theme_path = os.path.join(themes_dir_path, theme_name)

            # Check if the theme already exists
            if os.path.isdir(theme_path):
                raise CommandError('The theme %s is already installed.' %
                                   theme_name)

        # Copy the theme files down
        theme_download = urllib.urlopen(theme_url)
        theme_zip_path = os.path.join(themes_dir_path, "themes.zip")
        theme_zip = open(theme_zip_path, 'wb')
        theme_zip.write(theme_download.read())
        theme_zip.close()

        # Unzip the theme files
        theme_zip_file = open(theme_zip_path, 'r')
        zfobj = zipfile.ZipFile(theme_zip_file)
        unzip_dirname = "themes"
        for i, name in enumerate(zfobj.namelist()):
            if i == 0:
                unzip_dirname = name[:-1]
            if name.endswith('/'):
                try:  # Don't try to create a directory if exists
                    os.mkdir(os.path.join(themes_dir_path, name))
                except:
                    pass
            else:
                outfile = open(os.path.join(themes_dir_path, name), 'wb')
                outfile.write(zfobj.read(name))
                outfile.close()

        # Delete the zip file
        os.remove(theme_zip_path)

        # Move the themes out of the unzipped folder
        unzip_dir_path = os.path.join(themes_dir_path, unzip_dirname)
        if all_themes:
            for name in os.listdir(unzip_dir_path):
                # Check for themes
                if os.path.isdir(os.path.join(
                        unzip_dir_path, name)) and not name.startswith('.'):
                    # Check if the theme already exists
                    if not os.path.isdir(os.path.join(themes_dir_path, name)):
                        move(os.path.join(unzip_dir_path, name),
                             os.path.join(themes_dir_path, name))
        elif theme_name:
            move(os.path.join(unzip_dir_path, theme_name),
                 os.path.join(themes_dir_path, theme_name))

        rmtree(os.path.join(themes_dir_path, unzip_dirname))
        UpdateTracker.end()
Example #6
0
def update_tendenci_check(request):
    if not request.is_ajax():
        raise Http404

    tracker = UpdateTracker.get_or_create_instance()
    return HttpResponse(tracker.is_updating)
Example #7
0
    def handle(self, theme_name=None, theme_url=None, **options):
        """
        Downloads a theme to be installed on the site and sets
        it as the active theme.
        """
        from tendenci.core.base.models import UpdateTracker

        UpdateTracker.start()
        all_themes = options.get('all', False)

        if not theme_url:
            theme_url = "https://github.com/tendenci/tendenci-themes/archive/master.zip"

        if not (theme_name or all_themes):
            raise CommandError('Specify a theme name, or add --all for all themes')

        themes_dir_path = os.path.join(settings.PROJECT_ROOT, "themes")
        if theme_name:
            theme_path = os.path.join(themes_dir_path, theme_name)

            # Check if the theme already exists
            if os.path.isdir(theme_path):
                raise CommandError('The theme %s is already installed.' % theme_name)

        # Copy the theme files down
        theme_download = urllib.urlopen(theme_url)
        theme_zip_path = os.path.join(themes_dir_path, "themes.zip")
        theme_zip = open(theme_zip_path, 'wb')
        theme_zip.write(theme_download.read())
        theme_zip.close()

        # Unzip the theme files
        theme_zip_file = open(theme_zip_path, 'r')
        zfobj = zipfile.ZipFile(theme_zip_file)
        unzip_dirname = "themes"
        for i, name in enumerate(zfobj.namelist()):
            if i == 0:
                unzip_dirname = name[:-1]
            if name.endswith('/'):
                try:  # Don't try to create a directory if exists
                    os.mkdir(os.path.join(themes_dir_path, name))
                except:
                    pass
            else:
                outfile = open(os.path.join(themes_dir_path, name), 'wb')
                outfile.write(zfobj.read(name))
                outfile.close()

        # Delete the zip file
        os.remove(theme_zip_path)

        # Move the themes out of the unzipped folder
        unzip_dir_path = os.path.join(themes_dir_path, unzip_dirname)
        if all_themes:
            for name in os.listdir(unzip_dir_path):
                # Check for themes
                if os.path.isdir(os.path.join(unzip_dir_path, name)) and not name.startswith('.'):
                    # Check if the theme already exists
                    if not os.path.isdir(os.path.join(themes_dir_path, name)):
                        move(os.path.join(unzip_dir_path, name), os.path.join(themes_dir_path, name))
        elif theme_name:
            move(os.path.join(unzip_dir_path, theme_name), os.path.join(themes_dir_path, theme_name))

        rmtree(os.path.join(themes_dir_path, unzip_dirname))
        UpdateTracker.end()