コード例 #1
0
def test(limit=2):
    global log
    level = log.getEffectiveLevel()
    logger.setLevel('debug')
    ret = pmapLarge(func, range(8), limit)
    logger.setLevel(level)
    return ret
コード例 #2
0
 def getResourceYaml(self):
     logger.setLevel()
     k8s_client = ApiClient().apiclient()  # type: ApiClient
     dyn_client = DynamicClient(k8s_client)
     v1_resources = dyn_client.resources.get(api_version='v1',
                                             kind=self.resource_type)
     resource = v1_resources.get(namespace=self.namespace, name=self.name)
     return resource
コード例 #3
0
 def getResourceName(self):
     logger.setLevel()
     k8s_client = ApiClient().apiclient()  # type: ApiClient
     dyn_client = DynamicClient(k8s_client)
     v1_resources = dyn_client.resources.get(api_version='v1',
                                             kind=self.resource_type)
     resource = v1_resources.get(namespace=self.namespace, name=self.name)
     logging.info('Resource name is ' + resource.metadata.name)
     return resource.metadata.name
コード例 #4
0
 def getPodNamesFromSelectors(self):
     logger.setLevel()
     k8s_client = ApiClient().apiclient()  # type: ApiClient
     dyn_client = DynamicClient(k8s_client)
     v1_resources = dyn_client.resources.get(api_version='v1', kind='Pod')
     resource_list = v1_resources.get(namespace=self.namespace,
                                      label_selector='app=' + self.name)
     listitem = []  # type: List[Any]
     for resource in resource_list.items:
         listitem.append(resource.metadata.name)
     return listitem
コード例 #5
0
 def getResourceNames(self):
     logger.setLevel()
     k8s_client = ApiClient().apiclient()  # type: ApiClient
     dyn_client = DynamicClient(k8s_client)
     v1_resources = dyn_client.resources.get(api_version='v1',
                                             kind=self.resource_type)
     resource_list = v1_resources.get(namespace=self.namespace)
     resdict = []  # type: List[Any]
     for resource in resource_list.items:
         resdict.append(resource.metadata.name)
     return resdict
コード例 #6
0
ファイル: baconian.py プロジェクト: DoomyDwyer/cipher-utils
def main():
	print('Ensure that cipherbin.txt is present in the same directory as baconian.py')
	input('Hit any key to continue...')
	print('Reading in file cipherbin.txt and removing all whitespace characters...')
	import cipher_utils
	cipherbintext = cipher_utils.stripWhitespace(cipher_utils.readFile('cipherbin.txt'))
	logger.setLevel(logger.ERROR)
	logger.debug('%s' % (cipherbintext))
	cipherbinlist = cipherbintext.split(sep='2')
	print(cipherbinlist)
	input('Hit any key to continue...')
	ciphertext = baconianBinToText(cipherbinlist, sep=' ')
	logger.info(ciphertext)
	cipher_utils.writeFile('cipher.txt', ciphertext)
	print('Let\'s perform some frequency analysis on the ciphertext we extracted from the Baconian binary text...')
	input('Hit any key to continue...')
	logger.setLevel(logger.ERROR)
	ciphertext = cipher_utils.stripWhitespace(cipher_utils.readFile('cipher.txt'))
	cipherlist=list(ciphertext)
	freq = cipher_utils.frequencyAnalysis(cipherlist)
	sortedFreq = cipher_utils.sortedFrequency(freq)
	cipher_utils.displayFrequency(sortedFreq)
	print('ioc = %s' % (cipher_utils.ioc(cipherlist)))
	print('Let\'s decrypt the ciphertext using the Simple Substitution Cipher decryption algorithm, with our guessed key...')
	input('Hit any key to continue...')
	ciphertext = cipher_utils.readFile('cipher.txt')
	logger.setLevel(logger.DEBUG)
	plaintext = cipher_utils.decryptSimpleSubstitutionCipher(ciphertext, 'DIJAKLMNFOPQECRSTUVWXYZGBH', dummy='.')
	print(plaintext)
	cipher_utils.writeFile('solution.txt', plaintext)
	logger.setLevel(logger.ERROR)
コード例 #7
0
ファイル: GoogleScraper.py プロジェクト: maxim-k/armif
def setup_logger(level=logging.INFO):
    # First obtain a logger
    logger = logging.getLogger('GoogleScraper')
    logger.setLevel(level)

    ch = logging.StreamHandler(stream=sys.stderr)
    ch.setLevel(level)

    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    # add logger to the modules namespace
    setattr(sys.modules[__name__], 'logger', logger)
