コード例 #1
0
ファイル: dictutils.py プロジェクト: raychorn/chrome_gui
def walk(top, options=DictWalkOptions.values_only):
    from vyperlogix import misc
    try:
        __stack__ = []
        options = options if ((options) and
                              (options.value)) else DictWalkOptions.values_only
        while (1):
            top = [top] if (not misc.isIterable(top)) else [top] if (
                misc.isDict(top)) else top
            for t in top:
                for k, v in t.iteritems():
                    __is__ = misc.isDict(v) or misc.isHashedDict(v[0] if (
                        misc.isIterable(v)) else v)
                    if (__is__):
                        __stack__.append(v)
                    if (options) and (options.value):
                        if (options.value
                                & DictWalkOptions.keys_and_values.value):
                            yield (k, v)
                        elif (options.value & DictWalkOptions.keys_only.value):
                            yield k if (__is__) else v
                        elif (options.value
                              & DictWalkOptions.values_only.value):
                            if (__is__):
                                continue
                            else:
                                yield v
                    else:
                        yield k if (misc.isDict(v)) else v
            top = __stack__.pop() if (len(__stack__) > 0) else None
            if (not top):
                raise StopIteration
    except:
        raise StopIteration
    raise StopIteration
コード例 #2
0
ファイル: django_utils.py プロジェクト: raychorn/chrome_gui
 def handle_key_and_value(_so, k, v):
     _reToks = re.compile(r"\[(?P<t>[a-z]*)\]*")
     _regEx = r"(?P<name>[a-z]*)"
     toks = _reToks.findall(k)
     for i in xrange(0, len(toks)):
         _regEx += r"\[(?P<t%d>[a-z]*)\]" % (i + 1)
     _re = re.compile(_regEx)
     matches = _re.findall(k)
     if (len(matches) > 0):
         _root = so
         _matches = []
         if (misc.isList(matches)):
             if (misc.isList(matches[0])):
                 for item in matches[0]:
                     _matches.append(item)
             elif (misc.isIterable(matches[0])):
                 for item in list(matches[0]):
                     _matches.append(item)
             else:
                 for item in matches:
                     _matches.append(item)
         _matches = [m for m in _matches if (len(m) > 0)]
         if (len(_matches) > 1):
             for n in _matches[0:-1] if (len(_matches) > 1) else _matches:
                 if (not _root[n]):
                     _root[n] = SmartFuzzyObject()
                 _root = _root[n]
         n = _matches[-1]
         _root[n] = misc.normalize_as_float(
             get_from_post_or_get(request, k, -1))
     else:
         so[k] = misc.normalize_as_float(
             get_from_post_or_get(request, k, -1))
コード例 #3
0
    def __callback2__(*args, **kwargs):
	__re1__ = re.compile("@@@delete=(?P<filename>.*)@@@", re.DOTALL | re.MULTILINE)
	data = args[0] if (misc.isIterable(args) and (len(args) > 0)) else args
	matches1 = __re1__.search(data)
	if (matches1):
	    f = matches1.groupdict().get('filename',None)
	    if (f):
		fpath = os.sep.join([__ipath__,f])
		if (os.path.exists(fpath) and os.path.isfile(fpath)):
		    print 'INFO: Removing "%s".' % (fpath)
		    os.remove(fpath)
	print 'DEBUG.%s: args=%s, kwargs=%s' % (misc.funcName(),args,kwargs)
	return None
コード例 #4
0
	logger.info('REMOTE DEBUGGER:')
	sftp = __sftp__()
	cmd = 'find / -iname wrapper.conf | grep %s' % (__dest__)
	responses = sftp.exec_command(cmd)
	logger.info(cmd)
	logger.info('\n'.join(responses))
	lines = [l for l in responses if (len(l.strip()) > 0)]
	if (len(lines) == 0) or (len(lines) >= 2):
	    logger.warning('Cannot proceed without a valid destination which should be something like "collector/wrapper.conf" as the -d or --dest argument on the command line.  Either the IP Address is not for the Analytics VM or the ANalytics VM has become corrupted.')
	else:
	    fname = lines[0]
	    logger.info('Using "%s" for the wrapper.conf file.' % (fname))
	    sftp = __sftp__()
	    cmd = 'cat %s' % (fname)
	    responses = sftp.exec_command(cmd)
	    lines = responses[0].split('\n') if (misc.isIterable(responses)) else responses.split('\n')
	    lines = [l.strip() for l in lines if (len(l.strip()) > 0)]
	    errors = [l.strip() for l in lines if (l.strip().find('No such file or directory') > -1)]
	    logger.info(cmd)
	    logger.info('\n'.join(responses))
	    if (len(errors) > 0):
		logger.warning('Cannot proceed without a valid wrapper.conf file for the collector.')
	    else:
		__lines__ = []
		for l in lines:
		    m = __regex_wrapper_conf__.search(l)
		    so = SmartObject(args=m.groupdict() if (m) else {})
		    while (so.variable.startswith('#')):
			if (so.variable.startswith('#')):
			    so.variable = so.variable[1:]
			else:
