Browse Source

Remove scripts that are deprecated or superseded by ./dev

rafalp 6 years ago
parent
commit
61f8b243e9

+ 0 - 6
cleansource

@@ -1,6 +0,0 @@
-#!/bin/bash
-
-yapf -ir ${1:-misago} -e '*/project_template/**/*.py' -e '*/conf/defaults.py'
-isort -rc ${1:-misago}
-pylint ${1:-misago}
-python pycodestyle.py ${1:-misago}

+ 0 - 0
extras/__init__.py


+ 0 - 5
extras/config.py

@@ -1,5 +0,0 @@
-from django.utils.six.moves import configparser
-
-
-yapf = configparser.ConfigParser()
-yapf.read('.style.yapf')

+ 0 - 59
extras/createdevproject.py

@@ -1,59 +0,0 @@
-"""
-Creates a dev project for local development
-"""
-
-import os
-import sys
-
-from misago.core import setup
-
-
-BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-
-
-def main():
-    project_name = os.environ['PROJECT_NAME']
-
-    # Allow for overriding project name
-    if len(sys.argv) > 1:
-        project_name = sys.argv[1]
-    else:
-        sys.argv.append(project_name)
-
-    settings_file = os.path.join(BASE_DIR, project_name, 'settings.py')
-
-    # Avoid recreating if already present
-    if os.path.exists(settings_file):
-        return
-
-    setup.start_misago_project()
-    fill_in_settings(settings_file)
-
-
-def fill_in_settings(f):
-    with open(f, 'r') as fd:
-        s = fd.read()
-
-        # Postgres
-        s = s.replace("'NAME': '',", "'NAME': os.environ.get('POSTGRES_DB'),")
-        s = s.replace("'USER': '',", "'USER': os.environ.get('POSTGRES_USER'),")
-        s = s.replace("'PASSWORD': '',", "'PASSWORD': os.environ.get('POSTGRES_PASSWORD'),")
-        s = s.replace("'HOST': 'localhost',", "'HOST': os.environ.get('POSTGRES_HOST'),")
-
-        # Specify console backend for email
-        s += "\nEMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'\n"
-
-        # Empty the contents of STATICFILES_DIRS (STATICFILES_DIRS = [])
-        pos = s.find('STATICFILES_DIRS')
-        s = s[:s.find('[', pos) + 1] + s[s.find(']', pos):]
-
-        # Remote theme dir from template dirs
-        pos = s.find("'DIRS': [")
-        s = s[:s.find('[', pos) + 1] + s[s.find(']', pos):]
-
-    with open(f, 'w') as fd:
-        fd.write(s)
-
-
-if __name__ == '__main__':
-    main()

+ 0 - 27
extras/createsuperuser.py

@@ -1,27 +0,0 @@
-"""
-Create superuser for the devproject
-"""
-
-import os
-import django
-
-os.environ['DJANGO_SETTINGS_MODULE'] = '{}.settings'.format(os.environ['PROJECT_NAME'])
-django.setup()
-
-from django.contrib.auth import get_user_model
-from django.utils.crypto import get_random_string
-
-User = get_user_model()
-
-
-if User.objects.count() == 0:
-    superuser = User.objects.create_superuser(
-        os.environ['SUPERUSER_USERNAME'],
-        os.environ['SUPERUSER_EMAIL'],
-        get_random_string(10), # set throwaway password
-        set_default_avatar=True,
-    )
-
-    # Override user's throwaway password with configured one
-    superuser.set_password(os.environ['SUPERUSER_PASSWORD'])
-    superuser.save()

+ 0 - 93
extras/fixabsoluteimports.py