コード例 #8
0
    def _createConn(self):
        try:
            System.setProperty("com.couchbase.forceIPv4", "false")
            logger = Logger.getLogger("com.couchbase.client")
            logger.setLevel(Level.SEVERE)
            for h in logger.getParent().getHandlers():
                if isinstance(h, ConsoleHandler):
                    h.setLevel(Level.SEVERE)
#             self.cluster = CouchbaseCluster.create(Java_Connection.env, self.hosts)
            self.cluster = CouchbaseCluster.fromConnectionString(
                Java_Connection.env, self.connection_string)
            self.cluster.authenticate("Administrator", self.password)
            self.cb = self.cluster.openBucket(self.bucket)
        except CouchbaseException:
            self.cluster.disconnect()
            raise
コード例 #9
0
ファイル: config.py プロジェクト: Matthijs990/os-sys-github
 def common_logger_config(self, logger, config, incremental=False):
     """
     Perform configuration which is common to root and non-root loggers.
     """
     level = config.get('level', None)
     if level is not None:
         logger.setLevel(logger._checkLevel(level))
     if not incremental:
         #Remove any existing handlers
         for h in logger.handlers[:]:
             logger.removeHandler(h)
         handlers = config.get('handlers', None)
         if handlers:
             self.add_handlers(logger, handlers)
         filters = config.get('filters', None)
         if filters:
             self.add_filters(logger, filters)
コード例 #10
0
ファイル: cactus.py プロジェクト: jtpverhoeven/cactus
def initLogger(config):

    logger = logging.getLogger('cactus')
    logger.setLevel(logging.DEBUG)

    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)

    fh = logging.FileHandler('runinfo.log', mode='w')
    fh.setLevel(logging.DEBUG)

    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    fh.setFormatter(formatter)

    logger.addHandler(ch)
    logger.addHandler(fh)
コード例 #11
0
def pmap(callable, sequence, limit=NCPU, *args, **kwds):
    """
    A parallel version of the built-in map function with an optional process
    'limit'. The given 'callable' should not be parallel-aware (that is, have a
    'channel' parameter) since it will be wrapped for parallel communications
    before being invoked.

    Return the processed 'sequence' where each element in the sequence is
    processed by a different process.
    """
    global log
    level = log.getEffectiveLevel()
    logger.setLevel('info')

    mymap = MapMoreArgs(limit=limit)
    x = mymap(callable, sequence, *args, **kwds)

    logger.setLevel(level)
    return x
コード例 #12
0
def pmapLarge(consumer, seq, limit=NCPU, processor=None, *args, **kwds):
    """
    feed seq by single CPU and consumed by limit CPUs

    consumer:  function to consume one feed at a time, 1st argument == one feed from seq
    seq:       any sequence or generator/iterator
    args/kwds: for consumer
    processor: function to process arguments value returned from consumer

    return exchange object with data attribute
    """
    global log
    level = log.getEffectiveLevel()
    logger.setLevel('info')

    exchange = makeExchange(limit)
    exchange = parallelFeeder(consumer, seq, exchange, processor, *args,
                              **kwds)

    logger.setLevel(level)
    return exchange.data
