Example #1
0
 def test_rm_r(self):
     "Remove the tree below something"
     newdir = tempfile.mkdtemp()
     os.mkdir(newdir + os.sep + 'subdir')
     filepath = newdir + os.sep + 'subdir' + os.sep + 'some.txt'
     with open(filepath, 'w'):
         pass  # touch()
     nix.rm(newdir, recursive=True)
Example #2
0
 def test_rm_r(self):
     "Remove the tree below something"
     newdir = tempfile.mkdtemp()
     os.mkdir(newdir + os.sep + 'subdir')
     filepath = newdir + os.sep + 'subdir' + os.sep + 'some.txt'
     with open(filepath, 'w'):
         pass # touch()
     nix.rm(newdir, recursive=True)
Example #3
0
 def test_rm_path(self):
     "Remove a Path"
     self.assertTrue(os.path.exists(self.newfile))
     nix.rm(Path(self.newfile))
     self.assertFalse(os.path.exists(self.newfile))
Example #4
0
 def test_rm(self):
     "Remove a file"
     self.assertTrue(os.path.exists(self.newfile))
     nix.rm(self.newfile)
     self.assertFalse(os.path.exists(self.newfile))
Example #5
0
 def tearDown(self):
     rm(self.tmpath)
     rm(self.tdir, force=True, recursive=True)
Example #6
0
 def tearDown(self):
     rm(self.tmpath)
     rm_r(self.tdir)
Example #7
0
def start_project(name, USERLAND_HERE):
    """
    In which we perform the steps required to start a new Opal project.

    1. Run Django' Startproject
    2. Create a data/lookuplists dir
    3. Copy across the scaffolding directory
    4. Interpolate our project data into the templates.
    5. Swap our scaffold app with the Django created app
    6. Interpolate the code templates from our scaffold app
    7. Create extra directories we need
    8. Run Django's migrations
    9. Create a superuser
    10. Initialise our git repo
    11. Load referencedata shipped with Opal
    """

    project_dir = USERLAND_HERE / name
    if project_dir:
        write("\n\nDirectory {0} already exists !".format(project_dir))
        write("Please remove it or choose a new name.\n\n")
        sys.exit(1)

    write("Bootstrapping your Opal project...")

    # 1. Run Django Startproject
    write("Creating project dir at {0}".format(project_dir))
    project_dir.mkdir()
    management.call_command('startproject', name, project_dir)

    # 3. Copy across the scaffold
    with SCAFFOLD:
        for p in SCAFFOLD.ls():
            target = project_dir / p[-1]
            p.cp(target)

    # Dotfiles need their dot back
    gitignore = project_dir / 'gitignore'
    gitignore.mv(project_dir / '.gitignore')

    # 4. Interpolate the project data
    interpolate_dir(project_dir,
                    name=name,
                    secret_key=get_random_secret_key(),
                    version=opal.__version__)

    app_dir = project_dir / name

    # 5. Django Startproject creates some things - let's kill them &
    # replace with our own things.
    nix.rm(app_dir, recursive=True, force=True)
    nix.mv(project_dir / 'app', app_dir)

    #  7. Create extra directories we need
    js = app_dir / 'static/js/{0}'.format(name)
    css = app_dir / 'static/css'
    js.mkdir()
    css.mkdir()
    nix.mv(app_dir / 'static/js/app/routes.js',
           app_dir / 'static/js/{0}/routes.js'.format(name))
    nix.mv(app_dir / 'static/js/app/flow.js',
           app_dir / 'static/js/{0}/flow.js'.format(name))

    templates = app_dir / 'templates' / name
    templates.mkdir()

    assets = app_dir / 'assets'
    assets.mkdir()
    assets_explainer = assets / 'README.md'
    assets_explainer << """
    This placeholder file is here to ensure that there we still have our
    STATICFILES_DIRS target if we commit generated code to source control.

    This means that we can run collectstatic OK.
    """

    # 2. Create lookup lists
    create_lookuplists(app_dir)

    # We have this here because it uses name from above.
    def manage(command):
        args = ['python', os.path.join(name, 'manage.py')]
        args += command.split()
        args.append('--traceback')
        call(args)

    # 8. Run Django's migrations
    write('Creating Database')
    manage('makemigrations {0}'.format(name))
    manage('migrate')

    # 9. Create a superuser
    write('Creating superuser')
    manage('createopalsuperuser')

    # 10. Initialise git repo
    call_if_exists(
        ('git', 'init'),
        'Unable to locate git; Skipping git repository initialization.',
        cwd=project_dir,
        stdout=subprocess.PIPE)

    # 11. Load referencedata shipped with Opal
    manage('load_lookup_lists')
