Esempio n. 1
0
    def daemonContext(self):
        with db.DbManager(
                host=self._engineConfig.get('ENGINE_DB_HOST'),
                port=self._engineConfig.get('ENGINE_DB_PORT'),
                database=self._engineConfig.get('ENGINE_DB_DATABASE'),
                username=self._engineConfig.get('ENGINE_DB_USER'),
                password=self._engineConfig.get('ENGINE_DB_PASSWORD'),
                secured=self._engineConfig.getboolean('ENGINE_DB_SECURED'),
                secure_validation=self._engineConfig.getboolean(
                    'ENGINE_DB_SECURED_VALIDATION'),
        ) as db_manager:

            with listener.FenceKdumpListener(
                    bind=(self._config.get('LISTENER_ADDRESS'),
                          self._config.getinteger('LISTENER_PORT')),
                    db_manager=db_manager,
                    heartbeat_interval=(
                        self._config.getinteger('HEARTBEAT_INTERVAL')),
                    session_sync_interval=(
                        self._config.getinteger('SESSION_SYNC_INTERVAL')),
                    reopen_db_connection_interval=(self._config.getinteger(
                        'REOPEN_DB_CONNECTION_INTERVAL')),
                    session_expiration_time=(
                        self._config.getinteger('KDUMP_FINISHED_TIMEOUT')),
            ) as server:
                server.run()
Esempio n. 2
0
 def __init__(self):
     if config.extractor == 'vgg_face':
         self.__extractor = VggFeatureExtractor()
     else:
         self.__extractor = LightenedCnnFeatureExtractor()
     self.__db = db.DbManager()
     self.__align = AlignDlib(config.dlib_model_file)
Esempio n. 3
0
def first_run():
    path_config = get_conf_path()
    path_db = get_db_path()
    if not os.path.isdir(ad.user_data_dir):
        os.mkdir(ad.user_data_dir)
    if not os.path.isfile(path_config):
        logging.debug("Writing config at %s" % path_config)
        write_blank(path_config)
    if not os.path.isfile(path_db):
        logging.debug("Writing empty db at: %s" % path_db)
        db = db.DbManager(path_db)
        db.init()
Esempio n. 4
0
    def __init__(self):
        # configurations for detection.
        self.__gpu_memory_fraction = 0.25
        self.__minsize = 20
        self.__threshold = [0.6, 0.7, 0.7]
        self.__factor = 0.709
        self.__margin = 32
        self.__image_size = 160

        # configurations for extraction.
        self.__model_dir = config.model_dir
        self.__embedding_size = 128

        self.__db = db.DbManager()

        with tf.Graph().as_default():
            gpu_options = tf.GPUOptions(
                per_process_gpu_memory_fraction=self.__gpu_memory_fraction)
            self.__detect_sess = tf.Session(config=tf.ConfigProto(
                gpu_options=gpu_options, log_device_placement=False))
            with self.__detect_sess.as_default():
                self.__pnet, self.__rnet, self.__onet = align.detect_face.create_mtcnn(
                    self.__detect_sess, None)

            self.__extract_sess = tf.Session()
            with self.__extract_sess.as_default():
                meta_file, ckpt_file = facenet.get_model_filenames(
                    os.path.expanduser(self.__model_dir))
                facenet.load_model(self.__model_dir, meta_file, ckpt_file)
                self.__images_placeholder = tf.get_default_graph(
                ).get_tensor_by_name("input:0")
                self.__embeddings = tf.get_default_graph().get_tensor_by_name(
                    "embeddings:0")
                self.__phase_train_placeholder = tf.get_default_graph(
                ).get_tensor_by_name("phase_train:0")

                image_size = self.__images_placeholder.get_shape()[1]
                assert image_size == self.__image_size

                embedding_size = self.__embeddings.get_shape()[1]
                assert embedding_size == self.__embedding_size
