Exemplo n.º 1
0
    def test_launcher(self):
        launcher.main(launch=False)

        try:
            raise Exception("test")
        except Exception:
            launcher.exc_already_reported(traceback.format_exc())
Exemplo n.º 2
0
def main():
    launcher.main()
    if len(sys.argv) == 1:
        mode = "prompt"
        runPrompt()
    else:
        mode = "profile"
        runFromProfile(sys.argv[1])
Exemplo n.º 3
0
def main():
    launcher.main("now-5m", "now")

    # Difference between 'recv()' and 'recvfrom()'?
    # Buffer size, look at that
    while True:
        data = s.recvfrom(1024)
        # data = s.recv(655565)

        packet = frames.Packet()

        ethernet = frames.Ethernet()
        parser.ethernet_header(data[0][0:14], ethernet)
        packet.layer2 = ethernet

        if int(ethernet.ethertype, 16) == int('0x800', 16):
            ipv4 = frames.IPv4()
            parser.ipv4_header(data[0][14:34], ipv4)
            packet.layer3 = ipv4

            if ipv4.protocol == 1:
                icmp = frames.ICMP()
                parser.icmp_header(data[0][34:42], icmp)
                packet.layer4 = icmp
                packet.label = "ICMP"

            elif ipv4.protocol == 6:
                tcp = frames.TCP()
                parser.tcp_header(data[0][34:54], tcp)
                packet.layer4 = tcp
                packet.label = "TCP"

            elif ipv4.protocol == 17:
                udp = frames.UDP()
                parser.udp_header(data[0][34:42], udp)
                packet.layer4 = udp
                packet.label = "UDP"

            else:
                print("Other protocol:", ipv4.protocol)
                print()

        elif int(ethernet.ethertype, 16) == int('0x86dd', 16):
            print("Name: IPv6")
            print()
        elif int(ethernet.ethertype, 16) == int('0x806', 16):
            arp = frames.ARP()
            parser.arp_header(data[0][14:42], arp)
            packet.layer3 = arp
            packet.label = "ARP"

        else:
            print("Other ethertype:", ethernet.ethertype)
            print()

        #packet.print()
        mysql.insert_sniffer(packet)
Exemplo n.º 4
0
my_signature = 'fi.hacklab.reactorsimulator.simcontrol'
launcher_config = {
    'dbus_default_interface_name': my_signature,
    'dbus_object_path': '/fi/hacklab/reactorsimulator/simcontrol',
    'main_class_name': os.path.basename(__file__).replace('_launcher.py', ''),
    'config_file_path':
    os.path.realpath(__file__).replace('_launcher.py', '.yml'),
}


# Basic pass-through implementation
class my_launcher(launcher.baseclass):
    def __init__(self, mainloop, bus, **kwargs):
        super(my_launcher, self).__init__(mainloop, bus, **kwargs)
        print "launcher initialized as %s:%s with config %s" % (
            self.dbus_interface_name, self.dbus_object_path, repr(self.config))

    @dbus.service.method(my_signature + '.launcher')
    def quit(self):
        launcher.baseclass.quit(self)

    @dbus.service.method(my_signature + '.launcher')
    def reload(self):
        launcher.baseclass.reload(self)
        self.main_instance.config_reloaded()


# Another small bit of boilerplate
if __name__ == '__main__':
    launcher.main(my_launcher, **launcher_config)
# Import the launcher and dbus modules
import launcher,dbus


# Define some values that will be used
my_signature = 'fi.hacklab.reactorsimulator.engine'
launcher_config = {
    'dbus_default_interface_name': my_signature,
    'main_class_name': os.path.basename(__file__).replace('_launcher.py', ''), 
    'config_file_path': os.path.realpath(__file__).replace('_launcher.py', '.yml'),
}

# Basic pass-through implementation
class my_launcher(launcher.baseclass):
    def __init__(self, mainloop, bus, **kwargs):
        super(my_launcher, self).__init__(mainloop, bus, **kwargs)
        print "launcher initialized as %s:%s with config %s" % (self.dbus_interface_name, self.dbus_object_path, repr(self.config))

    @dbus.service.method(my_signature + '.launcher')
    def quit(self):
        launcher.baseclass.quit(self)

    @dbus.service.method(my_signature + '.launcher')
    def reload(self):
        launcher.baseclass.reload(self)
        self.main_instance.config_reloaded()

