Example #1
0
def execargs():
    if sys.argv[0] == '-h' or sys.argv[0] == '--help' or sys.argv[0] == '/?':
        funcs.help()
    elif sys.argv[0] == '-c':
        database.load()
        for k in database.database.keys():
            print(k)
    elif sys.argv[0] == '-w':
        if not funcs.areUsure():
            print('failed')
        database.database = {}
        database.dump()
        print('\nok\n')
    elif sys.argv[0] == '-a' and len(sys.argv) == 3 and os.path.exists(
            sys.argv[2]):
        database.load()
        with open(sys.argv[2], 'r', encoding='utf-8') as f:
            database.addCountedWords(process.count(f.read()), sys.argv[1])
        database.dump()
        print('\nok\n')
    elif sys.argv[0] == '-p' and len(sys.argv) == 2 and os.path.exists(
            sys.argv[1]):
        database.load()
        scores = process.getscores(sys.argv[1])
        for cat in scores.keys():
            print(f'{cat}\t:\t{scores[cat]}')
Example #2
0
    def dump_compress_database(self):
        dump_file_path = os.path.join(self.current_folder, '%s.dump' % self.project)
        dump(self.project.title, open(dump_file_path, 'w'), self.log)
        self.log.info('Dumped to %s' % get_size(dump_file_path))

        self.log.info('Compressing database')
        dump_tarfile_path = '%s.tar.gz' % dump_file_path
        compress_file(dump_file_path, dump_tarfile_path, self.log)
        os.remove(dump_file_path)
        self.log.info('Compressed to %s' % get_size(dump_tarfile_path))
Example #3
0
def index():
    chinese = {
        '1': '一',
        '2': '二',
        '3': '三',
        '4': '四',
        '5': '五',
        '6': '六',
        '0': '日'
    }
    name = request.args.get('name')
    zimuzu = request.args.get('zimuzu')
    day = request.args.get('day')
    if name != "" and zimuzu != "" and name != None and zimuzu != None:
        database.dump(name, zimuzu, day)
        result = database.load(day)
        return render_template('index.html', result=result)
    else:
        result = []
        for days in range(7):
            result.append("周" + chinese[str(days)])
            result.append(database.load(days))
        return render_template('index.html', result=result)
Example #4
0
def main():
    global changes
    database.load()
    while True:
        funcs.clear()
        funcs.menu()
        ans = input('your choice : ')
        if ans == 'e':
            if changes == '':
                exit()
            q = input(
                'there are some unsaved changes. do you want to save them ??? (y/n)'
            )
            if q == 'n':
                exit()
            elif q == 'y':
                database.dump()
                exit()
        elif ans == 'a':
            pth = input('enter file name to add to database : ')
            with open(pth, 'r', encoding='utf-8') as f:
                cat = input('category name : ')
                database.addCountedWords(process.count(f.read()), cat)
                changes += f'Add {pth} to database[{cat}].\n'
                input(
                    'new file added successfully\npress enter to continue ...')
        elif ans == 'd':
            """if not funcs.areUsure():
                input('press enter to continue ...')
                continue"""
            database.dump()
            changes = ''
            input('ok\npress enter to continue ...')
        elif ans == 'l':
            if changes == '':
                input('no changes detected !!!\npress enter to continue ...')
                continue
            if not funcs.areUsure():
                input('press enter to continue ...')
                continue
            database.load()
            input('ok\npress enter to continue ...')
        elif ans == 'w':
            if not funcs.areUsure():
                input('press enter to continue ...')
                continue
            database.database = {}
            database.dump()
            input('ok\npress enter to continue ...')
        elif ans == 'p':
            pth = input('enter file name : ')
            scores = process.getscores(pth)
            print()
            for cat in scores.keys():
                print(f'{cat}\t:\t{scores[cat]}')
            print()
            input('\npress enter to continue ...')
        elif ans == 'c':
            print()
            for k in database.database.keys():
                print(k)
            input('\npress enter to continue ...')
