ソースを参照

tools for database

Gamaliel Espinoza 8 年 前
コミット
03101c4f50
3 ファイル変更53 行追加0 行削除
  1. 1 0
      tools/fourier/__init__.py
  2. 30 0
      tools/fourier/cli.py
  3. 22 0
      tools/setup.py

+ 1 - 0
tools/fourier/__init__.py

@@ -0,0 +1 @@
+__version__ = '1.0.0b1'

+ 30 - 0
tools/fourier/cli.py

@@ -0,0 +1,30 @@
+from argparse import ArgumentParser
+import sqlite3
+import json
+import os
+
+
+if __name__ == '__main__':
+    parser = ArgumentParser()
+    subparsers = parser.add_subparsers(dest='entity')
+    
+    dbparser = subparsers.add_parser('db')
+    dbparser.add_argument('action')
+
+    args = parser.parse_args()
+    action = args.action
+
+    with open('/etc/fourier-config.json', 'r') as fp:
+        config = json.loads(fp.read())
+
+    device_id = config['device_id']
+
+    if action == 'stats':
+        dbpath = '/var/fourier/{}/files.db'.format(device_id)
+        conn = sqlite3.connect(dbpath)
+        cursor = conn.cursor()
+        cursor.execute("select count(*), count(uploaded) from file")
+        total, uploaded, = cursor.fetchone()
+        print("total: {}".format(total))
+        print("uploaded: {}".format(uploaded))
+        print("pending: {}".format(total - uploaded))

+ 22 - 0
tools/setup.py

@@ -0,0 +1,22 @@
+from __future__ import absolute_import
+from os.path import join, dirname
+from setuptools import setup
+import fourier
+
+basepath = dirname(__file__)
+binpath = join(basepath, 'bin')
+
+setup(
+  name = 'fourier',
+  packages = ['fourier'],
+  version = fourier.__version__,
+  description = 'Fourier command line tools',
+  long_description = 'You can use it for do maintenance stuff',
+  scripts = [join(binpath, 'fourier')],
+  install_requires=[],
+  author = 'Gamaliel Espinoza M.',
+  author_email = 'gamaliel.espinoza@gmail.com',
+  url = 'https://git.miralo.xyz/AudioValid/fourier-install',
+  keywords = ['image', 'icons', ''],
+  classifiers = [],
+)