# Another small bit of boilerplate
if __name__ == '__main__':
    launcher.main(my_launcher, **launcher_config)
Exemplo n.º 6
0
from launcher import main

if __name__ == '__main__':
    main()

Exemplo n.º 7
0
    shutil.copyfile(model+"/"+config.totalfits, config.iraf_input_dir + config.totalfits)
    shutil.copyfile(model+"/"+config.bulgefits, config.iraf_input_dir + config.bulgefits)

    list_of_catalogs = glob.glob(model+"/catalog"+catalog_number+".cat")
    for catalog in list_of_catalogs:
        print catalog
        # Copies the catalog file in the right folder ready for launcher
        shutil.copyfile(catalog, config.main_catalog)

        # correct output directory (depends on the catalog number)
        catalogDirectory = mainDirOutput+"/"+os.path.splitext(os.path.basename(catalog))[0]+'/'
        if os.path.isdir(catalogDirectory):
            shutil.rmtree(catalogDirectory)
        os.mkdir(catalogDirectory)

        error_code = launcher.main()
        if error_code == 0:
            for code in config.filestosave:
                for file in config.filestosave[code]:
                    shutil.copyfile(file, os.path.join(catalogDirectory, os.path.basename(file)))
        else:
            errorMessage = "There was an error running " + error_code + ". Only the files created before "+ error_code+" will be transfered to output."
            errorFile = catalogDirectory+"ERROR_MESSAGE.txt"
            logError = open(errorFile, 'w')
            logError.write(str(datetime.datetime.now())+" -- ")
            logError.write(errorMessage)
            logError.close()
            if error_code == 'ML.f':
                for file in config.filestosave["Ffinder"]:
                    shutil.copyfile(file, os.path.join(catalogDirectory, os.path.basename(file)))
            if error_code == 'prob_bd.f':
Exemplo n.º 8
0
        while running:
            for event in pygame.event.get():
                if event.type == QUIT:
                    running = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_SPACE:
                        pause = not pause
            if not pause:
                self.draw_cell_list(self.cells)
                self.draw_grid()
                pygame.display.flip()
                clock.tick(self.speed)
                self.cells = self.get_next_generation()
        pygame.quit()


if __name__ == '__main__':
    if launcher.main():
        try:
            with open('settings.yml', 'r') as f:
                params = safe_load(f)
                game = GameOfLife(params['width'], params['height'],
                                  params['cell_size'], params['speed'],
                                  params['cell_color'])
                if params['figure']:
                    game.randomize = False
                    game.figure = params['figure']
        except FileNotFoundError:
            game = GameOfLife()
        game.run()
Exemplo n.º 9
0
def main(file):

    packets = []
    total_counter = 0
    counter = 0

    start = time.time()

    # Fix the counters
    # Re-create the table for each reader
    for lenght, timestamp, pkt in rpcap(file):

        if counter == 100000:
            mysql.insert_reader(packets)
            counter = 0
            packets.clear()

        packet = frames.Packet()
        ethernet = frames.Ethernet()
        parser.ethernet_header(pkt[0:14], ethernet)
        packet.layer2 = ethernet

        if int(ethernet.ethertype, 16) == int('0x800', 16):
            ipv4 = frames.IPv4()
            parser.ipv4_header(pkt[14:34], ipv4)
            packet.layer3 = ipv4

            if ipv4.protocol == 1:
                icmp = frames.ICMP()
                parser.icmp_header(pkt[34:42], icmp)
                packet.layer4 = icmp
                packet.label = "ICMP"

            elif ipv4.protocol == 6:
                tcp = frames.TCP()
                parser.tcp_header(pkt[34:54], tcp)
                packet.layer4 = tcp
                packet.label = "TCP"

            elif ipv4.protocol == 17:
                udp = frames.UDP()
                parser.udp_header(pkt[34:42], udp)
                packet.layer4 = udp
                packet.label = "UDP"

            else:
                pass
                #print("Other protocol:", ipv4.protocol)
                #print()

        elif int(ethernet.ethertype, 16) == int('0x86dd', 16):
            pass
            #print("Name: IPv6")
            #print()

        elif int(ethernet.ethertype, 16) == int('0x806', 16):
            arp = frames.ARP()
            parser.arp_header(pkt[14:42], arp)
            packet.layer3 = arp
            packet.label = "ARP"

        else:
            pass
            #print("Other ethertype:", ethernet.ethertype)
            #print()

        #packet.print()
        packet.time = datetime.fromtimestamp(timestamp)
        packets.append(packet)
        counter += 1
        total_counter += 1
        #mysql.insert(packet)
    mysql.insert_reader(packets)

    end = time.time()

    print()
    print("Inserted {PACKETS} in {TIME:.2f} seconds".format(
        PACKETS=total_counter, TIME=(end - start)))
    print()

    start, end = mysql.get_time_range()
    launcher.main(start, end)
