Beispiel #1
0
def update():
    ori_ip = get_ip()

    manager = Manager()
    manager.load_all()
    datas = []
    for item in manager.mods:
        proxy = item.__all__()
        data = proxy.get_data()
        for one in data:
            res = check_ip_available(ori_ip, one[0], one[1])
            if res != False:
                one.append(res)
                one.append(proxy.plugin_name)
                datas.append(one)
    return datas
Beispiel #2
0
def install_lib_classic(obj, libs):
    """Install libraries."""
    if not obj.is_classic:
        raise RuntimeError('Cannot manage classic libs in retail game folder')
    obj.manager_lib_classic.install(libs)
    obj.manager_lib_classic.export()
    Manager().process_libs()
Beispiel #3
0
def checkSerials():
    """
    check all serials in all nodes on all clusters,
    compare the serials in quattor with the real serials reported by the machines
    """
    #set options
    opts = options() #default options object
    opts.all_nodes = True
    opts.verbose= 0
    opts.forced = True
    opts.runcmd = "dmidecode -s system-serial-number"

    for cluster in CLUSTERS:
        opts.cluster = cluster

        #create manager
        manager = Manager(opts)

        #get serials from quattor
        serials = {}
        for  node in manager.nodes.getNodes():
            serials[node.nodeid] = node._getQuattorElement(SERIAL_XPATH)
        print serials

        #get serials from nodes
        out = manager.doit()

        #parse output and compare
        for nodeout in out:
            if not isinstance(nodeout[0],Node):
                continue #skip monitoring etc...

            node = nodeout[0].nodeid
            if nodeout[1] and len(nodeout[1]) > 0 and len(nodeout[1][0]) > 1:
                serial = nodeout[1][0][1][0]
                if nodeout[1][0][1][1]:
                    print "error checking %s: %s"%(node,nodeout[1][0][1][1])
            else:
                serial = None

            try:
                if serials[node] != serial:
                    print "serial for %s is incorrect in quattor:%s, reported by machine: %s"%(node,serials[node],serial)
                #print node,serial,serials[node]
            except (KeyError,AttributeError):
                pass #master or icinga gets added my manager, ignore this.
Beispiel #4
0

def test_drop():
    print("Dropping table", table_test)
    database.actions.drop(table_test)

    with ENGINE.connect():
        table = Table(table_test, META, autoload=True, autoload_with=ENGINE)
        if not table.exists(bind=None):
            print('TABLE DROP SUCCESS!')
        else:
            print(
                "Something went wrong. Please rerun in DEBUG mod. DROP FAILED")


manager = Manager()


@manager.command()
def test_all():
    test_creation()
    test_insert()
    test_remap_without_changes()
    os.execl(sys.executable, 'python', '-m', 'tests.database_test',
             'remap_all')


@manager.command()
def remap_all():
    test_remap_with_all_changes()
    os.execl(sys.executable, 'python', '-m', 'tests.database_test',
Beispiel #5
0
def main():
    camera = cv2.VideoCapture(
        path.join(path.dirname(__file__), "samples/traffic.flv"))
    # camera = cv2.VideoCapture(path.join(path.dirname(__file__), "samples/human.avi"))
    # camera = cv2.VideoCapture(0)
    # KNN background subtractor
    bs = cv2.createBackgroundSubtractorKNN()

    # MOG subtractor
    # bs = cv2.bgsegm.createBackgroundSubtractorMOG(history = background_frame)
    # bs.setHistory(history)

    # GMG
    # bs = cv2.bgsegm.createBackgroundSubtractorGMG(initializationFrames = history)

    cv2.namedWindow("视窗")
    human_manager = Manager()
    frames = 0

    while True:
        print(" -------------------- FRAME %d --------------------" % frames)
        grabbed, frame = camera.read()
        if (grabbed is False):
            print("failed to grab frame.")
            break

        fgmask = bs.apply(frame)

        # this is just to let the background subtractor build a bit of history
        if frames < background_frame:
            frames += 1
            continue

        th = cv2.threshold(fgmask.copy(), 127, 255, cv2.THRESH_BINARY)[1]
        th = cv2.erode(th,
                       cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3)),
                       iterations=2)
        dilated = cv2.dilate(th,
                             cv2.getStructuringElement(cv2.MORPH_ELLIPSE,
                                                       (8, 3)),
                             iterations=2)
        image, contours, _ = cv2.findContours(dilated, cv2.RETR_EXTERNAL,
                                              cv2.CHAIN_APPROX_SIMPLE)

        found_filtered = []
        # 根据面积过滤一次
        for contour in contours:
            area = cv2.contourArea(contour)
            print("面积 %f" % area)
            if area > min_contour_area:
                found_filtered.append(contour)

        # for ridx, o in enumerate(contours):
        #     for qidx, i in enumerate(contours):
        #         # i 在 o 内
        #         if ridx != qidx and is_inside(cv2.boundingRect(o), cv2.boundingRect(i)):
        #             break
        #         else:
        #             found_filtered.append(i)

        detected_objects = []
        for contour in found_filtered:
            draw_person(frame, contour)
            track_window = cv2.boundingRect(contour)
            detected_objects.append(DetectedObject(track_window))

        print("找到 %d 个物体" % len(detected_objects))

        human_manager.process_detect_objs(detected_objects)

        frames += 1

        cv2.putText(frame, "count: %d" % human_manager.get_num(),
                    (int(20), int(20)), font, 1, (255, 255, 0), 1)
        cv2.imshow("surveillance", frame)

        cv2.waitKey(0)  # 暂停

        if cv2.waitKey(110) & 0xff == 27:
            break
    camera.release()
