Exemplo n.º 1
0
def set_windows_env_variables(config):
    import winpaths
    config.set('DEFAULT', 'common_app_data_folder',
               winpaths.get_common_appdata())
    config.set('DEFAULT', 'win_local_appdata', winpaths.get_local_appdata())
    config.set('DEFAULT', 'win_appdata', winpaths.get_appdata())
    config.set('DEFAULT', 'win_desktop', winpaths.get_desktop())
    config.set('DEFAULT', 'win_programs', winpaths.get_programs())
    config.set('DEFAULT', 'win_common_admin_tools',
               winpaths.get_common_admin_tools())
    config.set('DEFAULT', 'win_common_documents',
               winpaths.get_common_documents())
    config.set('DEFAULT', 'win_cookies', winpaths.get_cookies())
    config.set('DEFAULT', 'win_history', winpaths.get_history())
    config.set('DEFAULT', 'win_internet_cache', winpaths.get_internet_cache())
    config.set('DEFAULT', 'win_my_pictures', winpaths.get_my_pictures())
    config.set('DEFAULT', 'win_personal', winpaths.get_personal())
    config.set('DEFAULT', 'win_my_documents', winpaths.get_my_documents())
    config.set('DEFAULT', 'win_program_files', winpaths.get_program_files())
    config.set('DEFAULT', 'win_program_files_common',
               winpaths.get_program_files_common())
    config.set('DEFAULT', 'win_system', winpaths.get_system())
    config.set('DEFAULT', 'win_windows', winpaths.get_windows())
    config.set('DEFAULT', 'win_startup', winpaths.get_startup())
    config.set('DEFAULT', 'win_recent', winpaths.get_recent())
Exemplo n.º 2
0
 def get_cache_dir(cls):
     """Retrieve a cache directory appropriate for the current platform."""
     # Portable cache directory placement
     if os.name == 'nt':
         from winpaths import get_local_appdata
         croot = get_local_appdata()
     else:
         croot = os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
     return os.path.join(croot, cls.shortname, 'http_cache')
Exemplo n.º 3
0
def localFolder():
    if ('win' in sys.platform) and ('darwin' not in sys.platform):
        import winpaths
        lf = os.path.join(winpaths.get_local_appdata(), name)
    else:
        lf = os.path.join(os.path.expanduser('~'), u'.%s'%name.lower())
    if not os.path.exists(lf):
        os.makedirs(lf)
        logger.info("Configuration directory created under: %s"%lf)
    return lf
Exemplo n.º 4
0
    def get_current_log():
        """
        Returns the current log since the start of the NanoWrite program.

        @note:
            This script assumes that the latest log file in %localappdata%\Nanoscribe\Messages
            contains all the recent logs since the program started.


        @return: List of two elements lists, containing a datetime object and the log message.
            The latest log message is the last element of the list.
        @rtype: list
        """
        msgs_dir_path = os.path.join(winpaths.get_local_appdata(),
                                     'Nanoscribe\Messages')
        assert os.path.exists(
            msgs_dir_path), 'NanoWrite messages log path does not exist'

        # Get the most recent log file name
        # FIXME: This fails if there are other file names than '2013-07-08_16-17-00_Messages.log'
        log_file_name = os.listdir(msgs_dir_path)[-1]

        f = open(os.path.join(msgs_dir_path, log_file_name), 'r')

        results = list()
        for line in f.readlines():
            if len(line) <= 30:
                continue
            line = line.decode('latin-1')
            timestamp_txt = line[:28]
            msg_txt = line[29:]

            if len(timestamp_txt.strip()) == 0:
                assert len(
                    results) > 0, 'No previous timestamp available in log file'
                results[-1][1] += msg_txt
            else:
                # FIXME: Don't ignore time zone offset here
                timestamp_struct = time.strptime(timestamp_txt[:19],
                                                 '%Y-%m-%dT%H:%M:%S')
                timestamp = datetime.datetime.fromtimestamp(
                    time.mktime(timestamp_struct))
                results.append([timestamp, msg_txt])
        return results
