Przeglądaj źródła

New version with migrations

Gamaliel Espinoza 8 lat temu
rodzic
commit
e4c7b67874
3 zmienionych plików z 51 dodań i 3 usunięć
  1. 1 1
      tools/fourier/__init__.py
  2. 40 2
      tools/fourier/cli.py
  3. 10 0
      tools/fourier/migrations.py

+ 1 - 1
tools/fourier/__init__.py

@@ -1 +1 @@
-__version__ = '1.0.3'
+__version__ = '1.0.4'

+ 40 - 2
tools/fourier/cli.py

@@ -165,6 +165,40 @@ def main():
                 print('database already installed')
                 sys.exit(1)
 
+        elif action == 'migrate':
+            conn = sqlite3.connect(dbpath)
+            cursor = conn.cursor()
+            try:
+                cursor.execute(("select value "
+                                "from config "
+                                "where name = 'version'"))
+                row = cursor.fetchone()
+                min_version = row[0] if row else ''
+
+            except sqlite3.OperationalError as err:
+                strerr = str(err)
+                if "table" in strerr and "config" in strerr:
+                    min_version = ''
+                else:
+                    print(err)
+
+            from fourier.migrations import versions
+
+            cursor = conn.cursor()
+            for v, qrs in versions:
+                if v > min_version:
+                    try:
+                        for q in qrs:
+                            cursor.execute(q)
+                        cursor.execute()
+                    except Exception as ex:
+                        print('failed: {}'.format(ex))
+                        conn.rollback()
+
+        elif action == 'connect':
+            subprocess.call(['sqlite3', dbpath])
+
+
     elif args.entity == 'station':
         if action == 'list':
             stations_path = os.path.join('/var/fourier', device_id)
@@ -210,7 +244,6 @@ def main():
                     ffmpeg = subprocess.Popen([
                         'ffmpeg', '-f', 's16le', '-i', 'pipe:0',
                                   '-ac', '1', '-ar', '24000',
-                                  '-ab', '64k',
                                   '-nostdin',
                                   '-f', 'mp3', 
                                   filename,
@@ -286,12 +319,17 @@ def main():
 
                             totals[index] += len(data)
 
-                            if totals[index] % 10 == 0:
+                            if totals[index] % 100 == 0:
                                 scr.addstr(index + 1, 5, '{:01x} {:>4} {}\n\n'\
                                     .format(index, stations[index], totals[index])
                                 )
                                 refresh = True
 
+                        else:
+                            errout = processes[index].stderr.read(4096)
+                            scr.addstr(0, 0, 'ALL FUCKED')
+                            refresh = True
+
                     k = scr.getch()
                     if k > -1:
                         key = int(chr(k), 16) if k > 0 else 0

+ 10 - 0
tools/fourier/migrations.py

@@ -0,0 +1,10 @@
+versions = [
+    (
+        '1',
+        [
+            "create table config(name text primary key, value text)",
+            "insert into config (name, value) values ('version', '1')",
+            'create table "station"(remote_id text, indice int, status int)'
+        ],
+    ),
+]