Ejemplo n.º 1
0
 def run(self):
     while self.__running.isSet():
         try:
             utils.debug(utils.debug_line(), "testthreadclass",
                         "hello,python")
         except:
             utils.debug(utils.debug_line(), "testthreadclass")
         time.sleep(10)
Ejemplo n.º 2
0
 def __init__ (self, threadname, ip, conn):
     try:
         threading.Thread.__init__(self, name = threadname)
         self._ip = ip
         self._conn = conn
     except:
         utils.debug(utils.debug_line(),"httpthreadclass")
Ejemplo n.º 3
0
 def __init__(self, threadname):
     try:
         threading.Thread.__init__(self, name=threadname)
         self.__running = threading.Event()
         self.__running.set()
     except:
         utils.debug(utils.debug_line(), "testthreadclass")
Ejemplo n.º 4
0
def Recvdate(conn):
    try:
        conn.settimeout(5)
        readbuf = conn.recv(settings.BUFFSIZE)
        return readbuf
    except:
        utils.debug(utils.debug_line(), "sockets", 'Recive data time out!')
        return -1
Ejemplo n.º 5
0
 def __init__ (self,threadname):
     try:
         threading.Thread.__init__(self, name=threadname)
         self.sock = httpsocket.HttpSocket()
         self.__running = threading.Event()
         self.__running.set()
     except:
         utils.debug(utils.debug_line(),"httpthreadclass")
Ejemplo n.º 6
0
def stop():
    global HTTPTHREAD
    try:
        if HTTPTHREAD and isinstance(HTTPTHREAD,HttpThread):
            if HTTPTHREAD._HttpThread__running.isSet():
                HTTPTHREAD._HttpThread__running.clear()
    except:
        utils.debug(utils.debug_line(),"httpthreadclass")
Ejemplo n.º 7
0
def stop():
    global TESTTHREAD
    try:
        if TESTTHREAD and isinstance(TESTTHREAD, TestThread):
            if TESTTHREAD._TestThread__running.isSet():
                TESTTHREAD._TestThread__running.clear()
    except:
        utils.debug(utils.debug_line(), "testthreadclass")
Ejemplo n.º 8
0
def httpsocket_recv(conn):
    readbuf = None
    try:
        conn.settimeout(TIMEOUT)
        readbuf = conn.recv(BUFFSIZE)
    except:
        readbuf = None
        utils.debug(utils.debug_line(), "httpsocket", 'Recive data time out!')
    return readbuf
Ejemplo n.º 9
0
 def run(self):
     while self.__running.isSet():
         try:
             conn,addr = self.sock.Accept()
             workthread = WorkThread(str(addr[1]),addr[0],conn)
             workthread.start()
         except:
             utils.debug(utils.debug_line(),"httpthreadclass")
         time.sleep(.1)
Ejemplo n.º 10
0
def main():
    try:
        if len(sys.argv) > 1 and sys.argv[1] == '-D':
            settings.DEBUG = True
        #启动线程
        threadclass.init_thread()
        #记录启动日志
        utils.debug(utils.debug_line(), "main", "system start success")
        #接收WEB请求
        sock = httpsocket.HttpSocket()
        while True:
            try:
                conn, addr = sock.Accept()
                workthread = threadclass.WorkThread(str(addr[1]), addr[0],
                                                    conn)
                workthread.start()
            except:
                utils.debug(utils.debug_line(), "main")
    except:
        utils.debug(utils.debug_line(), "main")
Ejemplo n.º 11
0
def start():
    global HTTPTHREAD
    try:
        if HTTPTHREAD and isinstance(HTTPTHREAD, HttpThread) and HTTPTHREAD.isAlive():
            if not HTTPTHREAD._HttpThread__running.isSet():
                HTTPTHREAD._HttpThread__running.set()
                HTTPTHREAD.start()
        else:
            HTTPTHREAD = HttpThread('HTTPTHREAD')
            HTTPTHREAD.start()
    except:
        utils.debug(utils.debug_line(),"httpthreadclass")
Ejemplo n.º 12
0
def init_thread():
    global THREADS
    CURR_THREADS = set(
    )  #存放当前扫描到的线程列表,和THREADS比较,THREADS没有的则启动,THREADS有但CURR_THREADS没有的则停止
    try:
        #如果有license控制,筛选列表
        if os.path.exists(THREADCLASS_FILE_PATH):
            items = os.listdir(THREADCLASS_FILE_PATH)
            for item in items:
                im = re.match('((\S+thread)class)\.py*', item)
                itempath = os.path.join(THREADCLASS_FILE_PATH, item)
                if os.path.isfile(itempath) and im:
                    module_name = im.group(1)
                    try:
                        module = '%s.%s' % (THREADCLASS_PATH_NAME, module_name)
                        #不在现有线程列表里的开启
                        if not module in THREADS:
                            __import__(module)
                            if hasattr(sys.modules[module], "start"):
                                sys.modules[module].start()
                                utils.debug(utils.debug_line(), "threadclass",
                                            "Start thread %s" % module)
                        else:
                            #已在现有线程列表的重载
                            if hasattr(sys.modules[module], "stop"):
                                sys.modules[module].stop()
                                reload(sys.modules[module])
                                sys.modules[module].start()
                                utils.debug(utils.debug_line(), "threadclass",
                                            "Reload thread %s" % module)
                        CURR_THREADS.add(module)
                    except:
                        utils.debug(utils.debug_line(), "threadclass")
            THREADS_TO_STOP = THREADS - CURR_THREADS
            for module in THREADS_TO_STOP:
                if hasattr(sys.modules[module], "stop"):
                    sys.modules[module].stop()
            THREADS = CURR_THREADS
    except:
        utils.debug(utils.debug_line(), "threadclass")