Esempio n. 5
0
def main(argv=[]):
  args = parser.get_parser()

  verbose = 1
  if args.verbose:
    verbose = 2
  if args.debug:
    verbose = 3

  if verbose>2:
    log_level=logging.DEBUG
  elif verbose==2:
    log_level=logging.INFO
  elif verbose==1:
    log_level=logging.WARNING
  elif verbose<1:
    log_level=logging.ERROR

  logging.basicConfig(level=log_level, format="%(asctime)s %(levelname)s: %(message)s")

  if args.command == 'version':
    print cexbot.get_version()
    return True

  # make sure this is always above command parsing
  # print config
  config.first_run()

  if verbose == 3:
    print args

  if args.command == 'config':
    if args.list:
      return config.list()
    elif args.edit:
      return config.edit_config()
    elif args.testauth:
      return config.test_auth()
    elif args.name and args.value:
      v = config.set(args.name, args.value)
      return config.cprint(args.name)
    elif args.name:
      return config.cprint(args.name)
    logging.error('Invalid config option')
    return 1

  elif args.command == 'update':
    return updater.check_update()

  # not implemented
  elif args.command == 'cleardata':
    return config.clear_userdata()


  ac = cexapi.CexAPI(config.get('cex.username'), config.get('cex.apikey'), config.get('cex.secret'))
  dbi = db.DbManager()
  cx = CexMethods(ac, dbi)

  if args.command == 'balance':
    print "Balance: %s BTC" % ac.get_balance()
    return True

  elif args.command == 'initdb':
    return dbi.initdb()

  elif args.command == 'getmarket':
    return ac.get_market()

  elif args.command == 'getprice':
    return ac.get_market_quote()

  elif args.command == 'order':
    amount = args.amount
    price = args.price
    r = ac.place_order(amount, price)
    logging.info("Ordered: %s" % r)

  elif args.command == 'updatequotes':
    logging.info('Running updatequotes')
    ticker_timer = timer.ReqTimer(2, cx.update_ticker)
    ticker_timer.start()

  elif args.command == 'buybalance':
    logging.info('Running buybalance')
    balance_timer = timer.ReqTimer(5, ac.buy_balance)
    balance_timer.start()
Esempio n. 6
0
import json

import flask

sys.path.append('./lib')

import brew
import db
import periodic
import utils

app = flask.Flask('stackbrew')
config = None
with open('./config.json') as config_file:
    config = json.load(config_file)
data = db.DbManager(config['db_url'], debug=config['debug'])


@app.route('/')
def home():
    return utils.resp(app, 'stackbrew')


@app.route('/summary')
@app.route('/status')
def latest_summary():
    result = data.latest_status()
    return utils.resp(app, result)


@app.route('/summary/<int:id>')
Esempio n. 7
0
import sys

sys.path.append('./lib')

import db

data = db.DbManager(debug=True)
data.generate_tables()
Esempio n. 8
0
def main(argv=[]):
  args = parser.get_parser()

  verbose = 1
  if args.verbose:
    verbose = 2
  if args.debug:
    verbose = 3

  if verbose>2:
    log_level=logging.DEBUG
  elif verbose==2:
    log_level=logging.INFO
  elif verbose==1:
    log_level=logging.WARNING
  elif verbose<1:
    log_level=logging.ERROR

  logging.basicConfig(level=log_level, format="%(asctime)s %(levelname)s: %(message)s")

  proxy = args.proxy
  proxy_host = args.proxy_host
  proxy_port = args.proxy_port
  proxy_type = args.proxy_type

  config.first_run()

  if args.command == 'version':
    print torsurvey.get_version()
    return True

  elif args.command == 'update':
    return updater.check_update()

  ac = torapi.TorAPI(proxy_host=proxy_host, proxy_port=proxy_port, proxy_type=proxy_type, timeout=args.timeout)
  dbi = db.DbManager(args.dbpath)
  dbi.init()
  tc = controller.TorController(ac, dbi)
  # cx = CexMethods(ac, dbi)

  if args.command == 'checkip':
    print "Checking IP address"
    print ac.get_ip()
    return True

  elif args.command == 'flushdb':
    dbi.flush()
    print "Cleared db"

  elif args.command == 'fetch':
    if not args.url:
      logging.error("URL to fetch from required")
      return False
    print "Fetching from %s " % args.url
    f = tc.fetch_sitelist(args.url, args.cache, (not args.noinsert))
    return True

  elif args.command == 'read':
    if not args.filepath:
      logging.error("Need file to read onion addresses from")
    f = tc.read_sitelist(args.filepath, (not args.noinsert))

  elif args.command == 'survey':
    tc.survey(args.deadonly)

  elif args.command == 'list':
    dbi.list()