Ejemplo n.º 1
0
def main():
    import pprint
    dhnio.SetDebug(14)
    if sys.argv.count('list'):
        pprint.pprint(lst())
    elif sys.argv.count('info'):
        pprint.pprint(info())
    elif sys.argv.count('add'):
        print add(sys.argv[2], 'TCP')
    elif sys.argv.count('del'):
        print dlt(sys.argv[2], 'TCP')
    elif sys.argv.count('update'):
        dhnio.init()
        settings.init()
        init()
        pprint.pprint(update(sys.argv[2]))
    elif sys.argv.count('clear'):
        print clear()
    else:
        print 'usage:'
        print 'run_upnpc.py info'
        print 'run_upnpc.py list'
        print 'run_upnpc.py add [port]'
        print 'run_upnpc.py del [port]'
        print 'run_upnpc.py update [port]'
        print 'run_upnpc.py clear'
Ejemplo n.º 2
0
def test1():
    dhnio.SetDebug(20)
    dhnio.init()
    settings.init()
    update_sheduler()
    #SetLocalDir('c:\\Program Files\\\xc4 \xd8 \xcd')
    #download_and_replace_starter()
    reactor.run()
Ejemplo n.º 3
0
def main():
    s.init(get_loc())
    components = get_components()

    while True:
        installedstate = menu.installed_states(components)
        anythinginstalled = len(installedstate[True]) > 0
        anyresultsunanalysed = amenu.should_show(components)
        anyexecutionunfinished = resmenu.should_show(components)
        if anythinginstalled:
            print('')
            print('Installed:')
            for item in installedstate[True]:
                print(item)
        print('')
        print('Not installed:')
        for item in installedstate[False]:
            print(item)
        print('')

        if anyresultsunanalysed:
            print('\t[A]nalyse')
        if anythinginstalled:
            print('\t[E]xecute')
        if anyexecutionunfinished:
            print('\tRe[S]tart')
        print('\t[I]nstall')
        if anythinginstalled:
            print('\t[R]econfigure')
        print('[Q]uit/[B]ack')
        choice = input('Please make a choice: ')
        choice = choice.upper()
        if anyresultsunanalysed and choice in ('A', 'ANALYSE'):
            amenu.analysis_menu(components)
        elif anythinginstalled and choice in ('E', 'EXECUTE'):
            emenu.execute_menu(components)
        elif anyexecutionunfinished and choice in ('S', 'RESTART'):
            resmenu.restart_execute_menu(components)
        elif choice in ('I', 'INSTALL'):
            imenu.install_menu(components)
        elif anythinginstalled and choice in ('R', 'RECONFIGURE'):
            recmenu.reconfig_menu(components)
        elif choice in ('Q', 'QUIT', 'B', 'BACK'):
            return
        else:
            print('Please choose something valid')
Ejemplo n.º 4
0
import methods
from methods import Create
from methods import View
from methods import Edit
from lib import settings
from lib import FormatSheet
from lib import PopulateSheet
from classes import CharacterClass
import pickle

if not os.path.exists('Excel/'):
    os.makedirs('Excel/')
if not os.path.exists('Characters/'):
    os.makedirs('Characters/')

settings.init()


def LoadCharacter():
    characterName = input("Which character do you want to load?")
    object = open('Characters/' + characterName, 'rb')
    character = pickle.load(object)
    print('{} {}'.format(character.name, character.characterclass.race))


progrun = True
while progrun == True:
    action = 0
    actioncheck = False
    while actioncheck == False:
        print('Would you like to:')
Ejemplo n.º 5
0
    dhnio.Dprint(6, "p2p_service.CheckWholeBackup with BackupID=" + BackupID)

#-------------------------------------------------------------------------------

def message2gui(proto, text):
    pass
#    statusline.setp(proto, text)


def getErrorString(error):
    try:
        return error.getErrorMessage()
    except:
        if error is None:
            return ''
        return str(error)


def getHostString(host):
    try:
        return str(host.host)+':'+str(host.port)
    except:
        if host is None:
            return ''
        return str(host)

if __name__ == '__main__':
    settings.init()
    print ListCustomerFiles('http://identity.datahaven.net/eeekat4.xml')

