-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into add-driver-method-to-drivers
- Loading branch information
Showing
19 changed files
with
560 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ source = masonite | |
[report] | ||
ignore_errors = True | ||
omit = | ||
*/tests/* | ||
*/tests/* | ||
masonite/commands/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from cleo import Command | ||
import os | ||
import shutil | ||
|
||
|
||
class AuthCommand(Command): | ||
""" | ||
Creates an authentication system | ||
auth | ||
""" | ||
|
||
def handle(self): | ||
self.info('Scaffolding Application ...') | ||
module_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
f = open('routes/web.py', 'a') | ||
# add all the routes | ||
f.write('\nROUTES = ROUTES + [\n ') | ||
f.write("Get().route('/login', 'LoginController@show'),\n ") | ||
f.write("Get().route('/logout', 'LoginController@logout'),\n ") | ||
f.write("Post().route('/login', 'LoginController@store'),\n ") | ||
f.write("Get().route('/register', 'RegisterController@show'),\n ") | ||
f.write("Post().route('/register', 'RegisterController@store'),\n ") | ||
f.write("Get().route('/home', 'HomeController@show'),\n") | ||
f.write(']\n') | ||
|
||
# move controllers | ||
shutil.copyfile(module_path+"/../masonite_snippets/auth/controllers/LoginController.py", | ||
os.getcwd()+"/app/http/controllers/LoginController.py") | ||
shutil.copyfile(module_path+"/../masonite_snippets/auth/controllers/RegisterController.py", | ||
os.getcwd()+"/app/http/controllers/RegisterController.py") | ||
shutil.copyfile(module_path+"/../masonite_snippets/auth/controllers/HomeController.py", | ||
os.getcwd()+"/app/http/controllers/HomeController.py") | ||
|
||
# move templates | ||
shutil.copytree(module_path + "/../masonite_snippets/auth/templates/auth", | ||
os.getcwd()+"/resources/templates/auth") | ||
|
||
self.info('Project Scaffolded. You now have 4 new controllers, 5 new templates and 6 new routes') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from cleo import Command | ||
import os | ||
|
||
|
||
class CommandCommand(Command): | ||
""" | ||
Creates a new command | ||
command | ||
{name : Name of the command you would like to create} | ||
""" | ||
|
||
def handle(self): | ||
command = self.argument('name') | ||
if not os.path.isfile('app/commands/{0}.py'.format(command)): | ||
if not os.path.exists(os.path.dirname('app/commands/{0}.py'.format(command))): | ||
# Create the path to the command if it does not exist | ||
os.makedirs(os.path.dirname('app/commands/{0}.py'.format(command))) | ||
|
||
f = open('app/commands/{0}.py'.format(command), 'w+') | ||
|
||
f.write('""" A {0} Command """\n'.format(command)) | ||
f.write('from cleo import Command\n\n\n') | ||
f.write('class {0}(Command):\n """\n Description of command\n\n '.format(command)) | ||
f.write('command:name\n {argument : description}\n """\n\n ') | ||
f.write('def handle(self):\n pass') | ||
|
||
self.info('Command Created Successfully!') | ||
else: | ||
self.error('Command Already Exists!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from cleo import Command | ||
import os | ||
|
||
|
||
class ControllerCommand(Command): | ||
""" | ||
Creates a controller | ||
controller | ||
{name : Name of the view you would like to create} | ||
""" | ||
|
||
def handle(self): | ||
controller = self.argument('name') | ||
if os.path.isfile('app/http/controllers/{0}.py'.format(controller)): | ||
self.error('{0} Controller Exists!'.format(controller)) | ||
else: | ||
f = open('app/http/controllers/{0}.py'.format(controller), 'w+') | ||
f.write("''' A Module Description '''\n\n") | ||
f.write('class {0}:\n'.format(controller)) | ||
f.write(" ''' Class Docstring Description '''\n\n") | ||
f.write(' def show(self):\n') | ||
f.write(' pass\n') | ||
|
||
self.info('{0} Created Successfully!'.format(controller)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from cleo import Command | ||
from subprocess import call | ||
import os | ||
import shutil | ||
|
||
class InstallCommand(Command): | ||
""" | ||
Installs all of Masonite's dependencies | ||
install | ||
""" | ||
|
||
def handle(self): | ||
call(["pip3", "install", "-r", "requirements.txt"]) | ||
|
||
# create the .env file if it does not exist | ||
if not os.path.isfile('.env'): | ||
shutil.copy('.env-example', '.env') | ||
|
||
call(["craft", "key", "--store"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from cleo import Command | ||
import os | ||
from cryptography.fernet import Fernet | ||
|
||
|
||
class JobCommand(Command): | ||
""" | ||
Creates a new Job | ||
job | ||
{name : Name of the job you want to create} | ||
""" | ||
|
||
def handle(self): | ||
job = self.argument('name') | ||
if not os.path.isfile('app/jobs/{0}.py'.format(job)): | ||
if not os.path.exists(os.path.dirname('app/jobs/{0}.py'.format(job))): | ||
# Create the path to the job if it does not exist | ||
os.makedirs(os.path.dirname('app/jobs/{0}.py'.format(job))) | ||
|
||
f = open('app/jobs/{0}.py'.format(job), 'w+') | ||
|
||
f.write("''' A {0} Queue Job '''\n\n".format(job)) | ||
f.write('from masonite.queues.Queueable import Queueable\n\n') | ||
f.write("class {0}(Queueable):\n\n ".format(job)) | ||
f.write("def __init__(self):\n pass\n\n ") | ||
f.write("def handle(self):\n pass\n") | ||
|
||
self.info('Job Created Successfully!') | ||
else: | ||
self.comment('Job Already Exists!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from cleo import Command | ||
import os | ||
from cryptography.fernet import Fernet | ||
|
||
|
||
class KeyCommand(Command): | ||
""" | ||
Generate a new key | ||
key | ||
{--s|--store : Stores the key in the .env file} | ||
""" | ||
|
||
def handle(self): | ||
store = self.option('store') | ||
key = bytes(Fernet.generate_key()).decode('utf-8') | ||
|
||
if store: | ||
with open('.env', 'r') as file: | ||
# read a list of lines into data | ||
data = file.readlines() | ||
|
||
# change the line that starts with KEY= | ||
for line_number, line in enumerate(data): | ||
if line.startswith('KEY='): | ||
data[line_number] = 'KEY={0}\n'.format(key) | ||
break | ||
|
||
# and write everything back | ||
with open('.env', 'w') as file: | ||
file.writelines(data) | ||
|
||
self.info('Key added to your .env file: {0}'.format(key)) | ||
else: | ||
self.info("Key: {0}".format(key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from cleo import Command | ||
import os | ||
from subprocess import call | ||
|
||
|
||
class MakeMigrationCommand(Command): | ||
""" | ||
Makes a new migration | ||
migration | ||
{name : Name of your migration} | ||
{--t|--table=False : Table you are migrating for} | ||
{--c|--create=False : Table you want to create with this migration} | ||
""" | ||
|
||
def handle(self): | ||
name = self.argument('name') | ||
|
||
if self.option('create') != 'False': | ||
call(['orator', 'make:migration', name, | ||
'-p', 'databases/migrations', '--table', self.option('create'), '--create']) | ||
elif self.option('table') != 'False': | ||
call(['orator', 'make:migration', name, | ||
'-p', 'databases/migrations', '--table', self.option('table')]) | ||
else: | ||
call(['orator', 'make:migration', name, | ||
'-p', 'databases/migrations']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from cleo import Command | ||
import os | ||
import sys | ||
from masonite.packages import add_venv_site_packages | ||
from subprocess import check_output | ||
|
||
|
||
class MigrateCommand(Command): | ||
""" | ||
Run migrations | ||
migrate | ||
""" | ||
|
||
def handle(self): | ||
sys.path.append(os.getcwd()) | ||
try: | ||
add_venv_site_packages() | ||
except ImportError: | ||
self.comment('This command must be ran inside of the root of a Masonite project directory') | ||
|
||
from wsgi import container | ||
|
||
|
||
migration_directory = ['databases/migrations'] | ||
for key, value in container.providers.items(): | ||
if 'MigrationDirectory' in key: | ||
migration_directory.append(value) | ||
|
||
for directory in migration_directory: | ||
self.line('') | ||
if len(migration_directory) > 1: | ||
self.info('Migrating: {0}'.format(directory)) | ||
try: | ||
output = bytes(check_output( | ||
['orator', 'migrate', '-c', 'config/database.py', '-p', directory, '-f'] | ||
)).decode('utf-8') | ||
|
||
self.line( | ||
output.replace('OK', '<info>OK</info>') \ | ||
.replace('Migrated', '<info>Migrated</info><fg=cyan>') + '</>' | ||
) | ||
except: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from cleo import Command | ||
import os | ||
from subprocess import check_output | ||
|
||
|
||
class MigrateRefreshCommand(Command): | ||
""" | ||
Migrate refresh | ||
migrate:refresh | ||
""" | ||
|
||
def handle(self): | ||
self.call('migrate:reset') | ||
self.call('migrate') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from cleo import Command | ||
import os | ||
import sys | ||
from masonite.packages import add_venv_site_packages | ||
from subprocess import check_output | ||
|
||
|
||
class MigrateResetCommand(Command): | ||
""" | ||
Migrate reset | ||
migrate:reset | ||
""" | ||
|
||
def handle(self): | ||
sys.path.append(os.getcwd()) | ||
try: | ||
add_venv_site_packages() | ||
from wsgi import container | ||
except ImportError: | ||
self.comment( | ||
'This command must be ran inside of the root of a Masonite project directory') | ||
|
||
|
||
# Get any migration files from the Service Container | ||
migration_directory = ['databases/migrations'] | ||
for key, value in container.providers.items(): | ||
if 'MigrationDirectory' in key: | ||
migration_directory.append(value) | ||
|
||
# Load in the Orator migration system | ||
from orator.migrations import Migrator, DatabaseMigrationRepository | ||
from config import database | ||
repository = DatabaseMigrationRepository(database.DB, 'migrations') | ||
migrator = Migrator(repository, database.DB) | ||
if not migrator.repository_exists(): | ||
repository.create_repository() | ||
|
||
# Create a new list of migrations with the correct file path instead | ||
migration_list = [] | ||
for migration in migrator.get_repository().get_ran(): | ||
for directory in migration_directory: | ||
if os.path.exists(os.path.join(directory, migration + '.py')): | ||
migration_list.append(os.path.join(os.getcwd(), directory)) | ||
break | ||
|
||
# Rollback the migrations | ||
notes = [] | ||
for migration in migrator.get_repository().get_ran(): | ||
for migration_directory in migration_list: | ||
try: | ||
migrator.reset(migration_directory) | ||
|
||
except: | ||
pass | ||
|
||
if migrator.get_notes(): | ||
notes += migrator.get_notes() | ||
|
||
|
||
# Show notes from the migrator | ||
self.line('') | ||
for note in notes: | ||
if not 'Nothing to rollback.' in note: | ||
self.line(note) | ||
if not notes: | ||
self.info('Nothing to rollback') |
Oops, something went wrong.