Steve Nyemba 5 ヶ月 前
コミット
a111dbb6cc
4 ファイル変更33 行追加29 行削除
  1. 1 1
      smart/info.py
  2. 6 6
      setup.py
  3. 22 20
      smart/__init__.py
  4. 4 2
      smart/top/__init__.py

+ 1 - 1
smart/info.py

@@ -1,6 +1,6 @@
 import os
 __app_name__= "smart-logger"
-__version__ = "1.0-RC"
+__version__ = "1.1"
 __author__ = "Steve L. Nyemba, info@the-phi.com"
 __home__ = os.sep.join([os.environ['HOME'],'.smart-logger'])
 __database__='smart_logs'

+ 6 - 6
setup.py

@@ -3,15 +3,15 @@
 from setuptools import setup, find_packages
 import os
 import sys
-import info
+import meta
 # def read(fname):
 #     return open(os.path.join(os.path.dirname(__file__), fname)).read() 
 args    = {
-    "name":info.__app_name__,
-    "version":info.__version__,
-    "author":info.__author__,"author_email":"info@the-phi.com",
-    "license":info.__license__,
-    "packages":["smart","smart.top","smart.folder","smart.logger","smart.files"]
+    "name":meta.__app_name__,
+    "version":meta.__version__,
+    "author":meta.__author__,"author_email":"meta@the-phi.com",
+    "license":meta.__license__,
+    "packages":["meta","smart","smart.top","smart.folder","smart.logger","smart.files"]
     }
 args["keywords"]=['mongodb','couchdb','rabbitmq','file','read','write','s3','sqlite']
 args["install_requires"] = ['typer','pandas','numpy','data-transport@git+https://github.com/lnyemba/data-transport.git']

+ 22 - 20
smart/__init__.py

@@ -16,7 +16,7 @@ import smart.logger
 import smart.files
 import uuid
 import typer
-import smart.info
+import meta
 import json
 import os
 import transport
@@ -52,12 +52,12 @@ def apply_apps (app:str=None,user:str=None):
     This function looks at applications/commands running on the system
     """
     
-    _df = smart.top.read()
+    _df = smart.top.read(name=app)
     _id = 'apps' if not app else app
-    if app  :
-        _index = _df.name == app
-        if _index.sum() :
-            _df = _df[_index]
+    # if app  :
+    #     _index = _df.name == app
+    #     if _index.sum() :
+    #         _df = _df[_index]
     post(_df,_id)
     
 @_cli.command(name='archive')
@@ -68,7 +68,7 @@ def _archive():
     
     _suffix = datetime.now()
     _suffix = "-".join([str(_value) for _value in [_suffix.year,_suffix.month,_suffix.day,_suffix.hour,_suffix.minute]])
-    _path = os.sep.join([smart.info.__home__,smart.info.__database__]) 
+    _path = os.sep.join([meta.__home__,meta.__database__]) 
     _src = _path + '.db3'
     if os.path.exists(_src):
         _target = _path +'-archived-on-'+ _suffix+'.db3'
@@ -95,16 +95,16 @@ def apply_files(folder:str) :
     post(_df,'files')
 @_cli.command(name='register')
 def apply_signup (email:str,key:str=None,provider:str='sqlite') :
-    _config = {"system":{"email":email,"uid":str(uuid.uuid4()),"version":smart.info.__version__},"store":{"provider":provider,"context":"write"}}
-    _db = smart.info.__database__
+    _config = {"system":{"email":email,"uid":str(uuid.uuid4()),"version":meta.__version__},"store":{"provider":provider,"context":"write"}}
+    _db = meta.__database__
     if provider in ['sqlite','sqlite3'] :
-        _db = os.sep.join([smart.info.__home__,_db+'.db3'])
+        _db = os.sep.join([meta.__home__,_db+'.db3'])
         _config['store']['database'] = _db
     else:
         _config['store']['database'] = _db
     #
     # Let us store this in a folder
-    _PATH = smart.info.__home__
+    _PATH = meta.__home__
     _verb = "written"
     if not os.path.exists(_PATH) :
         os.mkdir(_PATH)
@@ -114,13 +114,13 @@ def apply_signup (email:str,key:str=None,provider:str='sqlite') :
     f.write(json.dumps(_config))
     f.close()
     _msg = f"""
-        The configuration file was {_verb} successfully at {smart.info.__home__}
+        The configuration file was {_verb} successfully at {meta.__home__}
         data store: 
             provider {provider}
             database {_db}
 
-        If your database has security enabled, consider updating "{smart.info.__home__}{os.sep}config.json" For appropriate security
-        Visit https://github.com/lnyemba/data-transport for more information
+        If your database has security enabled, consider updating "{meta.__home__}{os.sep}config.json" For appropriate security
+        Visit https://github.com/lnyemba/data-transport for more.metarmation
     """
     print ()
     print (_msg)
@@ -129,18 +129,20 @@ def post(_df,_table):
     """
     Store data in a given location 
     """
-    _path = os.sep.join([smart.info.__home__,'config.json'])
+    _path = os.sep.join([meta.__home__,'config.json'])
     f = open (_path)
     _config = json.loads(f.read())
     f.close()
     _store = _config['store']
-    if _store['provider'] in ['mongodb','mongo','couch','couchdb'] :
-        _store['collection'] = _table
-    else:
-        _store['table'] = _table
+    # if _store['provider'] in ['mongodb','mongo','couch','couchdb'] :
+    #     _store['collection'] = _table
+    # else:
+    #     _store['table'] = _table
    
+    _store['table'] = _table
         
-    writer = transport.factory.instance(**_store)
+    # writer = transport.factory.instance(**_store)
+    writer = transport.get.writer(**_store)
     writer.write(_df)
     if hasattr(writer,'close') :
         writer.close()

+ 4 - 2
smart/top/__init__.py

@@ -88,6 +88,7 @@ def read(**args) :
         # We should filter the name of the apps we are interested in here (returning the full logs )
         # @TODO: Add filter here to handle filter on different columns
         #
+        
 
         if 'name' in args and args['name']:
             names = args['name'].split(',')
@@ -95,14 +96,15 @@ def read(**args) :
             for name in names :
                 # tmp = df[df.name == name.strip() ]
                 # ii = df.apply(lambda row: row['name'] == name.strip() or (name.strip() in str(row['name'])),axis=1).tolist()
-                ii = df.apply(lambda row: type(row['cmd']) ==str and name.strip() in row['cmd'],axis=1).tolist()
+                ii = df.apply(lambda row: type(row['cmd']) ==str and name.strip() == row['name'] in row['cmd'],axis=1).tolist()
                 tmp= df[ii]
                 # tmp.index = np.arange(tmp.shape[0])
                 if tmp.empty:
                     tmp = {"pid":None,"user":None,"mem":0,"cpu":0,"status":"-100","started":None,"name":name,"cmd":None,"args":None,"date":d,"time":t,"node":n}
                     
                 else:
-                    r = r.append(tmp,ignore_index=False)
+                    #r = r.append(tmp,ignore_index=False)
+                    r = pd.concat([r, tmp]) #r.append(tmp,ignore_index=False)
             if not r.empty :
                 # r.index = np.arange(r.shape[0])
                 df = r.copy()