Ejemplo n.º 6
0
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

import os, sys, signal, time, thread, threading
from lib import settings

tomato_module = settings.Config.TOMATO_MODULE_BACKEND_DEBUG
settings.init('/etc/tomato/config.yaml', tomato_module)
os.environ['TOMATO_MODULE'] = tomato_module

from lib import monkey
monkey.patch_all()

import socket
socket.setdefaulttimeout(300)

from mongoengine import connect
database_connection = connect(settings.settings.get_db_settings()['database'],
                              host=settings.settings.get_db_settings()['host'])
database_obj = getattr(database_connection,
                       settings.settings.get_db_settings()['database'])

from .lib import logging
Ejemplo n.º 7
0
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

import os, sys, signal, time, thread

from lib import settings

tomato_module = settings.Config.TOMATO_MODULE_BACKEND_API
settings.init("/etc/tomato/config.yaml", tomato_module)
os.environ["TOMATO_MODULE"] = tomato_module

import socket

socket.setdefaulttimeout(1800)

import threading

_currentUser = threading.local()


def getCurrentUserInfo():
    """
	get the current user's PermissionChecker object
	:return: current user's PermissionChecker object
Ejemplo n.º 8
0
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>

import os
import signal
import sys
import thread
import time

import monkey
monkey.patch_all()

from lib import settings

tomato_module = settings.Config.TOMATO_MODULE_BACKEND_CORE
settings.init('/etc/tomato/config.yaml', tomato_module)
os.environ['TOMATO_MODULE'] = tomato_module

import socket
socket.setdefaulttimeout(1800)

from mongoengine import connect
database_settings = settings.settings.get_db_settings()
database_connnection = connect(database_settings['database'], host=database_settings['host'], port=database_settings['port'])
database_obj = getattr(database_connnection, database_settings['database'])

from lib import logging

from lib import tasks #@UnresolvedImport
scheduler = tasks.TaskScheduler(maxLateTime=30.0, minWorkers=5, maxWorkers=settings.settings.get_tasks_settings()[settings.Config.TASKS_MAX_WORKERS])
Ejemplo n.º 9
0
        import terminaltables  # try to import specifically required module
    except ImportError:
        print "\nThere was a problem importing the 'terminaltables' module."
        print "\nPlease ensure you have 'terminaltables' installed. For more information visit:"
        print "\nhttps://robpol86.github.io/terminaltables/install.html"
        print "\nYou can install it by running 'pip install terminaltables' in your terminal window"
        raw_input("\nPress ENTER to be taken to website or CTRL+C to exit")

        webbrowser.open_new_tab(
            'https://robpol86.github.io/terminaltables/install.html'
        )  # take user to web page
        sys.exit()  # program cannot run without module so exit now

    # Import custom modules from private library
    from lib import settings
    settings.init()  # set up program defaults and global variables

    # Check if user is on Mac or Linux, if not then exit.
    if settings.platform_current == 'Darwin' or settings.platform_current == 'Linux':
        pass
    else:
        print "You are not running a UNIX based OS (macOS/Linux). This program is not compatible with other OS."
        raw_input("Press ENTER to exit.")
        sys.exit()

    # Check that the user is using a terminal window - not pycharm.
    if not sys.stdout.isatty():
        print "You are not on a UNIX terminal. This program only runs in UNIX (macOS/Linux) terminal windows."
        raw_input("Press ENTER to exit.")
        sys.exit()
Ejemplo n.º 10
0
def run(opts, args, overDict, pars):
    """
    The entry point, this is called from `p2p.dhnmain` to process command line arguments.
    """
    print 'Copyright 2006, DataHaven.NET LTD. of Anguilla. All rights reserved.'
    
    if overDict:
        settings.override_dict(overDict)
    dhnio.init()
    settings.init()
    if not opts or opts.debug is None:
        dhnio.SetDebug(0)

    appList = dhnio.find_process([
        'dhnmain.exe',
        'dhnmain.py',
        'dhn.py',
        'regexp:^/usr/bin/python\ +/usr/bin/datahaven.*$',
        ])
    running = len(appList) > 0
   
    cmd = ''
    if len(args) > 0:
        cmd = args[0].lower()
    
    #---help---
    if cmd in ['help', 'h']:
        import help
        if len(args) >= 2 and args[1].lower() == 'schedule':
            print help.schedule_format()
        elif len(args) >= 2 and args[1].lower() == 'settings':
            print settings.uconfig().print_all()
        else:
            print help.help()
            print pars.format_option_help()
        return 0
    
    #---backup---
    elif cmd in ['backup', 'backups', 'bk']:
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_backups(opts, args, overDict)

    #---restore---
    elif cmd in ['restore', 're']:
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_restore(opts, args, overDict)

    #---schedule---
    elif cmd in ['schedule', 'shed', 'sched', 'sh']:
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_schedule(opts, args, overDict)

    #---suppliers---
    elif cmd in [ 'suppliers', 'supplier', 'sup', 'supp', 'sp', ]:
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_suppliers(opts, args, overDict)
    
    #---customers---
    elif cmd in [ 'customers', 'customer', 'cus', 'cust', 'cs', ]:
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_customers(opts, args, overDict)

    #---register---
    elif cmd == 'register':
        if running:
            print 'DataHaven.NET already started.\n'
            return 0
        return cmd_register(opts, args, overDict)

    #---recover---
    elif cmd == 'recover':
        if running:
            print 'DataHaven.NET already started.\n'
            return 0
        return cmd_recover(opts, args, overDict)

    #---key---
    elif cmd == 'key':
        return cmd_key(opts, args, overDict)

    #---stats---
    elif cmd in [ 'stats', 'st' ]:
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_stats(opts, args, overDict)

    #---version---
    elif cmd in [ 'version', 'v', 'ver' ]:
        revnum = dhnio.ReadTextFile(settings.RevisionNumberFile()).strip()
        repo, location = misc.ReadRepoLocation()
        print 'revision:  ', revnum
        print 'repository:', repo
        return 0

    #---states---
    elif cmd in [ 'states', 'sta', 'automats', 'auto' ]:
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_states(opts, args, overDict)

    #---reconnect---
    elif cmd in [ 'reconnect', ]:
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_reconnect(opts, args, overDict)
        
    #---set---
    elif cmd == 'set':
        if len(args) == 1 or args[1].lower() in [ 'help', '?' ]:
            import help
            print help.settings_help()
            return 0
        if not running:
            cmd_set_directly(opts, args, overDict)
            return 0
        return cmd_set_request(opts, args, overDict)
    
    #---memory---
    elif cmd == 'memory':
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_memory(opts, args, overDict)
    
    #---money---
    elif cmd == 'money':
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_money(opts, args, overDict)
    
    elif cmd == 'storage':
        if not running:
            print 'DataHaven.NET is not running at the moment\n'
            return 0
        return cmd_storage(opts, args, overDict)
    
#    elif cmd == 'uninstall':
#        return cmd_uninstall(opts, args, overDict)
    
    return 2
Ejemplo n.º 11
0
def run(UI='', options=None, args=None, overDict=None):
    """
    In the method `main()` program firstly checks the command line arguments 
    and then calls this method to start the whole process.
    This initialize some low level modules and finally create 
    an instance of `initializer()` state machine and send it an event "run".
    """
    
    import lib.dhnio as dhnio
    dhnio.Dprint(6, 'dhnmain.run sys.path=%s' % str(sys.path))
    
    #---USE_TRAY_ICON---
    try:
        from dhnicon import USE_TRAY_ICON
        dhnio.Dprint(4, 'dhnmain.run USE_TRAY_ICON='+str(USE_TRAY_ICON))
        if dhnio.Linux() and not dhnio.X11_is_running():
            USE_TRAY_ICON = False
        if USE_TRAY_ICON:
            from twisted.internet import wxreactor
            wxreactor.install()
    except:
        USE_TRAY_ICON = False
        dhnio.DprintException()

    if USE_TRAY_ICON:
        if dhnio.Linux():
            icons_dict = {
                'red':      'icon-red-24x24.png',
                'green':    'icon-green-24x24.png',
                'gray':     'icon-gray-24x24.png',
                }
        else:
            icons_dict = {
                'red':      'icon-red.png',
                'green':    'icon-green.png',
                'gray':     'icon-gray.png',
                }
        import dhnicon
        icons_path = str(os.path.abspath(os.path.join(dhnio.getExecutableDir(), 'icons')))
        dhnio.Dprint(4, 'dhnmain.run call dhnicon.init(%s)' % icons_path)
        dhnicon.init(icons_path, icons_dict)
        def _tray_control_func(cmd):
            if cmd == 'exit':
                #import dhninit
                #dhninit.shutdown_exit()
                import shutdowner
                shutdowner.A('stop', 'exit')
        dhnicon.SetControlFunc(_tray_control_func)

    dhnio.Dprint(4, 'dhnmain.run want to import twisted.internet.reactor')
    try:
        from twisted.internet import reactor
    except:
        dhnio.DprintException()
        sys.exit('Error initializing reactor in dhnmain.py\n')

    #---settings---
    import lib.settings as settings
    if overDict:
        settings.override_dict(overDict)
    settings.init()
    if not options or options.debug is None:
        dhnio.SetDebug(settings.getDebugLevel())

    #---logfile----
    if dhnio.EnableLog and dhnio.LogFile is not None:
        dhnio.Dprint(2, 'dhnmain.run want to switch log files')
        if dhnio.Windows() and dhnio.isFrozen():
            dhnio.StdOutRedirectingStop()
        dhnio.CloseLogFile()
        dhnio.OpenLogFile(settings.MainLogFilename()+'-'+time.strftime('%y%m%d%H%M%S')+'.log')
        if dhnio.Windows() and dhnio.isFrozen():
            dhnio.StdOutRedirectingStart()
            
    #---memdebug---
    if settings.uconfig('logs.memdebug-enable') == 'True':
        try:
            import lib.memdebug as memdebug
            memdebug_port = int(settings.uconfig('logs.memdebug-port'))
            memdebug.start(memdebug_port)
            reactor.addSystemEventTrigger('before', 'shutdown', memdebug.stop)
            dhnio.Dprint(2, 'dhnmain.run memdebug web server started on port %d' % memdebug_port)
        except:
            dhnio.DprintException()  
            
    #---process ID---
    try:
        pid = os.getpid()
        pid_file_path = os.path.join(settings.MetaDataDir(), 'processid')
        dhnio.WriteFile(pid_file_path, str(pid))
        dhnio.Dprint(2, 'dhnmain.run wrote process id [%s] in the file %s' % (str(pid), pid_file_path))
    except:
        dhnio.DprintException()  
            
#    #---reactor.callLater patch---
#    if dhnio.Debug(12):
#        patchReactorCallLater(reactor)
#        monitorDelayedCalls(reactor)

    dhnio.Dprint(2,"dhnmain.run UI=[%s]" % UI)

    if dhnio.Debug(10):
        dhnio.Dprint(0, '\n' + dhnio.osinfofull())

    dhnio.Dprint(4, 'dhnmain.run import automats')

    #---START!---
    import lib.automat as automat
    automat.LifeBegins(dhnio.LifeBeginsTime)
    automat.OpenLogFile(settings.AutomatsLog())
    
    import initializer
    import shutdowner

    dhnio.Dprint(4, 'dhnmain.run send event "run" to initializer()')
    
    #reactor.callLater(0, initializer.A, 'run', UI)
    initializer.A('run', UI)

    #reactor.addSystemEventTrigger('before', 'shutdown', lambda : initializer.A('reactor-stopped'))

    dhnio.Dprint(2, 'dhnmain.run calling reactor.run()')
    reactor.run()
    dhnio.Dprint(2, 'dhnmain.run reactor stopped')
    # this will call initializer() without reactor.callLater(0, ... )
    # we do not have any timers initializer() so do not worry
    #initializer.A('reactor-stopped', use_reactor = False)
    shutdowner.A('reactor-stopped')

    dhnio.Dprint(2, 'dhnmain.run finished, EXIT')

    automat.objects().clear()
    automat.CloseLogFile()

##    import threading
##    dhnio.Dprint(0, 'threads:')
##    for t in threading.enumerate():
##        dhnio.Dprint(0, '  '+str(t))

    dhnio.CloseLogFile()

    if dhnio.Windows() and dhnio.isFrozen():
        dhnio.StdOutRedirectingStop()

    return 0