def __terminate__(): from vyperlogix.misc import _utils from vyperlogix.win.WinProcesses import Win32Processes from vyperlogix import misc from vyperlogix.misc import ObjectTypeName __programName__ = (sys.argv[0].split(os.sep)[-1].split('.'))[0] try: p = Win32Processes() pid = p.getProcessIdByName(__programName__) if (misc.isList(pid)) and (len(pid) > 0): pid = pid[0] elif (len(pid) == 0): pid = os.getpid() if (misc.isInteger(pid)): print 'DEBUG: pid="%s"' % (pid) print 'BEGIN:' _utils.terminate() print 'END !!!' else: print 'DEBUG: pid is not an Int because it is "%s" !!!' % (ObjectTypeName.typeClassName(pid)) except Exception as ex: info_string = _utils.formattedException(details=ex) print info_string
def __init__(self,ipAddress,portNum,retry=False): self.ipAddress = ipAddress self.portNum = portNum self.retry = retry __is__ = False while (1): try: self.__socket__ = socket.socket() self.__socket__.connect((self.ipAddress,self.portNum)) __is__ = True print 'INFO: Connection established...' break except socket.error: print >>sys.stderr, 'WARNING: Cannot connect to %s:%s at this time.' % (self.ipAddress,self.portNum) if (not retry): break print >>sys.stderr, 'INFO: Retrying connetion in 10 seconds...' time.sleep(10) if (not __is__) and (not retry): _utils.terminate('Cannot establish communications at this time. Aborting due to lack of retry...')
from optparse import OptionParser parser = OptionParser("usage: %prog -d DATABASE [-s]") parser.add_option('-d', '--database', dest='database', help="DATABASE file name", metavar="DATABASE") parser.add_option('-s', '--syncdb', dest='syncdb', action="store_true", help="should the database be created?") parser.add_option('-r', '--repl', dest='repl', action="store_true", help="start a REPL with access to your models") parser.add_option('--d', '--dumpdata', dest='dumpdata', action="store_true", help="django dumpdata") parser.add_option('-i', '--inspectdb', dest='inspectdb', action="store_true", help="django inspectdb") parser.add_option('-v', '--verbose', dest='verbose', help="verbose", action="store_true") options, args = parser.parse_args() if not options.database: parser.error("You must specify the database name") _utils.terminate('Cannot continue without the database name on the command line.') __cwd__ = os.path.expanduser("~") name = _utils.getProgramName() fpath = __cwd__ _log_path = _utils.safely_mkdir_logs(fpath=fpath) _log_path = _utils.safely_mkdir(fpath=_log_path,dirname=_utils.timeStampLocalTimeForFileName(delimiters=('_','-'),format=_utils.formatSalesForceTimeStr())) if (not os.path.exists(_log_path)): print >> sys.stderr, 'Logging path does not exist at "%s".' % (_log_path) logFileName = os.sep.join([_log_path,'%s.log' % (name)]) print '(%s) :: Logging to "%s".' % (_utils.timeStampLocalTime(),logFileName) from standalone.conf import settings
if (sys.platform == 'win32'): if (1 in run_tests): # Test #1 :: Create a new object data = {'items':['1','2','3','4','5']} json = tcpipbridge.tcpipConnector(simplejson.dumps(data)) print json print '='*40 def __callback__(*args, **kwargs): print 'DEBUG.%s: args=%s, kwargs=%s' % (misc.funcName(),args,kwargs) return args[0].replace('@vm2','@vm1') if (len(args) > 0) else args __eof__ = '@@@EOF@@@' if (2 in run_tests): tcpipbridge.startTCPIPBridge('127.0.0.1', 55555, callback=__callback__,__eof__=__eof__) print '+'*40 writer = tcpipbridge.SocketWriter('127.0.0.1', 55555) if (0): for i in xrange(0,100): writer.send('HELLO-%s' % (i)) writer.sendFile("C:\@vm2\simple-message-bus\data.json",__eof__=__eof__) time.sleep(1) _utils.terminate('Program complete.') else: print 'Do you have any idea what you are doing ? Get a grip and figure this out ! NOW !'
def die(reason): _utils.terminate(reason)
logger.error('(2) Database does not exist! Because: %s' % (__reason__)) return __is__ if (__name__ == '__main__'): ''' python database-api.py 127.0.0.1:9999 ''' import re import signal from django.core.management import call_command if options.syncdb: call_command('syncdb') _utils.terminate('Terminated: syncdb is complete.') elif options.repl: call_command('shell') _utils.terminate('Terminated: shell is complete.') elif options.dumpdata: call_command('dumpdata') _utils.terminate('Terminated: dumpdata is complete.') elif options.inspectdb: call_command('inspectdb') _utils.terminate('Terminated: inspectdb is complete.') __re__ = re.compile(r"(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):([0-9]{1,5})", re.MULTILINE) #sys.argv = [sys.argv[0]] if (options.address and __re__.search(options.address)):
def exit(self, status=0, msg=None): if msg: sys.stderr.write(msg) _utils.terminate('Program Complete.')
def __terminate__(): _utils.terminate()