Esempio n. 1
0
 def __init__(self, driver=None, path=None):
     path = path or config('logging.channels.single.path')
     make_directory(path)
     self.max_level = config('logging.channels.single.level')
     self.driver = DriverFactory.make(
         driver or config('logging.channels.single.driver'))(
             path=path, max_level=self.max_level)
Esempio n. 2
0
    def store(self, fileitem, filename=None, location=None):
        """Store the file onto a server.

        Arguments:
            fileitem {cgi.Storage} -- Storage object.

        Keyword Arguments:
            location {string} -- The location on disk you would like to store the file. (default: {None})
            filename {string} -- A new file name you would like to name the file. (default: {None})

        Returns:
            string -- Returns the file name just saved.
        """

        # use the new filename or get it from the fileitem
        if filename is None:
            filename = self.get_name(fileitem)

        # Check if is a valid extension
        self.validate_extension(filename)

        location = self.get_location(location)

        location = os.path.join(location, filename)

        make_directory(location)

        if isinstance(fileitem, _io.TextIOWrapper):
            open(location, 'wb').write(bytes(fileitem.read(), 'utf-8'))
        else:
            open(location, 'wb').write(fileitem.file.read())

        self.file_location = location

        return filename
Esempio n. 3
0
 def __init__(self, driver=None, path=None):
     path = path or config('logging.channels.daily.path')
     path = os.path.join(path, self.get_time().to_date_string() + '.log')
     self.max_level = config('logging.channels.daily.level')
     make_directory(path)
     self.driver = DriverFactory.make(
         driver or config('logging.channels.daily.driver'))(
             path=path, max_level=self.max_level)
Esempio n. 4
0
def test_make_directory():
    dir_path = 'storage/uploads/test-dir'
    file_path = 'storage/uploads/test-dir/test.py'
    assert make_directory(dir_path)
    assert make_directory(file_path)
    with open(file_path, "w+"):
        pass
    assert not make_directory(file_path)
    shutil.rmtree(dir_path)
Esempio n. 5
0
 def test_make_directory(self):
     dir_path = 'storage/uploads/test-dir'
     file_path = 'storage/uploads/test-dir/test.py'
     self.assertTrue(make_directory(dir_path))
     self.assertTrue(make_directory(file_path))
     with open(file_path, "w+"):
         pass
     self.assertFalse(make_directory(file_path))
     shutil.rmtree(dir_path)
Esempio n. 6
0
    def handle(self):
        view = View(App())
        class_directory = 'databases/seeds/{}_table_seeder.py'.format(
            self.argument('table'))

        if not make_directory(class_directory):
            pass
            # return self.error('{0} Seeder Already Exists!'.format(self.argument('table')))

        conn = DB.get_schema_manager().list_table_columns(
            self.argument('table'))
        # docstring = '"""Model Definition (generated with love by Masonite) \n\n'
        # for name, column in conn.items():
        #     length = '({})'.format(column._length) if column._length else ''
        #     docstring += '{}: {}{} default: {}\n'.format(
        #         name, column.get_type(), length, column.get_default())

        f = open(class_directory, 'w+')
        if view.exists('scaffold/seed'):
            f.write(
                view.render('scaffold/seed', {
                    'table': self.argument('table'),
                    'columns': conn.items(),
                }).rendered_template)
            self.info('Seeder Created Successfully!')
            return f.close()
    def handle(self):
        class_name = self.argument('name')
        view = View(App())
        class_directory = '{}{}.py'.format(self.base_directory, class_name)

        if not make_directory(class_directory):
            return self.error('{0} Already Exists!'.format(self.scaffold_name))

        with open(class_directory, 'w+') as f:
            if view.exists(self.template):
                f.write(
                    view.render(self.template, {
                        'class': class_name.split('/')[-1]
                    }).rendered_template)
                self.info('{} Created Successfully!'.format(
                    self.scaffold_name))

        if self.option('migration'):
            model_name = class_name.lower() + 's'
            self.call('migration',
                      [('name', 'create_{}_table'.format(model_name)),
                       ('-c', model_name)])

        if self.option('seed'):
            seed_file = model_name
            seed_file = self.option('seed')

            self.call('seed', [('table', seed_file)])
Esempio n. 8
0
    def handle(self):
        class_name = self.argument('name') + self.postfix
        view = View(App())
        class_directory = '{}{}{}{}'.format(
            self.base_directory, class_name, self.suffix, self.file_extension)

        if not make_directory(class_directory):
            return self.error('{0} Already Exists!'.format(self.scaffold_name))

        f = open(class_directory, 'w+')
        if view.exists(self.template):
            f.write(
                view.render(self.template, {
                            'class': class_name.split('/')[-1]}).rendered_template
            )
            self.info('{} Created Successfully!'.format(self.scaffold_name))
            return f.close()
    def handle(self):
        controller = self.argument('name')
        view = View(App())

        if not self.option('exact'):
            controller = controller + "Controller"

        if not make_directory('app/http/controllers/{0}.py'.format(controller)):
            return self.error('{0} Controller Exists!'.format(controller))

        with open('app/http/controllers/{0}.py'.format(controller), 'w+') as f:
            if view.exists('/masonite/snippets/scaffold/controller'):
                if self.option('resource'):
                    template = '/masonite/snippets/scaffold/controller_resource'
                else:
                    template = '/masonite/snippets/scaffold/controller'

                f.write(
                    view.render(
                        template, {'class': controller.split('/')[-1]}).rendered_template
                )

        self.info('Controller Created Successfully!')