Beispiel #6
0
def install_lib(obj, libs):
    """Install libraries."""
    obj.manager_lib.install(libs)
    obj.manager_lib.export()
    Manager().process_libs()
Beispiel #7
0
def _manage():
    print('Modifying addons to fit each other...')
    Manager().process()
    Manager().process_libs()
    print('Done!')
Beispiel #8
0
	h.update(addr)
	return h.hexdigest()

# returns hash distance from id1 to id2
def id_distance(id1, id2):
	if id1 == id2:
		# special case: if we're the only node, we need to have the distance
		# to our successor be maximum for forwarding to work correctly;
		# so if they're the same, the distance is 2^160
		return 2 ** 160
	l1 = long(id1, 16)
	l2 = long(id2, 16)
	if l1 > l2:
		return 2 ** 160 + l2 - l1
	else:
		return l2 - l1

def add_to_id(id, n):
	n = long(n)
	id = long(id, 16)
	sum = (id + n) & (2**160 - 1)
	return '%040x' % (id + n)

if __name__ == '__main__':
	if len(sys.argv) != 3:
		sys.exit("Usage: %s myhost server" % sys.argv[0])
	host = sys.argv[1]
	server = sys.argv[2]
	m = Manager(Main(), host, server)
	m.run()
Beispiel #9
0
    netG = Generator()
    netD = Discriminator()
    netG.to(device)
    netD.to(device)

    # optimizer
    optimizerG = Adam(netG.parameters(), lr=0.0002, betas=(0.5, 0.999))
    optimizerD = Adam(netD.parameters(), lr=0.0002, betas=(0.5, 0.999))
    schedulerG = lr_scheduler.ExponentialLR(optimizerG, gamma=0.9)
    schedulerD = lr_scheduler.ExponentialLR(optimizerD, gamma=0.9)
    
    # criterion
    criterion = torch.nn.BCELoss()

    # manager
    manager = Manager(netG, netD, optimizerG, optimizerD, criterion, device)

    # generate
    generated_save_path = './generated'
    num_generated_image = 5

    # epochs
    epochs = 500

    # load
    start_epoch = 1
    if os.path.exists('./log/lastest_checkpoint.log'):
        lastest_checkpoint = torch.load('./log/lastest_checkpoint.log')
        lastest_saved_epoch = lastest_checkpoint['epoch']
        netG.load_state_dict(torch.load('./log/G-weight-{:0>8}.log'.format(lastest_saved_epoch)))
        netD.load_state_dict(torch.load('./log/D-weight-{:0>8}.log'.format(lastest_saved_epoch)))
Beispiel #10
0
 def test_merge_namespace(self):
     new_manager = Manager()
     new_manager.add_command(Command(name='new_command'))
     manager.merge(new_manager, namespace='new_namespace')
     self.assertIn('new_namespace.new_command', manager.commands)
Beispiel #11
0
# -*- coding: utf-8 -*-
import sys
import unittest

from StringIO import StringIO

from manage import Arg, Command, Manager


manager = Manager()


class capture(object):
    """Captures the std output.
    """
    def __enter__(self):
        self.backup = sys.stdout
        sys.stdout = StringIO()
        return sys.stdout

    def __exit__(self, type, value, traceback):
        sys.stdout = self.backup


class ClassBased(manager.Command):
    def run(self, name, capitalyze=False):
        if capitalyze:
            return name.upper()
        return name