コード例 #5
0
    def startup(self):
	# When ReverseProxy is used the asyncore.loop() handles this part of the process...
	mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
	if (logger):
	    logger.info('%s.startup() :: self.ipAddr=[%s], self.port=[%s]' % (self.__class__,self.ipAddr,self.port))
	mySocket.bind ( ( self.ipAddr, self.port) )
	mySocket.listen ( 1 )
	channel, details = mySocket.accept()
	if (logger):
	    logger.info('(%s) Opened a connection with "%s".' % (self.port,details))
	__data__ = ''
	__filename__ = None
	__fOut__ = None
	__chunk_count__ = 0
	__re1__ = re.compile("@@@filename=(?P<filename>.*)@@@", re.DOTALL | re.MULTILINE)
	__re2__ = re.compile("@@@address=(?P<address>.*)@@@", re.DOTALL | re.MULTILINE)
	while True:
	    try:
		data = channel.recv(8192)
		if (data) and (len(data) > 0):
		    for ch in data:
			if (not __filename__) and (ord(ch) == 0):
			    if (__data__) and (misc.isString(__data__)) and (len(__data__) > 0) and (callable(self.callback)):
				self.__handler__(__data__)
			    __data__ = ''
			else:
			    __data__ += ch
			    matches1 = __re1__.search(__data__)
			    matches2 = __re2__.search(__data__)
			    if (matches1):
				f = matches1.groupdict().get('filename',None)
				if (f):
				    __filename__ = f
				    dirname = os.path.dirname(__filename__)
				    if (callable(self.callback)):
					dirname2 = self.__handler__(dirname)
					if (misc.isIterable(dirname2) and (len(dirname2) > 0)):
					    dirname2 = dirname2[0]
					if (dirname != dirname2):
					    __filename__ = __filename__.replace(dirname,dirname2)
					    dirname = dirname2
				    if (not os.path.exists(dirname)):
					os.makedirs(dirname)
				    __fOut__ = open(__filename__,'wb')
				    __data__ = ''
			    elif (matches2):
				f = matches2.groupdict().get('address',None)
				if (f):
				    self.address = f
				    if (logger):
					logger.debug('Address is "%s".' % (self.address))
				    __data__ = ''
			    else:
				i = __data__.find(self.eof)
				if (__filename__) and (i > -1):
				    __data__ = [ch for ch in __data__]
				    del __data__[i:]
				    __data__ = ''.join(__data__)
				    __fOut__.write(__data__)
				    __fOut__.flush()
				    __fOut__.close()
				    if (callable(self.callback)):
					self.__handler__(__filename__)
				    if (_utils.is_valid_ip_and_port(self.address)):
					connect_to_ip,connect_to_port = parse_ip_address_and_port(self.address, default_ip='0.0.0.0', default_port=51555)
					__writer__ = SocketWriter(connect_to_ip, connect_to_port,retry=True)
					__writer__.send('@@@delete=%s@@@' % (os.path.basename(__filename__)))
					__writer__.close()
				    __filename__ = None
				    __fOut__ = None
				    __data__ = ''
		    if (__filename__):
			__chunk_count__ += 1
			if (logger):
			    logger.debug('DEBUG: writing (%s bytes) x (%s) --> "%s"' % (len(__data__),__chunk_count__,__fOut__.name))
			__fOut__.write(__data__)
			__data__ = ''
	    except socket.error:
		mySocket.close()
		mySocket = socket.socket ( socket.AF_INET, socket.SOCK_STREAM )
		if (logger):
		    logger.info('%s.reconnect() :: self.ipAddr=[%s], self.port=[%s]' % (self.__class__,self.ipAddr,self.port))
		mySocket.bind ( ( self.ipAddr, self.port) )
		mySocket.listen ( 1 )
		channel, details = mySocket.accept()
		if (logger):
		    logger.info('(%s) Reopened a connection with "%s".' % (self.port,details))
		__data__ = ''
		__filename__ = None
		__fOut__ = None
		__chunk_count__ = 0
	    except Exception, details:
		info_string = _utils.formattedException(details=details)
		if (logger):
		    logger.exception('EXCEPTION: %s\n%s' % (details,info_string))