Exemplo n.º 10
0
    shutil.copyfile(model+"/"+config.totalfits, config.iraf_input_dir + config.totalfits)
    shutil.copyfile(model+"/"+config.bulgefits, config.iraf_input_dir + config.bulgefits)

    list_of_catalogs = glob.glob(model+"/catalog"+catalog_number+".cat")
    for catalog in list_of_catalogs:
        print catalog
        # Copies the catalog file in the right folder ready for launcher
        shutil.copyfile(catalog, config.main_catalog)

        # correct output directory (depends on the catalog number)
        catalogDirectory = mainDirOutput+"/"+os.path.splitext(os.path.basename(catalog))[0]+'/'
        if os.path.isdir(catalogDirectory):
            shutil.rmtree(catalogDirectory)
        os.mkdir(catalogDirectory)

        error_code = launcher.main(use_hdu, model)
        if error_code == 0:
            for code in config.filestosave:
                for file in config.filestosave[code]:
                    shutil.copyfile(file, os.path.join(catalogDirectory, os.path.basename(file)))
        else:
            errorMessage = "There was an error running " + error_code + ". Only the files created before "+ error_code+" will be transfered to output."
            errorFile = catalogDirectory+"ERROR_MESSAGE.txt"
            logError = open(errorFile, 'w')
            logError.write(str(datetime.datetime.now())+" -- ")
            logError.write(errorMessage)
            logError.close()
            if error_code == 'ML.f':
                for file in config.filestosave["Ffinder"]:
                    shutil.copyfile(file, os.path.join(catalogDirectory, os.path.basename(file)))
            if error_code == 'prob_bd.f':
