Tuesday, 28 January 2020

Python module management - View and Copy Configuration.

help('modules')

Its a python command and provide an entire list of the python modules, which are installed in the system.

>>>python
>>>help('modules')

Result::: Please wait a moment while I gather a list of all available modules
abc                 fractions           pyexpat             webencodings
aifc                ftplib              pygments            werkzeug
alembic             functools           pygtkcompat         wheel
aniso8601           future_builtins     pymysql             whichdb
antigravity         gc                  pyparsing           wsgiref
...
...


pip list 

This command will provide the list of all the python module installed in the system, with the versions.



Result::: 
SQLAlchemy (1.3.13)
typing (3.7.4.1)
urllib3 (1.25.8)
visitor (0.1.3)
...


> pip freeze

 This command also provide you same list in different format.
Result::: 
visitor==0.1.3
webencodings==0.5.1
Werkzeug==0.16.1
wtf==0.1
WTForm==1.0
...

Install all module to a different machine


Now if you want to install all these modules to some other system, then you can use some python commands, if you are not using any configuration management tools like chef.

Then by using any of the command get the list, add then to a file and add pip install to each line and create a complete shell file like this.

pip install     visitor                 ;
pip install     webencodings            ;
pip install     Werkzeug                ;
pip install     wtf                     ;
pip install     WTForm                  ;
pip install     WTForms                 ;

Now just login to machine and run this file.

>> installtion.sh

All your module will be installed now to this machine.








Sunday, 19 January 2020

ADF Security - How to get logged in user name and roles information

In ADF Security object and role information can be found out using the below code anytime using the java code 

User Name Information

     ADFContext adfCtx = ADFContext.getCurrent();  
     SecurityContext secCntx = adfCtx.getSecurityContext();  
     String user = secCntx.getUserPrincipal().getName();  
     String loggedInUserName = secCntx.getUserName();  


Role Information 
With the same set of logic you can find the role information.

  ADFContext adfCtx = ADFContext.getCurrent();  
  SecurityContext secCntx = adfCtx.getSecurityContext();   
    String[] Roles = secCntx.getUserRoles()


Role Information check
You can use below logic to check if user have a role which you want to check, like if you want to enable a button if user have have manager Role.


public boolean checkIsUserInRole(String roleName){
        return 
(FacesContext.getCurrentInstance().getExternalContext().isUserInRole(roleName));
}

Sunday, 5 January 2020

ERROR [root] Error: Target database is not up to date. - Python Flask


 While working on the python flask I got the below error and when I tried to debug more then I reliaze that this is not the culprit.



  1.     self.dialect.do_execute(
  2.   File "C:\Program Files\Python38\lib\site-packages\sqlalchemy\engine\default.py", line 552, in do_execute
  3.     cursor.execute(statement, parameters)
  4. sqlalchemy.exc.OperationalError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely)
  5. (sqlite3.OperationalError) no such table: user
  6. [SQL: INSERT INTO user (username, email, password_hash) VALUES (?, ?, ?)]
  7. [parameters: ('Vipin', 'XX.i.kumar@gmail.com', None)]
  8. (Background on this error at: http://sqlalche.me/e/e3q8)



Now When the ouput of the command falsk db migrate been checked, then got the root issue, problem was 

  warnings.warn(
c:\program files\python38\lib\site-packages\flask_sqlalchemy\__init__.py:834: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True or False to suppress this warning.
  warnings.warn(FSADeprecationWarning(
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
ERROR [root] Error: Target database is not up to date.

After reading a number of post concluded issue the the new migration folder which get created when we run the follwoing command.

flask db migrate


Now I rename the migration folder to xmigration. then re-run the script from

flask db init
flask db migrate -m 'user table'

Now it created the migration folder again and then next command also a success.

I am still not able to reach to root of the issue, will see it in some time, but till then happy solutioning.



Feature Selection in AI

In artifical intelegance/machine learning, everything start and end with data and in current world everyday by using facebook, insta we all ...