コード例 #6
0
def reportTheList(l, title, callback=None, asCSV=False, fOut=sys.stdout):
    '''Report the List using a callback or asCSV or the default str(item) method.'''
    from vyperlogix.hash import lists
    from vyperlogix.parsers import CSV
    from vyperlogix import misc
    from vyperlogix.misc import ObjectTypeName

    print >> fOut, 'BEGIN: %s num=(%s)' % (title, len(l))
    i = 1
    if (misc.isIterable(l)) or (misc.isList(l)):
        for item in l:
            if (isinstance(item, tuple)):
                item = list(item)
            if (isinstance(item, list)):
                if (lists.isDict(item[0])):
                    lists.prettyPrint(item[0],
                                      title='%d :: %s' % (i, title),
                                      asCSV=asCSV,
                                      fOut=fOut)
                    i += 1
                else:
                    isHandled = False
                    if (callable(callback)):
                        try:
                            print >> fOut, '\t%s' % (callback(item[0]))
                            isHandled = True
                        except:
                            pass
                    if (not isHandled):
                        if (asCSV):
                            print >> fOut, '%s' % (CSV.asCSV(item))
                        else:
                            print >> fOut, '\t%s' % (item[0])
                    i += 1
                for _item in item[1:]:
                    if (misc.isList(_item)):
                        for __item in _item:
                            if (lists.isDict(__item)):
                                lists.prettyPrint(__item,
                                                  title='%d :: %s' %
                                                  (i, title),
                                                  asCSV=asCSV,
                                                  fOut=fOut)
                                i += 1
                            else:
                                isHandled = False
                                if (callable(callback)):
                                    try:
                                        print >> fOut, '\t\t%d :: %s' % (
                                            ii, callback(__item))
                                        isHandled = True
                                    except:
                                        pass
                                if (not isHandled):
                                    if (asCSV):
                                        print >> fOut, '"%d","%s"' % (ii,
                                                                      __item)
                                    else:
                                        print >> fOut, '\t\t%d :: %s' % (
                                            ii, __item)
                                i += 1
                    else:
                        if (lists.isDict(_item)):
                            lists.prettyPrint(_item,
                                              title='%d :: %s' % (i, title),
                                              asCSV=asCSV,
                                              fOut=fOut)
                            i += 1
                        else:
                            isHandled = False
                            if (callable(callback)):
                                try:
                                    print >> fOut, '\t\t%s' % (
                                        callback(__item))
                                    isHandled = True
                                except:
                                    pass
                            if (not isHandled):
                                if (asCSV):
                                    print >> fOut, '"%s"' % (_item)
                                else:
                                    print >> fOut, '\t\t%s' % (_item)
                            i += 1
            else:
                if (lists.isDict(item)):
                    lists.prettyPrint(item,
                                      title='%d :: %s' % (i, title),
                                      asCSV=asCSV,
                                      fOut=fOut)
                    i += 1
                else:
                    isHandled = False
                    if (callable(callback)):
                        try:
                            print >> fOut, '\t%d :: %s' % (i, callback(item))
                            isHandled = True
                        except:
                            pass
                    if (not isHandled):
                        if (asCSV):
                            print >> fOut, '"%d","%s"' % (i, item)
                        else:
                            print >> fOut, '\t%d :: %s' % (i, item)
                    i += 1
    else:
        print >> fOut, 'NOTHING TO REPORT, List is EMPTY or not an interable; just for the record type "%s" is not iterable.' % (
            ObjectTypeName.typeClassName(l))
    print >> fOut, 'END! %s' % (title)
コード例 #7
0
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !

USE AT YOUR OWN RISK.
"""
import logging

import urllib2

import simplejson

from vyperlogix import misc
from vyperlogix.misc import _utils
from vyperlogix.classes import MagicObject

arg0 = lambda args: args[0] if (misc.isIterable(args)) and (len(
    args) > 0) and (misc.isString(args[0])) else None
list0 = lambda args: args[0] if (misc.isIterable(args)) and (len(
    args) > 0) and ((misc.isList(args[0])) or (misc.isDict(args[0]))) else []
int0 = lambda args: args[0] if (misc.isIterable(args)) and (len(
    args) > 0) and (misc.isInteger(args[0])) else None
bool0 = lambda args: args[0] if (misc.isIterable(args)) and (len(
    args) > 0) and (misc.isBooleanString(args[0])) else None

__only__ = lambda value, target: value if (str(value).lower().capitalize(
) == str(target).lower().capitalize()) else None


class SleepyMongoose(MagicObject.MagicObject2):
    def __init__(self, sleepy_mongoose):
        '''