Esempio n. 1
0
def clear_upload_in_progress(dir):
    """ Clear the upload in progress flag for the given directory
    """

    data = get_reg_value('HKLM', APP_DIR_REG_KEY, dir)
    data[DIR_UPLOAD_IN_PROGRESS] = 'false'
    set_reg_value('HKLM', APP_DIR_REG_KEY, dir, data)
Esempio n. 2
0
 def wrap_error(*args, **kwargs):
     try:
         set_reg_value('HKLM', APP_REG_KEY, 'internal_error', False)
         fn(*args, **kwargs)
     except rest.ErrorResponse, e:
         log.error('Application auth callback failure', exc_info=True,
             culprit=__culprit__)
         set_reg_value('HKLM', APP_REG_KEY, 'internal_error', True)
         redirect('/index.html')
Esempio n. 3
0
def add_watch_directory(path):
    """ Add the give n path to the list of directories to watch

    This only stores the info regarding the directory in the registry.  It does
    not start watching the directory.

    """
    absolute_path = os.path.abspath(path)
    tstamp = strftime('%d %b %Y')
    set_reg_value('HKLM', APP_DIR_REG_KEY, absolute_path,
                  [tstamp, 'None', 'true', 'false'])
Esempio n. 4
0
def set_directory_change_time(dir):
    """ Sets the last change time for the given directory

    """

    if dir in get_watched_directories():
        added, changed, _, inprogress = get_watched_directory_info(dir)
        pending = pending_changes(dir)
        set_reg_value('HKLM', APP_DIR_REG_KEY, dir,
                      [added, strftime('%d %b %Y %H:%M'), 'false',
                       str(inprogress).lower()])
Esempio n. 5
0
def set_pending_changes(dir, pending=True):
    """ Mark the directory for pending changes

    By default the directory is marked stating that pending changes are waiting.
    If pending=False, then the pending changes flag is removed

    """

    added, changed, _, inprogress = get_watched_directory_info(dir)
    set_reg_value('HKLM', APP_DIR_REG_KEY, dir,
                    [added, changed, str(pending).lower(),
                     str(inprogress).lower()])
Esempio n. 6
0
    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        # Looks like py2exe handles redirecting stdout and stderror for us
        #sys.stdout.close()
        #sys.stderr.close()
        #sys.stdout = NullOutput()
        #sys.stderr = NullOutput()
        # Create an event which we will use to wait on.
        # The "service stop" request will set this event.
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)
        # Event for named pipe operation
        self.overlapped = pywintypes.OVERLAPPED()
        self.overlapped.hEvent = win32event.CreateEvent(None, 0, 0, None)
        # Internal timer
        self.timer = win32event.CreateWaitableTimer(None, 0, None)

        set_reg_value('HKLM', APP_REG_KEY, 'restartneeded', 0)
        # Setup Named pip for IPC
        pipename = get_reg_value('HKLM', APP_REG_KEY, 'namedpipe')
        self.pipe_handle = None
        if not pipename:
            log.error('No named pipe was specified in the registry',
                        culprit=__culprit__)
            self.SvcStop()
        else:
            openmode = PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED
            pipmode = PIPE_TYPE_MESSAGE
            sa = pywintypes.SECURITY_ATTRIBUTES()
            sa.SetSecurityDescriptorDacl(1, None, 0)
            self.pipe_handle = CreateNamedPipe(pipename, openmode, pipmode,
                                                PIPE_UNLIMITED_INSTANCES, 0, 0,
                                                0, sa)

        # Initialize a list of watched handles
        self.handles = list()
        self.mgmt_handles = list()
        self.mgmt_callbacks = list()
Esempio n. 7
0
def save_settings():
    port = get_reg_value('HKLM', APP_REG_KEY, 'port', default=4242)
    hostname = get_reg_value('HKLM', APP_REG_KEY, 'hostname', default='127.0.0.1')
    sentrydsn = get_reg_value('HKLM', APP_REG_KEY, 'sentry_dsn')
    sentrysite = get_reg_value('HKLM', APP_REG_KEY, 'sentry_site')
    restartneeded = 0
    data = request.forms.settings_hostname
    if data:
        parts = data.split(':')
        if hostname <> parts[0].strip():
            log.info("--%s-- | --%s--" % (hostname, parts[0].strip()))
            hostname = parts[0].strip()
            restartneeded = 1
        if len(parts) > 1:
            try:
                if port <> int(parts[1].strip()):
                    port = int(parts[1].strip())
                    log.info("--%d-- | --%d--" % (port, int(parts[1].strip())))
                    restartneeded = 1
            except ValueError:
                log.error('Unable to set port to: %s' % parts[1].strip())

    data = request.forms.sentry_dsn if request.forms.sentry_dsn.lower() <> 'none' else None
    if data and (data <> sentrydsn):
        sentrydsn = data
        restartneeded = 1
    data = request.forms.sentry_site if request.forms.sentry_site.lower() <> 'none' else None
    if data and (data <> sentrysite):
        sentrysite = data
        restartneeded = 1
    swift_key = get_reg_value('HKLM', APP_STORAGE_REG_KEY, 'key')
    if not swift_key:
        swift_key = request.forms.settings_swift_key
    swift_password = get_reg_value('HKLM', APP_STORAGE_REG_KEY, 'password')
    if not swift_password:
        swift_password = request.forms.settings_swift_password
    swift_account = get_reg_value('HKLM', APP_STORAGE_REG_KEY, 'account')
    if not swift_account:
        swift_account = request.forms.settings_swift_account
    swift_auth_url = get_reg_value('HKLM', APP_STORAGE_REG_KEY, 'auth_url')
    if not swift_auth_url:
        swift_auth_url = request.forms.settings_swift_auth_url
    container = request.forms.settings_container
    set_reg_value('HKLM', APP_REG_KEY, 'hostname', hostname)
    set_reg_value('HKLM', APP_REG_KEY, 'port', port)
    set_reg_value('HKLM', APP_REG_KEY, 'restartneeded', restartneeded)
    set_reg_value('HKLM', APP_STORAGE_REG_KEY, 'container', container)
    set_reg_value('HKLM', APP_STORAGE_REG_KEY, 'key', swift_key)
    set_reg_value('HKLM', APP_STORAGE_REG_KEY, 'password', swift_password)
    set_reg_value('HKLM', APP_STORAGE_REG_KEY, 'account', swift_account)
    set_reg_value('HKLM', APP_STORAGE_REG_KEY, 'auth_url', swift_auth_url)
    set_reg_value('HKLM', APP_REG_KEY, 'sentry_dsn', sentrydsn)
    set_reg_value('HKLM', APP_REG_KEY, 'sentry_site', sentrysite)
    redirect('/index.html')