Ejemplo n.º 13
0
def start():
    global TESTTHREAD
    try:
        if TESTTHREAD and isinstance(TESTTHREAD,
                                     TestThread) and TESTTHREAD.isAlive():
            if not TESTTHREAD._TestThread__running.isSet():
                TESTTHREAD._TestThread__running.set()
                TESTTHREAD.start()
        else:
            TESTTHREAD = TestThread('TESTTHREAD')
            TESTTHREAD.start()
    except:
        utils.debug(utils.debug_line(), "testthreadclass")
Ejemplo n.º 14
0
 def run (self):
     rtndata = json.dumps({'state':'1','result':'9998'}) #数据传输失败
     try:
         cmddata = httpsocket.httpsocket_recv(self._conn)
         if cmddata:
             cmd = json.loads(cmddata)
             if 'params' in cmd:
                 cmd['params']['_ip'] = self._ip
             rtndata = dataprocess.http_dataprocess(cmd)
             sockets.Senddata(self._conn,rtndata)
     except:
         utils.debug(utils.debug_line(),"httpthreadclass")
     finally:
         httpsocket.httpsocket_close(self._conn)
Ejemplo n.º 15
0
 def __init__(self):
     try:
         self.conn = ''
         self.address = ''
         self.httpsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self.httpsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
         while True:
             try:
                 self.httpsock.bind(('0.0.0.0', HTTPSOCK_PORT))
                 self.httpsock.listen(100)
                 break
             except Exception, e:
                 pass
             time.sleep(1)
     except:
         utils.debug(utils.debug_line(), "httpsocket")
Ejemplo n.º 16
0
 def __init__(self):
     self.connection = ''
     self.address = ''
     self.httpcommunicatesock = socket.socket(socket.AF_INET,
                                              socket.SOCK_STREAM)
     self.httpcommunicatesock.setsockopt(socket.SOL_SOCKET,
                                         socket.SO_REUSEADDR, 1)
     while True:
         try:
             self.httpcommunicatesock.bind(('0.0.0.0', 1981))
             self.httpcommunicatesock.listen(20)
             break
         except Exception, e:
             utils.debug(utils.debug_line(),
                         "httpsocket-httpcommunicatesock")
         time.sleep(1)
Ejemplo n.º 17
0
def CloseSocket(conn):
    try:
        conn.close()
    except:
        utils.debug(utils.debug_line(), "sockets", traceback.print_exc())
Ejemplo n.º 18
0
def Senddata(conn, senddata='ok'):
    try:
        sendbuf = conn.sendall(senddata)
    except:
        utils.debug(utils.debug_line(), "sockets", traceback.print_exc())
Ejemplo n.º 19
0
        break

if stayQuiet == True:
    utils.setVerbose(0)

# get KDEROOT from env
KDEROOT = os.getenv( "KDEROOT" )
utils.debug( "buildAction: %s" % mainBuildAction )
utils.debug( "doPretend: %s" % doPretend, 1 )
utils.debug( "packageName: %s" % packageName )
utils.debug( "buildType: %s" % os.getenv( "EMERGE_BUILDTYPE" ) )
utils.debug( "buildTests: %s" % utils.envAsBool( "EMERGE_BUILDTESTS" ) )
utils.debug( "verbose: %d" % utils.verbose(), 1 )
utils.debug( "trace: %s" % os.getenv( "EMERGE_TRACE" ), 1 )
utils.debug( "KDEROOT: %s\n" % KDEROOT, 1 )
utils.debug_line()

def unset_var( varname ):
    if not os.getenv( varname ) == None:
        print
        utils.warning( "%s found as environment variable. you cannot override emerge"\
                       " with this - unsetting %s locally" % ( varname, varname ) )
        os.environ[ varname ] = ""

unset_var( "CMAKE_INCLUDE_PATH" )
unset_var( "CMAKE_LIBRARY_PATH" )
unset_var( "CMAKE_FIND_PREFIX" )
unset_var( "CMAKE_INSTALL_PREFIX" )