Example #5
0
                ip = temp[0]
                name = temp[len(temp)-1]
                host_list.append((ip, name))
    return host_list

# Check if a given node is responsive
def ping_node(ip):
    try:
        ping_status = subprocess.check_output("ping -c 1 -W 1.5 " + ip, shell=True).decode("ascii")
        return True
    except Exception as error:
    #    print("QUANAH_IPMI ERROR: Ping encountered exception {%s} for IP %s at time %s." % (error, ip, datetime.datetime.utcnow()))
        return False

# Main
if __name__=="__main__":
    hosts = generateHosts(path_list_of_IPs)
    
    pool = Pool(256)
    results = [pool.apply_async(get_node_data, (host,)) for host in hosts]
    pool.close()
    pool.join()

    success = database.dump('MP_Array', '10.1.6.102', 27017, 'logger', '3mpZjGdS', 'monitoring', 'monitoring', 'IPMI', results)
    if not success: 
        print("QUANAH_IPMI ERROR: Failed to record data at time: %s" % datetime.datetime.utcnow())




Example #6
0
        #receive the request
        request = protocol.receiveJSON(client_sock)
        if (verbose):
            print "Received message:"
            print request
        response = {}  #prepare the response object

        #parse the request
        if ("request" in request):

            #DUMP
            if (request["request"] == "DUMP"):
                if (verbose):
                    print "Received DUMP request"
                #dump the database and send back
                data = database.dump()
                response["response"] = "DATA"
                response["data"] = data
                if (verbose):
                    print "Sending response:"
                    print response

            #QUERY
            elif (request["request"] == "QUERY"):

                #execute the query and send back
                if (not "year" in request):
                    response["response"] = "ERROR"
                    response["error"] = "QUERY requires year parameter"
                    if (verbose):
                        print "Received malformed QUERY: no year"
Example #7
0
        sensor.parseResponse()
        if sensor.parse_success:
            return (True, sensor.record)
    return (False, {})


# Main
if __name__ == "__main__":
    results = []

    result1 = initTempSensorQuery("10.1.18.1")
    if result1[0]:
        results.append(result1[1])
    else:
        print(
            "TEMPSENSOR ERROR: Request to IP 10.1.18.1 failed to query or parse successfully"
        )

    result2 = initTempSensorQuery("10.1.12.1")
    if result2[0]:
        results.append(result2[1])
    else:
        print(
            "TEMPSENSOR ERROR: Request to IP 10.1.12.1 failed to query or parse successfully"
        )

    success = database.dump('Array', '10.1.6.102', 27017, 'logger', '3mpZjGdS',
                            'monitoring', 'test', 'TempSensor', results)
    if not success:
        print("TEMPSENSOR ERROR: See traceback above")
Example #8
0
import os, sys
import argparse 
import database 
import compare 

if __name__ == "__main__" :

  parser = argparse.ArgumentParser(description="This is code sniffer.")
  parser.add_argument('--config', metavar='filepath'
      , default="~/.snifferrc"
      , help = "Path of configuration file."
      )
  args = parser.parse_args()
  configFile = args.config 

  # check if file exists .
  if not os.path.exists(configFile) :
    print("[E] File {0} does not exists".format(configFile))
    sys.exit(0)
  
  # else parse it.
  import ConfigParser as cfg
  config = cfg.ConfigParser()
  config.read(configFile)
  db = database.buildListingDb(config) 
  if config.get("source", "compare") == "true" :
    compare.compare(config, db)
    database.dump(config, db)
  if config.get("source", "analyze_result") == "true" :
    database.writeContent(config, db)
Example #9
0
	def database_dump(self):
		'''Dump parsed data into the appropriate database.'''
		d = database.dump(self.db, self.clean_clips, self.line_ending)
		self.error.append(d)
 def database_dump(self):
     '''Dump parsed data into the appropriate database.'''
     d = database.dump(self.db, self.clean_clips, self.line_ending)
     self.error.append(d)