Exemplo n.º 5
0
def set_windows_env_variables(config):
    import winpaths
    config.set('DEFAULT', 'common_app_data_folder', winpaths.get_common_appdata())
    config.set('DEFAULT', 'win_local_appdata', winpaths.get_local_appdata())
    config.set('DEFAULT', 'win_appdata', winpaths.get_appdata())
    config.set('DEFAULT', 'win_desktop', winpaths.get_desktop())
    config.set('DEFAULT', 'win_programs', winpaths.get_programs())
    config.set('DEFAULT', 'win_common_admin_tools', winpaths.get_common_admin_tools())
    config.set('DEFAULT', 'win_common_documents', winpaths.get_common_documents())
    config.set('DEFAULT', 'win_cookies', winpaths.get_cookies())
    config.set('DEFAULT', 'win_history', winpaths.get_history())
    config.set('DEFAULT', 'win_internet_cache', winpaths.get_internet_cache())
    config.set('DEFAULT', 'win_my_pictures', winpaths.get_my_pictures())
    config.set('DEFAULT', 'win_personal', winpaths.get_personal())
    config.set('DEFAULT', 'win_my_documents', winpaths.get_my_documents())
    config.set('DEFAULT', 'win_program_files', winpaths.get_program_files())
    config.set('DEFAULT', 'win_program_files_common', winpaths.get_program_files_common())
    config.set('DEFAULT', 'win_system', winpaths.get_system())
    config.set('DEFAULT', 'win_windows', winpaths.get_windows())
    config.set('DEFAULT', 'win_startup', winpaths.get_startup())
    config.set('DEFAULT', 'win_recent', winpaths.get_recent())
Exemplo n.º 6
0
    def get_current_log():
        """
        Returns the current log since the start of the NanoWrite program.

        @note:
            This script assumes that the latest log file in %localappdata%\Nanoscribe\Messages
            contains all the recent logs since the program started.


        @return: List of two elements lists, containing a datetime object and the log message.
            The latest log message is the last element of the list.
        @rtype: list
        """
        msgs_dir_path = os.path.join(winpaths.get_local_appdata(), 'Nanoscribe\Messages')
        assert os.path.exists(msgs_dir_path), 'NanoWrite messages log path does not exist'

        # Get the most recent log file name
        # FIXME: This fails if there are other file names than '2013-07-08_16-17-00_Messages.log'
        log_file_name = os.listdir(msgs_dir_path)[-1]

        f = open(os.path.join(msgs_dir_path, log_file_name), 'r')

        results = list()
        for line in f.readlines():
            if len(line) <= 30:
                continue
            line = line.decode('latin-1')
            timestamp_txt = line[:28]
            msg_txt = line[29:]

            if len(timestamp_txt.strip()) == 0:
                assert len(results) > 0, 'No previous timestamp available in log file'
                results[-1][1] += msg_txt
            else:
                # FIXME: Don't ignore time zone offset here
                timestamp_struct = time.strptime(timestamp_txt[:19], '%Y-%m-%dT%H:%M:%S')
                timestamp = datetime.datetime.fromtimestamp(time.mktime(timestamp_struct))
                results.append([timestamp, msg_txt])
        return results
Exemplo n.º 7
0
    def __init__(self, author, name, data='data.sqlite'):
        """
        :param author: the name of the writer of the application
        :param name: the name of the application
        :param data: the name of the sqlite database file
        
        These names will be used to create a folder where the local data will 
        be stored.  On Windows this will be in the AppData folder of the user,
        otherwise it will be in a `.author` folder in the home directory of the
        user.
        """
        self.data = data
        if ('win' in sys.platform) and ('darwin' not in sys.platform):
            import winpaths
            self._local_folder = os.path.join(winpaths.get_local_appdata(),
                                              author, name)
        else:
            self._local_folder = os.path.join(os.path.expanduser('~'),
                                              u'.%s' % author, name)
        if not os.path.exists(self._local_folder):
            os.makedirs(self._local_folder)

        LOGGER.info(u'store database and media in %s' % self._local_folder)
Exemplo n.º 8
0
 def __init__( self, author, name, data = 'data.sqlite' ):
     """
     :param author: the name of the writer of the application
     :param name: the name of the application
     :param data: the name of the sqlite database file
     
     These names will be used to create a folder where the local data will 
     be stored.  On Windows this will be in the AppData folder of the user,
     otherwise it will be in a `.author` folder in the home directory of the
     user.
     """        
     self.data = data
     if ('win' in sys.platform) and ('darwin' not in sys.platform):
         import winpaths
         self._local_folder = os.path.join( winpaths.get_local_appdata(), 
                                            author, 
                                            name )
     else:
         self._local_folder = os.path.join( os.path.expanduser('~'), 
                                            u'.%s'%author, name )
     if not os.path.exists( self._local_folder ):
         os.makedirs( self._local_folder )
         
     LOGGER.info( u'store database and media in %s'%self._local_folder )