# adding emerge/bin to find base.py and gnuwin32.py etc.
os.environ["PYTHONPATH"] = os.getenv( "PYTHONPATH", "" ) + os.pathsep + \
Ejemplo n.º 20
0
def main():
    """ Testing the class"""

    # add two databases
    tempdbpath1 = os.path.join( os.getenv("KDEROOT"), "tmp", "temp1.db" )
    tempdbpath2 = os.path.join( os.getenv("KDEROOT"), "tmp", "temp2.db" )

    if not os.path.exists( os.path.join( os.getenv( "KDEROOT" ), "tmp" ) ):
        os.makedirs( os.path.join( os.getenv( "KDEROOT" ), "tmp" ) )

    if os.path.exists( tempdbpath1 ):
        os.remove( tempdbpath1 )
    if os.path.exists( tempdbpath2 ):
        os.remove( tempdbpath2 )

    db_temp = InstallDB( tempdbpath1 )
    db = InstallDB( tempdbpath2 )

    utils.debug( 'testing installation database' )

    utils.debug( 'testing if package win32libs/dbus-src with version 1.4.0 is installed: %s' %
                 db.isPkgInstalled( 'win32libs', 'dbus-src', '1.4.0' ) )

    # in case the package is still installed, remove it first silently
    if db.isInstalled( 'win32libs', 'dbus-src', '1.4.0' ):
        packageList = db.remInstalled( 'win32libs', 'dbus-src', '1.4.0' )
        # really commit uninstall
        for package in packageList:
            package.uninstall()
    utils.debug_line()

    utils.new_line()
    # add a package
    utils.debug( 'installing package win32libs/dbus-src-1.4.0 (release)' )
    package = db.addInstalled( 'win32libs', 'dbus-src', '1.4.0', 'release' )
    package.addFiles( dict().fromkeys( [ 'test', 'test1', 'test2' ], 'empty hash' ) )
    # now really commit the package
    package.install()

    # add another package in a different prefix
    utils.debug( 'installing package win32libs/dbus-src-1.4.0 (debug)' )
    package = db.addInstalled( 'win32libs', 'dbus-src', '1.4.0', 'debug' )
    package.addFiles( dict().fromkeys( [ 'test', 'test1', 'test2' ], 'empty hash' ) )
    # now really commit the package
    package.install()
    utils.debug_line()

    utils.new_line()
    utils.debug( 'checking installed packages' )
    utils.debug( 'get installed package (release): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'release' ) )
    utils.debug( 'get installed package (debug):   %s' % db.getInstalled( 'win32libs', 'dbus-src', 'debug' ) )

    utils.new_line()
    utils.debug( 'now trying to remove package & revert it again later' )
    # remove the package again
    packageList = db.remInstalled( 'win32libs', 'dbus-src', '1.4.0' )
    for pac in packageList:
        for line in pac.getFiles(): # pylint: disable=W0612
            # we could remove the file here
            # print line
            pass
    utils.debug_line()

    utils.new_line()
    utils.debug( 'checking installed packages' )
    utils.debug( 'get installed package (release): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'release' ) )
    utils.debug( 'get installed package (debug):   %s' % db.getInstalled( 'win32libs', 'dbus-src', 'debug' ) )
    utils.debug_line()

    utils.new_line()
    utils.debug( 'reverting removal' )
    # now instead of completing the removal, revert it
    for pac in packageList:
        pac.revert()

    utils.debug( 'checking installed packages' )
    utils.debug( 'get installed package (release): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'release' ) )
    utils.debug( 'get installed package (debug):   %s' % db.getInstalled( 'win32libs', 'dbus-src', 'debug' ) )
    utils.debug_line()

    db.getInstalled()
    db.getInstalled( category='win32libs', prefix='debug' )
    db.getInstalled( package='dbus-src' )

    utils.new_line()
    utils.debug( 'now really remove the package' )
    packageList = db.remInstalled( 'win32libs', 'dbus-src', '1.4.0')
    for pac in packageList:
        utils.debug( 'removing %s files' % len( pac.getFiles() ) )
        pac.uninstall()

    utils.debug( 'get installed package (release): %s' % db.getInstalled( 'win32libs', 'dbus-src', 'release' ) )
    utils.debug( 'get installed package (debug):   %s' % db.getInstalled( 'win32libs', 'dbus-src', 'debug' ) )
    utils.debug_line()

    # test the import from the old style (manifest based) databases
    utils.new_line()
    db_temp.importExistingDatabase()
    print("getInstalled:", db_temp.getInstalled())
    print("findInstalled:", portage.findInstalled( 'win32libs', 'dbus-src' ))
    print("getFileListFromManifest:", len( utils.getFileListFromManifest( os.getenv( "KDEROOT" ), 'dbus-src' ) ))
Ejemplo n.º 21
0
def httpsocket_close(conn):
    try:
        conn.close()
    except:
        utils.debug(utils.debug_line(), "httpsocket")
Ejemplo n.º 22
0
 def Accept(self):
     try:
         self.connection, self.address = self.httpcommunicatesock.accept()
         return self.connection, self.address
     except:
         utils.debug(utils.debug_line(), "httpsocket-httpcommunicatesock")
Ejemplo n.º 23
0
def httpsocket_send(conn, senddata='ok'):
    try:
        sendbuf = conn.sendall(senddata)
    except:
        utils.debug(utils.debug_line(), "httpsocket")
Ejemplo n.º 24
0
 def Accept(self):
     try:
         self.conn, self.address = self.httpsock.accept()
         return self.conn, self.address
     except:
         utils.debug(utils.debug_line(), "httpsocket")