Exemplo n.º 11
0
    def test_preferences_only_selected_with_keyboard(self, prefs_mock):
        """
        The user launches the plugin, then uses only the keyboard
        to modify some preferences and proceed with the execution:
        - Shift+Tab, then Return to open the Preferences dialog;
        - Shift+Tab, then Space to check the parse only selected files checkbutton;
        - Tab, Space, Arrow Down, Space to select the first two files in the list;
        - Shift+Tab twice, then Return to save preferences and close the dialog;
        - Tab twice, then Return to proceed with the epub parsing;
        - Return to proceed with the deletion of selected ids and classes from the epub
          and exit the plugin successfully.
        """
        self.create_sigil_cfg()
        utils.SCRIPT_DIR = self.root_path
        plugin.run = self.plugin_run
        # patching launcher.SavedStream mocks away sys.stdout and sys.stderr
        old_stdout = sys.stdout
        old_stderr = sys.stderr
        with patch('launcher.SavedStream'
                   ):  #, patch('plugin.run', side_effect=self.plugin_run):
            launcher.main([
                '', self.ebook_root, self.output_dir.name, self.script_type,
                self.script_target
            ])
        sys.stdout = old_stdout
        sys.stderr = old_stderr
        window = FunctionalTest.test_main_window
        window.pump_events()
        time.sleep(0.2)
        self.assertEqual(window.focus_get(), window.start_button)
        window.event_generate('<Shift-Tab>')
        time.sleep(0.1)
        window.event_generate('<Shift-Tab>')
        window.pump_events()
        self.assertEqual(window.focus_get(), window.prefs_button)
        time.sleep(0.1)

        # events inside Preferences dialog
        window.after(100, lambda: window.event_generate('<Tab>'))
        window.after(200, lambda: window.event_generate('<space>'))
        window.after(300, lambda: window.event_generate('<Tab>'))
        window.after(400, lambda: window.event_generate('<space>'))
        window.after(500, lambda: window.event_generate('<KeyPress-Down>'))
        window.after(600, lambda: window.event_generate('<space>'))
        window.after(700, lambda: window.event_generate('<Shift-Tab>'))
        window.after(800, lambda: window.event_generate('<Shift-Tab>'))
        window.after(900, lambda: window.event_generate('<Return>'))
        # window.after(1000, lambda: self.get_prefs_dlg(window).event_generate('<Return>'))
        window.event_generate(
            '<Return>'
        )  # this opens the Preferences dialog, execution stops until dlg is closed

        window.pump_events()
        self.assertTrue(window.warning_text.get().startswith('Only selected'))
        window.prefs_button.focus_force(
        )  # why during tests the focus doesn't automatically return to prefs_button?
        self.assertEqual(window.focus_get(), window.prefs_button)
        time.sleep(0.1)
        window.event_generate('<Tab>')
        window.event_generate('<Tab>')
        self.assertEqual(window.focus_get(), window.start_button)
        self.assertEqual(window.check_undefined_attributes['classes'], {})
        self.assertEqual(window.check_undefined_attributes['ids'], {})
        window.event_generate('<Return>')
        window.pump_events()
        time.sleep(0.1)
        self.assertTrue(
            'SectionNumber' in window.check_undefined_attributes['classes'])
        self.assertTrue(
            'Indicegenerale1' in window.check_undefined_attributes['ids'])
        window.event_generate('<Shift-Tab>')
        self.assertEqual(window.focus_get(), window.stop_button)
        time.sleep(0.1)
        window.event_generate('<Tab>')
        self.assertEqual(window.focus_get(), window.start_button)
        window.pump_events()
        window.event_generate('<Return>')
        window.pump_events()
        self.assertTrue(window.success)
        self.assertFalse(window.is_running)
Exemplo n.º 12
0
    #'main_class': 'excel.Excel_settings'
}

### compile parts
def build(self):
    files_path = os.path.join('src', 'main')
    main_class = self.main_class.replace('.', os.sep) + '.java'

    cmd = '{0} -d bin -sourcepath {1} -cp "lib/poi-3.11/*" {2} {3}'.format(
            self.compilo, files_path,
            os.path.join(files_path, main_class), self.flags)

    subprocess.call(cmd, shell=True)


### run parts
def run(self, *args):
    subprocess.call('java -cp "lib/poi-3.11/*:bin" {0} {1}'.format(self.main_class, ' '.join(args)),
                        shell=True)


def clean(self):
    """clean the java project"""

    self._clean(os.path.join('bin', '*'),
                os.path.join('tree', '*'))

    self._clean_rec('*~')

launcher.main()
Exemplo n.º 13
0
# if (mealie_path):
#     sys.path.append(mealie_path)
# else:
#     print("ERROR: Environment variable \"MEALIE_PATH\" is not defined")
#     sys.exit(2)

try:
    from launcher import main
except ImportError:
    print("ERROR: Cannot import base.launcher. Is your \"MEALIE_PATH\" set correctly?")
    sys.exit(2)

from entities.assetspecs import asp_handler
from entities.assets import ass_handler
from entities.locations import loc_handler

action_handler = {
    "ASP": asp_handler,
    "ASS": ass_handler,
    "COM": com_handler,
    "ICG": icg_handler,
    "LOC": loc_handler,
    "UND": und_handler,
    "UOM": uom_handler
}

if __name__ == "__main__":
    er = main(sys.argv[1:])                # Pass all args except name of program
    action_handler.get(er.entity_type)(er) # Call the appropriate handler for the entity