Example #8
0
def start_project(name, USERLAND_HERE):
    """
    In which we perform the steps required to start a new Opal project.

    1. Run Django' Startproject
    2. Create a data/lookuplists dir
    3. Copy across the scaffolding directory
    4. Interpolate our project data into the templates.
    5. Swap our scaffold app with the Django created app
    6. Interpolate the code templates from our scaffold app
    7. Create extra directories we need
    8. Run Django's migrations
    9. Create a superuser
    10. Initialise our git repo
    """

    project_dir = USERLAND_HERE/name
    if project_dir:
        write("\n\nDirectory {0} already exists !".format(project_dir))
        write("Please remove it or choose a new name.\n\n")
        sys.exit(1)

    # 1. Run Django Startproject
    write("Creating project dir at {0}".format(project_dir))
    os.system('django-admin.py startproject {0}'.format(name))

    write("Bootstrapping your Opal project...")

    if not project_dir:
        project_dir.mkdir()

    # Copy across the scaffold
    with SCAFFOLD:
        for p in SCAFFOLD.ls():
            target = project_dir/p[-1]
            p.cp(target)

    # Dotfiles need their dot back
    gitignore = project_dir/'gitignore'
    gitignore.mv(project_dir/'.gitignore')

    # Interpolate the project data
    interpolate_dir(project_dir, name=name, secret_key=get_random_secret_key(),
                    version=opal.__version__)

    app_dir = project_dir/name

    # Django Startproject creates some things - let's kill them &
    # replace with our own things.
    nix.rm(app_dir, recursive=True, force=True)
    nix.mv(project_dir/'app', app_dir)

    #  Create extra directories we need
    js = app_dir/'static/js/{0}'.format(name)
    css = app_dir/'static/css'
    js.mkdir()
    css.mkdir()
    nix.mv(app_dir/'static/js/app/routes.js',
           app_dir/'static/js/{0}/routes.js'.format(name))
    nix.mv(app_dir/'static/js/app/flow.js',
           app_dir/'static/js/{0}/flow.js'.format(name))

    templates = app_dir/'templates'/name
    templates.mkdir()

    assets = app_dir/'assets'
    assets.mkdir()
    assets_explainer = assets/'README.md'
    assets_explainer << """
    This placeholder file is here to ensure that there we still have our
    STATICFILES_DIRS target if we commit generated code to source control.

    This means that we can run collectstatic OK.
    """

    # Create lookup lists
    create_lookuplists(app_dir)

    # We have this here because it uses name from above.
    def manage(command):
        args = ['python', '{0}/manage.py'.format(name)]
        args += command.split()
        args.append('--traceback')

        try:
            subprocess.check_call(args)
        except subprocess.CalledProcessError:
            sys.exit(1)
        return

    # 8. Run Django's migrations
    write('Creating Database')
    manage('makemigrations {0}'.format(name))
    manage('migrate')

    # 9. Create a superuser
    sys.path.append(os.path.join(os.path.abspath('.'), name))
    _set_settings_module(name)

    from django.contrib.auth.models import User
    user = User(username='******')
    user.set_password('super1')
    user.is_superuser = True
    user.is_staff = True
    user.save()
    from opal.models import UserProfile
    profile, _ = UserProfile.objects.get_or_create(user=user)
    profile.force_password_change = False
    profile.save()

    # 11. Initialise git repo
    os.system('cd {0}; git init'.format(name))
Example #9
0
 def test_rm_raises(self):
     "Raise if a file does not exist"
     nofile = 'my/nonexistant/file.txt'
     self.assertFalse(os.path.exists(nofile))
     with self.assertRaises(exceptions.DoesNotExistError):
         nix.rm(nofile)