@@ -1,93 +0,0 @@
-import os
-
-
-def walk_directory(root, dirs, files):
-    for file_path in files:
-        if 'project_template' not in root and file_path.lower().endswith('.py'):
-            clean_file(os.path.join(root, file_path))
-
-
-def clean_file(file_path):
-    py_source = file(file_path).read()
-    if 'misago.' in py_source:
-        package = file_path.rstrip('.py').split('/')
-
-        parse_file = True
-        save_file = False
-        cursor = 0
-
-        while parse_file:
-            try:
-                import_start = py_source.index('from ', cursor)
-                import_end = py_source.index(' import', import_start)
-                cursor = import_end
-
-                import_len = import_end - import_start
-                import_path = py_source[import_start:import_end].lstrip('from').strip()
-
-                if import_path.startswith('misago.'):
-                    cleaned_import = clean_import(package, import_path.split('.'))
-                    if cleaned_import:
-                        save_file = True
-
-                        cleaned_import_string = 'from {}'.format('.'.join(cleaned_import))
-                        py_source = ''.join((py_source[:import_start], cleaned_import_string, py_source[import_end:]))
-                        cursor -= import_end - import_start - len(cleaned_import_string)
-            except ValueError:
-                parse_file = False
-
-        if save_file:
-            with open(file_path, 'w') as package:
-                print file_path
-                package.write(py_source)
-
-
-def clean_import(package, import_path):
-    if len(package) < 2 or len(import_path) < 2:
-        # skip non-app import
-        return
-
-    if package[:2] != import_path[:2]:
-        # skip other app import
-        return
-
-    if package == import_path:
-        # import from direct child
-        return ['', '']
-
-    if package[:-1] == import_path[:-1]:
-        # import from sibling module
-        return ['', import_path[-1]]
-
-    if len(package) < len(import_path) and package == import_path[:len(package)]:
-        # import from child module
-        return [''] + import_path[len(package):]
-
-    if len(package) > len(import_path) and package[:len(import_path)] == import_path:
-        # import from parent module
-        return [''] * (len(package) - len(import_path) + 1)
-
-    # relative up and down path
-    relative_path = []
-
-    # find upwards path
-    overlap_len = 2
-    while True:
-        if package[:overlap_len + 1] != import_path[:overlap_len + 1]:
-            break
-        overlap_len += 1
-
-    relative_path += ([''] * (len(package) - overlap_len))[:-1]
-
-    # append eventual downwards path
-    if import_path[overlap_len:]:
-        relative_path += [''] + import_path[overlap_len:]
-
-    return relative_path
-
-
-if __name__ == '__main__':
-    for args in os.walk('../misago'):
-        walk_directory(*args)
-
-    print "\nDone! Don't forget to run isort to fix imports ordering!"

+ 0 - 160
extras/fixdictsformatting.py

@@ -1,160 +0,0 @@
-from __future__ import unicode_literals
-
-import sys
-
-from lib2to3.pytree import Node, Leaf
-from lib2to3.fixer_util import token, syms
-
-from yapf.yapflib import pytree_utils
-
-from django.utils import six
-
-from .config import yapf as yapf_config
-
-
-MAX_LINE_LENGTH = yapf_config.getint('style', 'column_limit') + 1
-
-
-def fix_formatting(filesource):
-    if not ('{'  in filesource and ('[' in filesource or '(' in filesource)):
-        return filesource
-
-    tree = pytree_utils.ParseCodeToTree(filesource)
-    for node in tree.children:
-        walk_tree(node, node.children)
-    return six.text_type(tree)
-
-
-def walk_tree(node, children):
-    for item in children:
-        if item.type == syms.dictsetmaker:
-            indent = item.parent.children[-1].column
-            walk_dict_tree(item, item.children, indent)
-        else:
-            walk_tree(item, item.children)
-
-
-def walk_dict_tree(node, children, indent):
-    for item in children:
-        prev = item.prev_sibling
-        if isinstance(prev, Leaf) and prev.value == ':':
-            if isinstance(item, Leaf):
-                if six.text_type(item).startswith("\n"):
-                    item.replace(Leaf(
-                        item.type,
-                        item.value,
-                        prefix=' ',
-                    ))
-            elif six.text_type(item).strip()[0] in ('[', '{'):
-                walk_tree(item, item.children)
-            else:
-                walk_dedent_tree(item, item.children, indent)
-
-
-def walk_dedent_tree(node, children, indent):
-    force_split_next = False
-    for item in children:
-        prev = item.prev_sibling
-        if not prev:
-            if isinstance(item, Leaf) and six.text_type(item).startswith("\n"):
-                prev = node.prev_sibling
-                next = node.next_sibling
-                final_length = 0
-
-                if prev and "\n" not in six.text_type(node).strip():
-                    final_length = prev.column + len(six.text_type(node).strip()) + 3
-
-                item.replace(Leaf(
-                    item.type,
-                    item.value,
-                    prefix=' ',
-                ))
-
-                if final_length and final_length > MAX_LINE_LENGTH:
-                    # tell next call to walk_dedent_tree_node that we need
-                    # different stringformat tactic
-                    force_split_next = True
-        elif isinstance(item, Node):
-            if node.type == syms.power:
-                for subitem in item.children[1:]:
-                    walk_dedent_power_node(subitem, subitem.children, indent)
-            else:
-                for subitem in item.children[1:]:
-                    walk_dedent_tree_node(subitem, subitem.children, indent, force_split_next)
-                    force_split_next = False
-
-
-def walk_dedent_tree_node(node, children, indent, force_split_next=False):
-    if six.text_type(node).startswith("\n"):
-        if isinstance(node, Leaf):
-            prev = node.prev_sibling
-            next = node.next_sibling
-
-            is_followup = prev and prev.type == token.STRING and node.type == token.STRING
-            if is_followup:
-                new_value = node.value
-
-                # insert linebreak after last string in braces, so its closing brace moves to new line
-                if not node.next_sibling:
-                    closing_bracket = node.parent.parent.children[-1]
-                    if not six.text_type(closing_bracket).startswith("\n"):
-                        new_value = "%s\n%s" % (node.value, (' ' * (indent + 4)))
-
-                node.replace(Leaf(
-                    node.type,
-                    new_value,
-                    prefix="\n%s" % (' ' * (indent + 8)),
-                ))
-            else:
-                if six.text_type(node).strip() in (')', '}'):
-                    new_prefix = "\n%s" % (' ' * (indent + 4))
-                else:
-                    new_prefix = "\n%s" % (' ' * (indent + 8))
-
-                node.replace(Leaf(
-                    node.type,
-                    node.value,
-                    prefix=new_prefix
-                ))
-        else:
-            for item in children:
-                walk_dedent_tree_node(item, item.children, indent)
-    elif isinstance(node, Leaf):
-        if node.type == token.STRING:
-            strings_tuple = node.parent.parent
-
-            prev = node.prev_sibling
-            next = node.next_sibling
-
-            is_opening = prev is None and six.text_type(strings_tuple).strip()[0] == '('
-            has_followup = next and next.type == token.STRING
-
-            if is_opening and has_followup:
-                node.replace(Leaf(
-                    node.type,
-                    node.value,
-                    prefix="\n%s" % (' ' * (indent + 8)),
-                ))
-            elif force_split_next:
-                node.replace(Leaf(
-                    node.type,
-                    "%s\n%s" % (node.value, (' ' * (indent + 4))),
-                    prefix="\n%s" % (' ' * (indent + 8)),
-                ))
-    else:
-        for item in children:
-            walk_dedent_tree_node(item, item.children, indent)
-
-
-def walk_dedent_power_node(node, children, indent):
-    if isinstance(node, Leaf):
-        if six.text_type(node).startswith("\n"):
-            node.replace(Leaf(
-                node.type,
-                node.value,
-                prefix=node.prefix[:-4],
-            ))
-    else:
-        for item in children:
-            walk_dedent_power_node(item, item.children, indent)
-