Exemplo n.º 9
0
Typical Usage:
    See TestDetectInstalledSites.py

Todo:
    replace hardcoded site list with something more subtle

"""
import platform
import os

import Configuration

if platform.system() == 'Windows':
    import winpaths
    PROGRAM_FILES = winpaths.get_program_files()
    LOCAL_APPDATA = winpaths.get_local_appdata()

class DetectInstalledSites():

    def __init__(self, sitename = "All"):

        self.Config=Configuration.Config()
        #
        # objects returned
        #
        self.sitestatusdict = {}
        self.sitename = sitename
        self.heroname = ""
        self.hhpath = ""
        self.detected = ""
        #
    See TestDetectInstalledSites.py

Todo:
    replace hardcoded site list with something more subtle

"""
import platform
import os

import Configuration
Config = Configuration.Config()

if Config.os_family in ['Win7', 'XP']:
    import winpaths
    PROGRAM_FILES = winpaths.get_program_files()
    LOCAL_APPDATA = winpaths.get_local_appdata()


class DetectInstalledSites():
    def __init__(self, sitename="All"):
        #
        # objects returned
        #
        self.sitestatusdict = {}
        self.sitename = sitename
        self.heroname = ""
        self.hhpath = ""
        self.detected = ""
        #
        #since each site has to be hand-coded in this module, there
        #is little advantage in querying the sites table at the moment.
Exemplo n.º 11
0
import os
import wx
import winpaths

import familysysadmin.familysysadmin

# todo:
# - figure out how to not have an error when starting up with nothing in the registry
# - make guid text boxes reasonable big even if there is nothing yet

if __name__ == "__main__":
    app_data_folder = os.path.join(winpaths.get_local_appdata(),
                                   familysysadmin.familysysadmin.APP_NAME)
    if not os.path.exists(app_data_folder):
        os.mkdir(app_data_folder)
    redirect_file = os.path.join(app_data_folder, 'log.txt')
    if os.path.exists(redirect_file):
        os.remove(redirect_file)
    app = familysysadmin.familysysadmin.FamilySysAdminApp(
        redirect=True, filename=redirect_file)
    app.MainLoop()
Exemplo n.º 12
0
import os
import wx
import winpaths

import familysysadmin.familysysadmin

# todo:
# - figure out how to not have an error when starting up with nothing in the registry
# - make guid text boxes reasonable big even if there is nothing yet

if __name__ == "__main__":
    app_data_folder = os.path.join(winpaths.get_local_appdata(), familysysadmin.familysysadmin.APP_NAME)
    if not os.path.exists(app_data_folder):
        os.mkdir(app_data_folder)
    redirect_file = os.path.join(app_data_folder, "log.txt")
    if os.path.exists(redirect_file):
        os.remove(redirect_file)
    app = familysysadmin.familysysadmin.FamilySysAdminApp(redirect=True, filename=redirect_file)
    app.MainLoop()
Exemplo n.º 13
0
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""

import os
import sys
from pathlib import Path

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if sys.platform == "win32":
    import winpaths
    USERDATA_DIR = Path(winpaths.get_local_appdata())
else:
    USERDATA_DIR = Path.home() / ".pharmaship"
USERDATA_DIR.mkdir(parents=True, exist_ok=True)

DB_PATH = USERDATA_DIR / 'db.sqlite3'

# Pharmaship configuration
PHARMASHIP_DATA = Path(BASE_DIR) / "data"
PHARMASHIP_GUI = Path(BASE_DIR) / "gui/templates"
PHARMASHIP_REPORTS = Path(BASE_DIR) / "gui/reports"
PHARMASHIP_LOCALE = Path(BASE_DIR) / "gui/locale"
PHARMASHIP_CONF = USERDATA_DIR / "config.yaml"
PHARMASHIP_LOG = USERDATA_DIR / 'pharmaship.log'

VALIDATOR_PATH = Path(BASE_DIR) / "schemas"