コード例 #13
0
async def on_ready():

    await bot.change_presence(status=discord.Status.online,
                              activity=discord.Game('a!'))

    #says who its logged in as and gives logs
    logger = logging.getLogger('discord')
    logger.setLevel(logging.DEBUG)
    handler = logging.FileHandler(filename='discord_alcebot.log',
                                  encoding='utf-8',
                                  mode='w')
    handler.setFormatter(
        logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
    logger.addHandler(handler)

    print('Logged in as')
    print(bot.user.name)
    print(bot.user.id)
    print('valid token')
    print('passcode: ' + str(passcode))
    print('------')
コード例 #14
0
ファイル: config.py プロジェクト: Matthijs990/os-sys-github
def _install_loggers(cp, handlers, disable_existing):
    """Create and install loggers"""

    # configure the root first
    llist = cp["loggers"]["keys"]
    llist = llist.split(",")
    llist = list(_strip_spaces(llist))
    llist.remove("root")
    section = cp["logger_root"]
    root = logger.root
    log = root
    if "level" in section:
        level = section["level"]
        log.setLevel(level)
    for h in root.handlers[:]:
        root.removeHandler(h)
    hlist = section["handlers"]
    if len(hlist):
        hlist = hlist.split(",")
        hlist = _strip_spaces(hlist)
        for hand in hlist:
            log.addHandler(handlers[hand])

    #and now the others...
    #we don't want to lose the existing loggers,
    #since other threads may have pointers to them.
    #existing is set to contain all existing loggers,
    #and as we go through the new configuration we
    #remove any which are configured. At the end,
    #what's left in existing is the set of loggers
    #which were in the previous configuration but
    #which are not in the new configuration.
    existing = list(root.manager.loggerDict.keys())
    #The list needs to be sorted so that we can
    #avoid disabling child loggers of explicitly
    #named loggers. With a sorted list it is easier
    #to find the child loggers.
    existing.sort()
    #We'll keep the list of existing loggers
    #which are children of named loggers here...
    child_loggers = []
    #now set up the new ones...
    for log in llist:
        section = cp["logger_%s" % log]
        qn = section["qualname"]
        propagate = section.getint("propagate", fallback=1)
        logger = logger.getLogger(qn)
        if qn in existing:
            i = existing.index(qn) + 1  # start with the entry after qn
            prefixed = qn + "."
            pflen = len(prefixed)
            num_existing = len(existing)
            while i < num_existing:
                if existing[i][:pflen] == prefixed:
                    child_loggers.append(existing[i])
                i += 1
            existing.remove(qn)
        if "level" in section:
            level = section["level"]
            logger.setLevel(level)
        for h in logger.handlers[:]:
            logger.removeHandler(h)
        logger.propagate = propagate
        logger.disabled = 0
        hlist = section["handlers"]
        if len(hlist):
            hlist = hlist.split(",")
            hlist = _strip_spaces(hlist)
            for hand in hlist:
                logger.addHandler(handlers[hand])

    #Disable any old loggers. There's no point deleting
    #them as other threads may continue to hold references
    #and by disabling them, you stop them doing any logger.
    #However, don't disable children of named loggers, as that's
    #probably not what was intended by the user.
    #for log in existing:
    #    logger = root.manager.loggerDict[log]
    #    if log in child_loggers:
    #        logger.level = logger.NOTSET
    #        logger.handlers = []
    #        logger.propagate = 1
    #    elif disable_existing_loggers:
    #        logger.disabled = 1
    _handle_existing_loggers(existing, child_loggers, disable_existing)
コード例 #15
0
		letter = ordinalToClearLetter(ordinal).upper()
		if letter in charFrequencies:
			F = charFrequencies[letter]
		else:
			F = 0
		iocLetter = (F**2 - F) / (n**2 - n)
		ioc += iocLetter
		logger.debug('%s : %s\t: cumulative: %s' % (letter, iocLetter, ioc))
	return ioc

def displayFrequency(sortedList):
	# Displays the sorted frequency list
	for item in sortedList:
		print('%s : %s' % (item[0], item[1]))

# Always perform a sanity check first on the known example cipher:
print('Checking logic on cipher_utils module...')
logger.setLevel(logger.ERROR)
if integerToChr(7) != 'H':
	print('Error testing integerToChr(cipherInt) method!!! Check your code before continuing...')
	sys.exit()
else:
	print('logic OK.')
logger.setLevel(logger.ERROR)

# if cipher_utils.py is run, instead of being imported as a module,
# call the main() function

if __name__ == '__main__':
	main()
コード例 #16
0
ファイル: bastan.py プロジェクト: enginv71/Web-Services
from sqlalchemy.orm import sessionmaker
from sqlalchemy.exc import SQLAlchemyError

log = logging.getLogger(__name__)

res = Flask(__name__)

res.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
res.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
api = Api(res)
db = SQLAlchemy(res)
parser = reqparse.RequestParser()

logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = logging.FileHandler(
    '/home/stajyer/.virtualenvs/rest/flaskk/deneme.log')
logger.addHandler(handler)


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(50), unique=True, nullable=False)
    email = db.Column(db.String(60), unique=True, nullable=False)
    password = db.Column(db.Integer, unique=True, nullable=False)

    def __repr__(self):
        return '<user %r>' % self.username

    def save(self):
