<commit_before>#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 24 15:11:09 2015

@author: Randy

This is the main module of the OTOne Python backend code. When started, it creates
a publisher (:class:`publisher.Publisher`) and a subscriber (:class:`subscriber.Subscriber`)
for handling all communication with a WAMP router and then tries to make a connection
(:meth:`otone_client.make_a_connection`) with the Crossbar.io WAMP router. Once that
connection is established, it instantiates and configures various objects with
:meth:`otone_client.instantiate_objects`:

 head: :class:`head.Head` - Represents the robot head and creates a connection with Smoothieboard

 deck: :class:`deck.Deck` - Represents the robot deck

 runner: :class:`protocol_runner.ProtocolRunner` - Runs protocol jobs
"""

import asyncio
import logging
import logging.handlers
import os
import shutil
import sys
import time

from autobahn.wamp.serializer import JsonSerializer, MsgPackSerializer

# If code is frozen (i.e. pyinstaller executable) then
# file path is the sys._MEIPASS attribute
if getattr(sys, 'frozen', None):
    print('using frozen path...')
    path = dir_path = sys._MEIPASS
    perm_dir_path = dir_path
else:
    print('using non frozen path...')
    path = os.path.abspath(__file__)
    dir_path = os.path.dirname(path)
    perm_dir_path = dir_path


if len(sys.argv) > 1:
    perm_dir_path = sys.argv[1]

disconnect_counter = 0
disconnect_seconds_timeout = 30
keep_backend_running = False

if len(sys.argv) > 2:
    keep_backend_running = True

print('resource path is', path)
print('dir path is', dir_path)
print('perm path is', perm_dir_path)

if not os.path.exists(perm_dir_path):
    os.makedirs(perm_dir_path)


fname_default_protocol = os.path.join(dir_path,'data/sample_user_protocol.json')
fname_default_containers = os.path.join(dir_path, 'data/containers.json')
fname_default_calibrations = os.path.join(dir_path, 'data/pipette_calibrations.json')

fname_data = os.path.join(perm_dir_path,'otone_data')

fname_data_logfile = os.path.join(perm_dir_path,'otone_data/logfile.txt')
fname_data_containers = os.path.join(perm_dir_path,'otone_data/containers.json')
fname_data_calibrations = os.path.join(perm_dir_path, 'otone_data/pipette_calibrations.json')


if not os.path.isdir(fname_data):
    os.makedirs(fname_data)

open(fname_data_containers, "w+")
shutil.copy(fname_default_containers, fname_data_containers)

if not os.path.exists(fname_data_calibrations):
    open(fname_data_calibrations, "w+")
    shutil.copy(fname_default_calibrations, fname_data_calibrations)

print('logging to {}'.format(fname_data_logfile))

logger = logging.getLogger('app')

LOG_FORMAT ="%(asctime)s - %(name)s - %(levelname)s - %(message)s"

file_handler = logging.handlers.RotatingFileHandler(
    fname_data_logfile, maxBytes=20000, backupCount=2
)

# Set up file logging
file_handler.setFormatter(logging.Formatter(LOG_FORMAT))
logger.setLevel(logging.DEBUG)
logger.addHandler(file_handler)


# Set up console logging
console_handler = logging.StreamHandler()<commit_msg>making logfile larger<commit_after>#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 24 15:11:09 2015

@author: Randy

This is the main module of the OTOne Python backend code. When started, it creates
a publisher (:class:`publisher.Publisher`) and a subscriber (:class:`subscriber.Subscriber`)
for handling all communication with a WAMP router and then tries to make a connection
(:meth:`otone_client.make_a_connection`) with the Crossbar.io WAMP router. Once that
connection is established, it instantiates and configures various objects with
:meth:`otone_client.instantiate_objects`:

 head: :class:`head.Head` - Represents the robot head and creates a connection with Smoothieboard

 deck: :class:`deck.Deck` - Represents the robot deck

 runner: :class:`protocol_runner.ProtocolRunner` - Runs protocol jobs
"""

import asyncio
import logging
import logging.handlers
import os
import shutil
import sys
import time

from autobahn.wamp.serializer import JsonSerializer, MsgPackSerializer

# If code is frozen (i.e. pyinstaller executable) then
# file path is the sys._MEIPASS attribute
if getattr(sys, 'frozen', None):
    print('using frozen path...')
    path = dir_path = sys._MEIPASS
    perm_dir_path = dir_path
else:
    print('using non frozen path...')
    path = os.path.abspath(__file__)
    dir_path = os.path.dirname(path)
    perm_dir_path = dir_path


if len(sys.argv) > 1:
    perm_dir_path = sys.argv[1]

disconnect_counter = 0
disconnect_seconds_timeout = 30
keep_backend_running = False

if len(sys.argv) > 2:
    keep_backend_running = True

print('resource path is', path)
print('dir path is', dir_path)
print('perm path is', perm_dir_path)

if not os.path.exists(perm_dir_path):
    os.makedirs(perm_dir_path)


fname_default_protocol = os.path.join(dir_path,'data/sample_user_protocol.json')
fname_default_containers = os.path.join(dir_path, 'data/containers.json')
fname_default_calibrations = os.path.join(dir_path, 'data/pipette_calibrations.json')

fname_data = os.path.join(perm_dir_path,'otone_data')

fname_data_logfile = os.path.join(perm_dir_path,'otone_data/logfile.txt')
fname_data_containers = os.path.join(perm_dir_path,'otone_data/containers.json')
fname_data_calibrations = os.path.join(perm_dir_path, 'otone_data/pipette_calibrations.json')


if not os.path.isdir(fname_data):
    os.makedirs(fname_data)

open(fname_data_containers, "w+")
shutil.copy(fname_default_containers, fname_data_containers)

if not os.path.exists(fname_data_calibrations):
    open(fname_data_calibrations, "w+")
    shutil.copy(fname_default_calibrations, fname_data_calibrations)

print('logging to {}'.format(fname_data_logfile))

logger = logging.getLogger('app')

LOG_FORMAT ="%(asctime)s - %(name)s - %(levelname)s - %(message)s"

file_handler = logging.handlers.RotatingFileHandler(
    fname_data_logfile, maxBytes=200000, backupCount=2
)

# Set up file logging
file_handler.setFormatter(logging.Formatter(LOG_FORMAT))
logger.setLevel(logging.DEBUG)
logger.addHandler(file_handler)


# Set up console logging
console_handler = logging.StreamHandler()
{'fraction_non_alphanumeric': 0.10724121172849506, 'fraction_numerical': 0.008585776769803984, 'mean_word_length': 5.762322015334064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1983518', 'n_tokens_mistral': 2157, 'n_tokens_neox': 2069, 'n_words': 479}