+ 0 - 53
extras/fixrelativeimports.py

@@ -1,53 +0,0 @@
-import os
-import re
-
-
-RELATIVE_IMPORT = re.compile(r'(from|import) \.\.+([a-z]+)?')
-
-
-def walk_directory(root, dirs, files):
-    for file_path in files:
-        if 'project_template' not in root and file_path.lower().endswith('.py'):
-            clean_file(os.path.join(root, file_path))
-
-
-def clean_file(file_path):
-    py_source = file(file_path).read()
-    if 'from ..' in py_source or 'import ..' in py_source:
-        print '====' * 8
-        print file_path
-        print '====' * 8
-
-        package = file_path.rstrip('.py').split('/')
-
-        def replace_import(matchobj):
-            prefix, suffix = matchobj.group(0).split()
-            return '{} {}'.format(prefix, clean_import(package, suffix))
-
-        py_source = RELATIVE_IMPORT.sub(replace_import, py_source)
-
-        #print py_source
-        with open(file_path, 'w') as package:
-            print file_path
-            package.write(py_source)
-
-
-def clean_import(package, match):
-    path = match[1:]
-
-    import_path = package[:]
-    while match and match[0] == '.':
-        import_path = import_path[:-1]
-        match = match[1:]
-
-    if match:
-        import_path.append(match)
-
-    return '.'.join(import_path)
-
-
-if __name__ == '__main__':
-    for args in os.walk('../misago'):
-        walk_directory(*args)
-
-    print "\nDone! Don't forget to run isort to fix imports ordering!"

+ 0 - 2
extras/psql.sh

@@ -1,2 +0,0 @@
-#!/usr/bin/env bash
-PGPASSWORD=$POSTGRES_PASSWORD psql --username $POSTGRES_USER --host $POSTGRES_HOST $POSTGRES_DB

+ 0 - 10
extras/wait_for_postgres.sh

