Skip to content

Commit

Permalink
Merge pull request #63 from santosfamilyfoundation/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dcelik authored Feb 19, 2017
2 parents f7f16d0 + 83278e9 commit e1dcbb4
Show file tree
Hide file tree
Showing 29 changed files with 1,897 additions and 1,071 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,10 @@ target/

# Project directory
project_dir/*
*.IDdict
*.IDdict
application/test_app.py
application/test_cloud.py

*.dmg

*.zip
5 changes: 0 additions & 5 deletions application/.application

This file was deleted.

13 changes: 13 additions & 0 deletions application/SantosBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

echo $DIR

cd $DIR
pyinstaller $DIR/app.spec
chmod 777 $DIR/dist/app

echo “[Press any button to exit]”
read -rsn1
exit
13 changes: 13 additions & 0 deletions application/SantosBuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

echo $DIR

cd $DIR
pyinstaller $DIR/app.spec
chmod 777 $DIR/dist/app

echo “[Press any button to exit]”
read -rsn1
exit
761 changes: 287 additions & 474 deletions application/app.py

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions application/app.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- mode: python -*-

block_cipher = None


a = Analysis(['app.py'],
pathex=['/Users/user/Documents/SantosGUI/application'],
binaries=[],
datas=[],
hiddenimports=['sklearn','sklearn.neighbors.typedefs'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='app',
debug=False,
strip=False,
upx=True,
console=True )
149 changes: 120 additions & 29 deletions application/app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,171 @@


class AppConfig(object):
PROJECT_DIR = None
CURRENT_PROJECT_PATH = None # Path to base of currently open project's folder
PROJECT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "project_dir"))
CURRENT_PROJECT_NAME = None
CURRENT_PROJECT_CONFIG = None # Path
CURRENT_PROJECT_VIDEO_PATH = None

def __init__(self):
super(AppConfig, self).__init__()
def get_base_project_dir():
return AppConfig.PROJECT_DIR

@classmethod
def load_application_config(cls):
config_parser = SafeConfigParser()
config_parser.read(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".application"))
cls.PROJECT_DIR = config_parser.get("info", "default_project_dir")
def get_project_path():
if AppConfig.CURRENT_PROJECT_NAME:
return os.path.join(AppConfig.PROJECT_DIR, AppConfig.CURRENT_PROJECT_NAME)
return None

# TODO: class method for writing to application config file
def get_config_path():
if AppConfig.CURRENT_PROJECT_NAME:
return os.path.join(AppConfig.PROJECT_DIR, AppConfig.CURRENT_PROJECT_NAME, "config.cfg")
return None

def update_project_cfg(section, option, value):
def get_identifier():
config_path = get_config_path()
if config_path:
return get_config_with_sections(config_path, "info", "identifier")
return None

def get_project_video_path():
config_path = get_config_path()
if config_path:
video = get_config_with_sections(config_path, "video", "name")
if video:
return os.path.join(get_project_path(), video)
else:
print("ERR: project_video(): Couldn't get video")
return None

def projects_exist():
if not os.path.exists(get_base_project_dir()):
return False
return (len(os.listdir(get_base_project_dir())) > 0)

def update_config_with_sections(config_path, section, option, value):
"""
Updates a single value in the current open project's configuration file.
Writes nothing and returns -1 if no project currently open. Creates sections
in the config file if they do not already exist.
Args:
config_path (str): Path to the config file
section (str): Name of the section to write new option-value pair to write.
option (str): Name of the option to write/update.
value (str): Value to write/update assocaited with the specified option.
"""
if not AppConfig.CURRENT_PROJECT_CONFIG:
if not os.path.exists(config_path):
print("ERR [update_config_with_sections()]: File {} does not exist.".format(config_path))
return -1
cfp = SafeConfigParser()
cfp.read(AppConfig.CURRENT_PROJECT_CONFIG)
cfp.read(config_path)
if section not in cfp.sections(): # If the given section does not exist,
cfp.add_section(section) # then create it.
cfp.set(section, option, value) # Set the option-value pair
with open(AppConfig.CURRENT_PROJECT_CONFIG, "wb") as cfg_file:
with open(config_path, "wb") as cfg_file:
cfp.write(cfg_file) # Write changes


def check_project_cfg_option(section, option):
def get_config_with_sections(config_path, section, option):
"""
Checks the currently open project's configuration file for the specified option
in the specified section. If it exists, this returns (True, <value>). If it does not
exist, this returns (False, None).
Checks the configuration file for the specified option
in the specified section. If it exists, this returns <value>. If it does not
exist, this returns None.
Args:
config_path (str): Path to the config file to check
section (str): Name of the section to check for option.
option (str): Name of the option check/return.
"""
if config_path == None:
print("ERR [get_config_with_sections()]: config_path was None.")
return None
if not os.path.exists(config_path):
print("ERR [get_config_with_sections()]: File {} does not exist.".format(config_path))
return None
cfp = SafeConfigParser()
cfp.read(AppConfig.CURRENT_PROJECT_CONFIG)
cfp.read(config_path)
try:
value = cfp.get(section, option)
except NoSectionError:
print("ERR [check_project_cfg_option()]: Section {} is not available in {}.".format(section, AppConfig.CURRENT_PROJECT_CONFIG))
return (False, None)
return None
except NoOptionError:
print("Option {} is not available in {}.".format(option, AppConfig.CURRENT_PROJECT_CONFIG))
return (False, None)
return None
else:
return value

def get_config_section(config_path, section):
"""
Checks the configuration file for the specified option
in the specified section. If it exists, this returns dict_of_data. If it does not
exist, this returns None.
Args:
config_path (str): Path to the config file to check
section (str): Name of the section whose data should be returned.
"""
if not os.path.exists(config_path):
print("ERR [get_config_section()]: File {} does not exist.".format(config_path))
return None
cfp = SafeConfigParser()
cfp.read(config_path)
try:
tuples = cfp.items(section)
except NoSectionError:
print("ERR [get_config_section()]: Section {} is not available in {}.".format(section, config_path))
return None
else:
return (True, value)
d = {}
for (key, value) in tuples:
d[key] = value
return d


def check_project_cfg_section(section):
def config_section_exists(config_path, section):
"""
Checks the currently open project's configuration file for the section. If it exists,
this returns True. If it does not exist, this returns False.
Args:
config_path (str): Path to the config file.
section (str): Name of the section to check existance of.
"""
cfp = SafeConfigParser()
cfp.read(AppConfig.CURRENT_PROJECT_CONFIG)
cfp.read(config_path)
if section in cfp.sections(): # If the given section exists,
return True # then return True.
else: # Otherwise,
return False # then return False
return False # then return False

def update_config_without_sections(config_path, update_dict):
"""helper function to edit cfg files that look like tracking.cfg
update_dict: i.e. {'nframes': 10, 'video-filename': 'video.avi'}
"""
unused_keys = update_dict.keys()
with open(config_path, 'r') as rf:
lines = rf.readlines()
with open(config_path, 'w') as wf:
for line in lines:
line_param = line.split('=')[0].strip()
if line_param in update_dict.keys():
wf.write("{} = {}\n".format(line_param, update_dict[line_param]))
unused_keys.remove(line_param)
else:
wf.write(line)
for unused_key in unused_keys:
wf.write("{} = {}\n".format(unused_key, update_dict[unused_key]))


def get_config_without_sections(config_path):
"""helper function to get params and their values of cfg files that look like tracking.cfg
get_dict: params to their values, as a dictionary
"""
get_dict = {}
with open(config_path, 'r') as rf:
lines = rf.readlines()
for line in lines:
# if not a comment line
if line[0] != "#":
line_param = line.split('=')[0].strip()
line_value = line.split('=')[1].strip()
get_dict[line_param] = line_value
return get_dict

Loading

0 comments on commit e1dcbb4

Please sign in to comment.