Example #10
0
 def test_rm_f(self):
     "Remove a nonexistant file without error"
     nofile = 'my/nonexistant/file.txt'
     self.assertFalse(os.path.exists(nofile))
     nix.rm(nofile, force=True)
     self.assertFalse(os.path.exists(nofile))
Example #11
0
 def test_rm_path(self):
     "Remove a Path"
     self.assertTrue(os.path.exists(self.newfile))
     nix.rm(Path(self.newfile))
     self.assertFalse(os.path.exists(self.newfile))
Example #12
0
 def test_rm(self):
     "Remove a file"
     self.assertTrue(os.path.exists(self.newfile))
     nix.rm(self.newfile)
     self.assertFalse(os.path.exists(self.newfile))
Example #13
0
 def tearDown(self):
     nix.rm(self.tfile, force=True)
     nix.rm_r(self.tdir)
Example #14
0
 def tearDown(self):
     rm(self.tmpath)
     rm(self.tdir, force=True, recursive=True)
Example #15
0
 def tearDown(self):
     rm(self.tmpath)
     rm_r(self.tdir)
Example #16
0
 def test_rm_f(self):
     "Remove a nonexistant file without error"
     nofile = 'my/nonexistant/file.txt'
     self.assertFalse(os.path.exists(nofile))
     nix.rm(nofile, force=True)
     self.assertFalse(os.path.exists(nofile))
Example #17
0
 def test_rm_raises(self):
     "Raise if a file does not exist"
     nofile = 'my/nonexistant/file.txt'
     self.assertFalse(os.path.exists(nofile))
     with self.assertRaises(exceptions.DoesNotExistError):
         nix.rm(nofile)
Example #18
0
 def rm(self, resource, recursive=False):
     return nix.rm(resource, recursive=recursive)
Example #19
0
def startproject(args, USERLAND_HERE):
    """
    In which we perform the steps required to start a new OPAL project.

    1. Run Django' Startproject
    2. Create a data/lookuplists dir
    3. Copy across the scaffolding directory
    4. Interpolate our project data into the templates.
    5. Swap our scaffold app with the Django created app
    6. Interpolate the code templates from our scaffold app
    7. Create extra directories we need
    8. Run Django's migrations
    9. Create a superuser
    10. Initialise our git repo
    """
    name = args.name

    project_dir = USERLAND_HERE / name
    if project_dir:
        write("\n\nDirectory {0} already exists !".format(project_dir))
        write("Please remove it or choose a new name.\n\n")
        sys.exit(1)

    # 1. Run Django Startproject
    write("Creating project dir at {0}".format(project_dir))
    os.system('django-admin.py startproject {0}'.format(name))

    write("Bootstrapping your OPAL project...")

    # 2. Create empty directories
    lookuplists = project_dir / 'data/lookuplists'
    lookuplists.mkdir()

    # 3. Copy across the scaffold
    with SCAFFOLD:
        for p in SCAFFOLD.ls():
            target = project_dir / p[-1]
            p.cp(target)

    # Dotfiles need their dot back
    gitignore = project_dir / 'gitignore'
    gitignore.mv(project_dir / '.gitignore')

    # 3. Interpolate the project data
    interpolate_dir(project_dir, name=name, secret_key=get_random_secret_key())

    app_dir = project_dir / name

    # 5. Django Startproject creates some things - let's kill them &
    # replace with our own things.
    nix.rm(app_dir, recursive=True, force=True)
    nix.mv(project_dir / 'app', app_dir)

    # 7. Create extra directories we need
    js = app_dir / 'static/js/{0}'.format(name)
    css = app_dir / 'static/css'
    js.mkdir()
    css.mkdir()
    nix.mv(app_dir / 'static/js/app/routes.js',
           app_dir / 'static/js/{0}/routes.js'.format(name))
    nix.mv(app_dir / 'static/js/app/flow.js',
           app_dir / 'static/js/{0}/flow.js'.format(name))

    templates = app_dir / 'templates' / name
    templates.mkdir()

    assets = app_dir / 'assets'
    assets.mkdir()
    assets_explainer = assets / 'README.md'
    assets_explainer << """
    This placeholder file is here to ensure that there we still have our STATICFILES_DIRS target
    if we commit generated code to source control.

    This means that we can run collectstatic OK.
    """

    # We have this here because it uses name from above.
    def manage(command):
        args = ['python', '{0}/manage.py'.format(name)]
        args += command.split()
        args.append('--traceback')

        try:
            subprocess.check_call(args)
        except subprocess.CalledProcessError:
            sys.exit(1)
        return

    # 8. Run Django's migrations
    write('Creating Database')
    manage('makemigrations {0}'.format(name))
    manage('migrate')

    # 9. Create a superuser
    sys.path.append(os.path.join(os.path.abspath('.'), name))
    _set_settings_module(name)

    from django.contrib.auth.models import User
    user = User(username='******')
    user.set_password('super1')
    user.is_superuser = True
    user.is_staff = True
    user.save()
    from opal.models import UserProfile
    profile, _ = UserProfile.objects.get_or_create(user=user)
    profile.force_password_change = False
    profile.save()

    # 11. Initialise git repo
    os.system('cd {0}; git init'.format(name))