コード例 #17
0
ファイル: hill.py プロジェクト: DoomyDwyer/cipher-utils
def main():
    import cipher_utils
    print(
        'Ensure that plaintext.txt is present in the same directory as hill.py'
    )
    input('Hit any key to continue...')
    print(
        'Reading in file plaintext.txt and removing all whitespace characters...'
    )
    plaintext = cipher_utils.stripWhitespace(
        cipher_utils.readFile('plaintext.txt'))
    logger.setLevel(logger.ERROR)
    logger.debug('%s' % (plaintext))
    plaintextlist = list(plaintext)
    print(plaintext)
    print('Ready to encrypt')
    input('Hit any key to continue...')
    logger.setLevel(logger.ERROR)
    ciphertext = hillCipher(plaintextlist, 'HILL')
    print(ciphertext)
    cipher_utils.writeFile('solution.txt', ciphertext)
    logger.setLevel(logger.ERROR)
    print('Ensure that cipher.txt is present in the same directory as hill.py')
    input('Hit any key to continue...')
    print(
        'Reading in file cipher.txt and removing all whitespace characters...')
    ciphertext = cipher_utils.stripWhitespace(
        cipher_utils.readFile('cipher.txt'))
    logger.setLevel(logger.ERROR)
    logger.debug('%s' % (ciphertext))
    cipherlist = list(ciphertext)
    print(ciphertext)
    print('Ready to decrypt')
    input('Hit any key to continue...')
    logger.setLevel(logger.ERROR)
    plaintext = hillCipher(cipherlist, 'HILL', mode='decrypt')
    print(plaintext)
    cipher_utils.writeFile('solution.txt', plaintext)
    logger.setLevel(logger.ERROR)
コード例 #18
0
TYPEAHEAD_PLAYER_LIMIT = 20
BASE_REGION = 'newjersey'

logging.info('Beginning server...');

# parse config file
config = Config()

mongo_client = MongoClient(host=config.get_mongo_url())
print "parsed config: ", config.get_mongo_url()

# set logger level from config
log_level = config.get_logging_level()
print "log level is set to " + str(log_level)
logger.setLevel(log_level)


app = Flask(__name__)
api = restful.Api(app)


def err(error_message, status_code=400):
    # TODO: log error_message
    abort(status_code, description=error_message)

def log_exception():
    try:
        exc_type, exc_value, exc_tb = sys.exc_info()
        tb = traceback.format_exc()
        logger.error(tb)
コード例 #19
0
"""
Removes old versions of Lambda functions.
"""
import logging
import sys
from pathlib import Path
file = Path(__file__).resolve()
sys.path.append(str(file.parent))
import logger
import boto3

# Initialize log
logger.logger_init()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
logger.propagate = False

try:
    CLIENT = boto3.client('lambda', region_name='eu-west-1')
except Exception as exception:
    logger.error(str(exception), exc_info=True)

# Number of versions to keep
KEEP_LAST = 10


