Browse Source

cli and testing fixes

master
phryk 9 months ago
parent
commit
8bdf79f6cb
4 changed files with 25 additions and 2 deletions
  1. 1
    1
      example.py
  2. 6
    0
      poobrains/__init__.py
  3. 8
    0
      poobrains/cli/__init__.py
  4. 10
    1
      poobrains/testing.py

+ 1
- 1
example.py View File

@@ -117,4 +117,4 @@ def list_nonexposed(listing):
117 117
 if __name__ == '__main__':
118 118
 
119 119
     #app.run()
120
-    poobrains.app.cli()
120
+    poobrains.app.main()

+ 6
- 0
poobrains/__init__.py View File

@@ -222,6 +222,7 @@ class Poobrain(flask.Flask):
222 222
         super(Poobrain, self).__init__(*args, **kwargs)
223 223
 
224 224
         self.cronjobs = []
225
+
225 226
         @click.group(cls=flask.cli.FlaskGroup, create_app=lambda x: self)
226 227
         @click.option('--database', default="sqlite:///%s.db" % project_name)
227 228
         def cli(database):
@@ -306,6 +307,11 @@ class Poobrain(flask.Flask):
306 307
         self.site = Pooprint('site', 'site')
307 308
         self.admin = Pooprint('admin', 'admin')
308 309
 
310
+    
311
+    def main(self):
312
+        #self.cli(obj={})
313
+        self.cli()
314
+
309 315
 
310 316
     def select_jinja_autoescape(self, filename):
311 317
         if filename is None:

+ 8
- 0
poobrains/cli/__init__.py View File

@@ -225,6 +225,14 @@ def install(**options):
225 225
                     os.mkdir(type_dir, mode=0o770)
226 226
 
227 227
 
228
+            if isinstance(poobrains.app.db, peewee.SqliteDatabase):
229
+                prefix = 'sqlite:///'
230
+            else:
231
+                prefix = 'postgres://'
232
+
233
+            options['database'] = '%s%s' % (prefix, poobrains.app.db.database)
234
+
235
+
228 236
             config = mkconfig('config', **options) 
229 237
             config_fd = open(os.path.join(app.root_path, 'config.py'), 'w')
230 238
             config_fd.write(config)

+ 10
- 1
poobrains/testing.py View File

@@ -7,6 +7,7 @@ import random
7 7
 import datetime
8 8
 
9 9
 import OpenSSL
10
+import peewee
10 11
 
11 12
 import poobrains
12 13
 from click.testing import CliRunner
@@ -516,7 +517,15 @@ def run_all():
516 517
         pass
517 518
 
518 519
     try:
519
-        os.unlink('%s.db' % poobrains.project_name)
520
+        if 'DATABASE' in poobrains.app.config and poobrains.app.config['DATABASE'].startswith('sqlite://'):
521
+            db_file = poobrains.app.config['DATABASE'].split('/')[-1]
522
+            os.unlink(db_name)
523
+    except:
524
+        pass
525
+
526
+    try:
527
+        if isinstance(poobrains.app.db, peewee.SqliteDatabase):
528
+            os.unlink(poobrains.app.db.database)
520 529
     except:
521 530
         pass
522 531
 

Loading…
Cancel
Save