Example #20
0
def start_project(name, USERLAND_HERE):
    """
    In which we perform the steps required to start a new Opal project.

    1. Run Django' Startproject
    2. Create a data/lookuplists dir
    3. Copy across the scaffolding directory
    4. Interpolate our project data into the templates.
    5. Swap our scaffold app with the Django created app
    6. Interpolate the code templates from our scaffold app
    7. Create extra directories we need
    8. Run Django's migrations
    9. Create a superuser
    10. Initialise our git repo
    11. Load referencedata shipped with Opal
    """

    project_dir = USERLAND_HERE/name
    if project_dir:
        write("\n\nDirectory {0} already exists !".format(project_dir))
        write("Please remove it or choose a new name.\n\n")
        sys.exit(1)

    write("Bootstrapping your Opal project...")

    # 1. Run Django Startproject
    write("Creating project dir at {0}".format(project_dir))
    project_dir.mkdir()
    management.call_command('startproject', name, project_dir)

    # 3. Copy across the scaffold
    with SCAFFOLD:
        for p in SCAFFOLD.ls():
            target = project_dir/p[-1]
            p.cp(target)

    # Dotfiles need their dot back
    gitignore = project_dir/'gitignore'
    gitignore.mv(project_dir/'.gitignore')

    # 4. Interpolate the project data
    interpolate_dir(project_dir, name=name, secret_key=get_random_secret_key(),
                    version=opal.__version__)

    app_dir = project_dir/name

    # 5. Django Startproject creates some things - let's kill them &
    # replace with our own things.
    nix.rm(app_dir, recursive=True, force=True)
    nix.mv(project_dir/'app', app_dir)

    #  7. Create extra directories we need
    js = app_dir/'static/js/{0}'.format(name)
    css = app_dir/'static/css'
    js.mkdir()
    css.mkdir()
    nix.mv(app_dir/'static/js/app/routes.js',
           app_dir/'static/js/{0}/routes.js'.format(name))

    templates = app_dir/'templates'/name
    templates.mkdir()

    assets = app_dir/'assets'
    assets.mkdir()
    assets_explainer = assets/'README.md'
    assets_explainer << """
    This placeholder file is here to ensure that there we still have our
    STATICFILES_DIRS target if we commit generated code to source control.

    This means that we can run collectstatic OK.
    """

    # 2. Create lookup lists
    create_lookuplists(app_dir)

    # We have this here because it uses name from above.
    def manage(command):
        args = ['python', os.path.join(name, 'manage.py')]
        args += command.split()
        args.append('--traceback')
        call(args)

    # 8. Run Django's migrations
    write('Creating Database')
    manage('makemigrations {0}'.format(name))
    manage('migrate')

    # 9. Create a superuser
    write('Creating superuser')
    manage('createopalsuperuser')

    # 10. Initialise git repo
    call_if_exists(
        ('git', 'init'),
        'Unable to locate git; Skipping git repository initialization.',
        cwd=project_dir, stdout=subprocess.PIPE
    )

    # 11. Load referencedata shipped with Opal
    manage('load_lookup_lists')