@@ -1,10 +0,0 @@
-#!/usr/bin/env bash
-# Sometimes postgres is not ready before django attempts to connect.
-# This script waits until we can do a basic select before continuing.
-export PGPASSWORD=$POSTGRES_PASSWORD
-RETRIES=10
-
-until psql -h $POSTGRES_HOST -U $POSTGRES_USER -d $POSTGRES_DB -c "select 1" > /dev/null 2>&1 || [ $RETRIES -eq 0 ]; do
-  echo "Waiting for postgres server, $((RETRIES--)) remaining attempts..."
-  sleep 5
-done

+ 0 - 58
initdev

@@ -1,58 +0,0 @@
-#!/usr/bin/env bash
-# This script is a shortcut for configuring newly-build docker container for Misago development
-python setup.py develop
-
-# Clear OS files
-rm -f /srv/misago/.DS_Store
-rm -f /srv/misago/Thumbs.db
-
-# If user specified "-f", clear after previous devinit
-if [ "$1" = "-f" ]
-then
-    echo "Cleaned files created by previous initdev"
-    rm -f /srv/misago/cron.txt
-    rm -f /srv/misago/manage.py
-    rm -rf /srv/misago/avatargallery
-    rm -rf /srv/misago/$PROJECT_NAME
-    rm -rf /srv/misago/media
-    rm -rf /srv/misago/static
-    rm -rf /srv/misago/theme
-    rm -rf /srv/misago/userdata
-fi
-
-# Create new project
-python extras/createdevproject.py $PROJECT_NAME /srv/misago
-
-# Clean up unnecessary project files
-rm -rf theme
-rm -f cron.txt
-
-# Database
-./extras/wait_for_postgres.sh
-python manage.py migrate
-python extras/createsuperuser.py
-
-# Print short bit of help at the end of cript
-RED='\033[0;31m'
-DEFAULT='\033[0m'
-
-echo ""
-echo "================================================================================"
-echo ""
-echo "Note: running 'initdev' after already having used it to setup Misago"
-echo "for development may result in any of following errors occuring:"
-echo ""
-echo "  - CommandError: /srv/misago/... already exists, overlaying a project or app into an existing directory won't replace conflicting files"
-echo "  - ModuleNotFoundError: No module named '$PROJECT_NAME'"
-echo "  - django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the NAME value."
-echo "  - python: can't open file 'manage.py': [Errno 2] No such file or directory"
-echo ""
-echo "If you are experiencing either of those errors, this means that files are"
-echo "present in the repository's main directory preventing 'initdev' from succedding."
-echo "Please try running the 'initdev' with \"-f\" option to force old files deletion:"
-echo ""
-echo "  docker-compose run --rm misago initdev -f"
-echo ""
-echo -e "${RED}Warning:${DEFAULT} if you have uncommited changes to Misago's setup that should be included"
-echo "in next release, make sure that they are commited to 'misago/project_template'"
-echo "or 'initdev -f' will overwrite the files causing them to be lost."

+ 0 - 8
makemessages

@@ -1,8 +0,0 @@
-#!/bin/bash
-cd misago
-
-echo "Extracting messages from .py and .html files..."
-django-admin.py makemessages -l $1 -e html,txt,py
-
-echo "Extracting messages from js files..."
-django-admin.py makemessages -l $1 -d djangojs

+ 0 - 3
pyclean

@@ -1,3 +0,0 @@
-#!/bin/bash
-
-find ./misago -name '*.pyc' -delete -not -path './misago/frontend/*'

+ 0 - 38
pycodestyle.py

@@ -1,38 +0,0 @@
-"""
-Code style cleanups done after yapf
-"""
-import argparse
-import codecs
-import os
-
-from extras import fixdictsformatting
-
-
-CLEANUPS = [
-    fixdictsformatting,
-]
-
-
-def walk_directory(root, dirs, files):
-    for filename in files:
-        if filename.lower().endswith('.py'):
-            with codecs.open(os.path.join(root, filename), 'r', 'utf-8') as f:
-                filesource = f.read()
-
-            org_source = filesource
-
-            for cleanup in CLEANUPS:
-                filesource = cleanup.fix_formatting(filesource)
-
-            if org_source != filesource:
-                print 'afterclean: %s' % os.path.join(root, filename)
-                with codecs.open(os.path.join(root, filename), 'w', 'utf-8') as f:
-                    f.write(filesource)
-
-
-if __name__ == '__main__':
-    parser = argparse.ArgumentParser()
-    parser.add_argument('path', nargs='?', default='./')
-
-    for args in os.walk(parser.parse_args().path):
-        walk_directory(*args)

+ 0 - 2
upload

@@ -1,2 +0,0 @@
-#!/bin/sh
-python setup.py sdist upload