HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //usr/lib/python2.7/site-packages/centos_package_cron/db_session_fetcher.py
import sqlalchemy
from sqlite3 import dbapi2 as sqlite
from sqlalchemy.orm import sessionmaker
from db_base import Base
import os

class db_session_fetcher:
    DEFAULT_DB_PATH = '/var/lib/centos-package-cron/already_annoyed.sqlite'
    
    def __init__(self, db_path=DEFAULT_DB_PATH):
        self.db_path = db_path
        self.session = None
        self.engine = None
        
    def __enter__(self):
        if self.engine == None:
            absolute_path = os.path.abspath(self.db_path)
            parent_dir = os.path.dirname(absolute_path)
            if not os.path.exists(parent_dir):
                raise Exception("Unable to find a parent directory for DB %s, did you install properly?" % (absolute_path))
                
            if not os.access(parent_dir, os.W_OK):
                raise Exception("Unable to write to directory for DB file %s, do you need to run as root?" % (absolute_path))
                
            if os.path.exists(absolute_path) and not os.access(absolute_path, os.W_OK):
                raise Exception("Unable to write to DB file %s, do you need to run as root?" % (absolute_path))
                
            self.engine = sqlalchemy.create_engine('sqlite:///%s' % (self.db_path),module=sqlite)
            
        Base.metadata.create_all(self.engine)
        Session = sessionmaker(bind=self.engine)
        self.session = Session()        
        return self.session
        
    def __exit__(self, type, value, traceback):
        self.session.close()