def clean_lambda_versions(event, context):
    """
    List all Lambda functions and call the delete_version function.
    Check if the paginator token exist that's included if more results are available.
コード例 #20
0
ファイル: log.py プロジェクト: Pentatonic/TinyNote
    logging.debug("Test")


if __name__ == "__main__":
    main()


# ===================================================================
""" rotate log, split log files when size limit is reached """

logLevel = logging.DEBUG
lcdLogger = logging.getLogger("lcd")
lcdLogger.setLevel(logLevel)
formatter = logging.Formatter("%(asctime)s-%(name)s-%(levelname)s-%(pathname)s(%(funcName)s): %(message)s")
rfh = logging.handlers.RotatingFileHandler("lcd.log", maxBytes=1024 * 1024, backupCount=2)
rfh.setFormatter(formatter)
lcdLogger.addHandler(rfh)

# ====================================================================
import logger

logger = logging.getLogger("stock")
hdlr = logging.FileHandler("stock.log")
formatter = logging.Formatter("%(asctime)s-%(levelname)s:%(message)s")
hdlr.setFormatter(formatter)
logger.addHandler(hdlr)
logger.setLevel(logging.DEBUG)

logget.debug("123 error")
コード例 #21
0
def main():
    import cipher_utils
    print(
        'Ensure that plaintext.txt is present in the same directory as bifid.py'
    )
    input('Hit any key to continue...')
    print(
        'Reading in file plaintext.txt and removing all whitespace characters...'
    )
    plaintext = cipher_utils.stripWhitespace(
        cipher_utils.readFile('plaintext.txt'))
    logger.setLevel(logger.ERROR)
    print(plaintext)
    print('Ready to encrypt')
    input('Hit any key to continue...')
    logger.setLevel(logger.ERROR)
    ciphertext = encryptBifid(plaintext, 'LIGOABCDEFHKMNPQRSTUVWXYZ', 4)
    print(ciphertext)
    cipher_utils.writeFile('solution.txt', ciphertext)
    logger.setLevel(logger.ERROR)
    print(
        'Ensure that cipher.txt is present in the same directory as bifid.py')
    input('Hit any key to continue...')
    print(
        'Reading in file cipher.txt and removing all whitespace characters...')
    ciphertext = cipher_utils.stripWhitespace(
        cipher_utils.readFile('cipher.txt'))
    logger.setLevel(logger.ERROR)
    print(ciphertext)
    print('Ready to decrypt')
    input('Hit any key to continue...')
    logger.setLevel(logger.ERROR)
    plaintext = decryptBifid(ciphertext, 'LIGOABCDEFHKMNPQRSTUVWXYZ', 4)
    print(plaintext)
    cipher_utils.writeFile('solution.txt', plaintext)
    logger.setLevel(logger.ERROR)
コード例 #22
0
ファイル: cli.py プロジェクト: scarsman/gimel
def cli(debug):
    if debug:
        logger.setLevel(logging.DEBUG)
コード例 #23
0
ファイル: vigenere.py プロジェクト: DoomyDwyer/cipher-utils
def main():
    # When run as a main programme, work through the example at the end of the
    # PDF 'A beginner’s guide to codebreaking', supplied by the
    # University of Southampton (A Vigenere cipher)
    print(
        'Ensure that example.txt is present in the same directory as vigenere.py'
    )
    input('Hit any key to continue...')
    print(
        'Reading in file example.txt and removing all whitespace characters...'
    )
    ciphertext = cipher_utils.stripWhitespace(
        cipher_utils.readFile('example.txt'))
    cipherlist = list(ciphertext)
    print('Performing standard frequency analysis on list:')
    freq = cipher_utils.frequencyAnalysis(cipherlist)
    sortedFreq = cipher_utils.sortedFrequency(freq)
    cipher_utils.displayFrequency(sortedFreq)
    input('Hit any key to continue...')
    print('Turning on debugging (DEBUG Level)...')
    logger.setLevel(logger.DEBUG)
    print(
        'Frequency analysis indicates a polyalphabetic cipher, so let\'s calculate the Index of Coincidence (ioc)'
    )
    print('%s' % (cipher_utils.ioc(cipherlist)))
    input('Hit any key to continue...')
    print('Turning on debugging (INFO Level)...')
    logger.setLevel(logger.INFO)
    print('Now calculate the ioc for all possible subkeys from 1 to 9')
    displayIocTable(cipherlist, 9)
    input('Hit any key to continue...')
    keyLength = 6
    print('Judging from the ioc table, we can guess that the keylength is %s' %
          (keyLength))
    print('Display frequency analysis for the %s subkeys:' % (keyLength))
    displaySubkeyFrequencies(cipherlist, keyLength)
    input('Hit any key to continue...')
    print(
        'Most frequent letters for subkey1=X, subkey2=J, subkey3=H, subkey4=J, subkey5=Y, subkey6=Y'
    )
    print(
        'X=24 : 24-5=19 (S), J=10 : 10-5=5 (E), H=8 : 8-5=3 (C), J=10 : 10-5=5 (E), Y=25 : 25-5=20 (T), Y=25 : 25-5=20 (T)'
    )
    print('Turning on debugging (DEBUG Level)...')
    logger.setLevel(logger.DEBUG)
    print('Attempt to decipher with keyword %s' %
          (deriveVigenereKeyPhrase('XJHJYY')))
    input('Hit any key to continue...')
    solution = decryptVigenere(ciphertext, deriveVigenereKeyPhrase('XJHJYY'))
    print(solution)
    cipher_utils.writeFile('solution.txt', solution)
    print('This doesn\'t appear to be quite right - re-evaluate subkeys 4 & 5')
    print(
        'Using second most frequent letters for subkeys 4 & 5: subkey1=X, subkey2=J, subkey3=H, subkey4=W, subkey5=J, subkey6=Y'
    )
    print(
        'X=24 : 24-5=19 (S), J=10 : 10-5=5 (E), H=8 : 8-5=3 (C), W=23 23-5=18 (R), J=10 : 10-5=5 (E), Y=25 : 25-5=20 (T)'
    )
    print('Attempt to decipher with keyword %s' %
          (deriveVigenereKeyPhrase('XJHWJY')))
    print('Turning off debugging (ERROR Level)...')
    logger.setLevel(logger.ERROR)
    input('Hit any key to continue...')
    solution = decryptVigenere(ciphertext, deriveVigenereKeyPhrase('XJHWJY'))
    print(solution)
    cipher_utils.writeFile('solution.txt', solution)
    logger.setLevel(logger.ERROR)