示例#1
0
 def test_nodirectory_make_project(self):
     drcty = tempfile.TemporaryDirectory()
     drcty.cleanup()
     self.assertFalse(os.path.isdir(drcty.name))
     path, proj = make_project(drcty.name)
     self.assertTrue(os.path.isdir(drcty.name))
     self.assertEqual(drcty.name, path.root)
示例#2
0
 def test_nodirectory_project_found(self):
     drcty = tempfile.TemporaryDirectory()
     drcty.cleanup()
     self.assertFalse(os.path.isdir(drcty.name))
     locn, proj = make_project(drcty.name)
     path, rv = find_project(drcty.name)
     self.assertEqual(locn.root, path.root)
     self.assertEqual(locn.project, path.project)
示例#3
0
    def test_find_most_recently_modified_project(self):
        assets = [make_project(self.drcty.name)]
        time.sleep(1)
        assets.append(make_project(self.drcty.name))

        path, proj = find_project(self.drcty.name)
        self.assertEqual(assets[1][0], path)

        # Modify first project
        time.sleep(1)
        fP = os.path.join(*(i for i in assets[0][0] if i is not None))
        with open(fP, "r") as data:
            text = data.read()
            with open(fP, "w") as output:
                output.write(text)
                output.flush()

        path, proj = find_project(self.drcty.name)
        self.assertEqual(assets[0][0], path)
示例#4
0
文件: main.py 项目: UKCloud/maloja
def main(args):

    log = logging.getLogger("maloja")
    log.setLevel(args.log_level)

    formatter = logging.Formatter(
        "%(asctime)s %(levelname)-7s %(name)s|%(message)s")
    ch = logging.StreamHandler()

    if args.log_path is None:
        ch.setLevel(args.log_level)
    else:
        fh = WatchedFileHandler(args.log_path)
        fh.setLevel(args.log_level)
        fh.setFormatter(formatter)
        log.addHandler(fh)
        ch.setLevel(logging.WARNING)

    ch.setFormatter(formatter)
    log.addHandler(ch)

    asyncio = None  # TODO: Tox testing
    try:
        loop = asyncio.SelectorEventLoop()
        asyncio.set_event_loop(loop)
        operations = asyncio.Queue(loop=loop)
        results = asyncio.Queue(loop=loop)
    except AttributeError:
        loop = None
        operations = queue.Queue()
        results = queue.Queue()

    os.makedirs(args.output, exist_ok=True)

    try:
        path, proj = find_project(args.output)
        log.info("Using project {0}.".format(path.project))
    except StopIteration:
        log.info("No projects detected.")
        path, proj = make_project(args.output)
        log.info("Created {0}.".format(path.project))

    maloja.broker.handler.register(
        Survey, maloja.surveyor.Surveyor.survey_handler
    )
    maloja.broker.handler.register(
        Design, maloja.builder.Builder.design_handler
    )
    maloja.broker.handler.register(
        Inspection, maloja.inspector.Inspector.inspection_handler
    )


    args.url = args.url.rstrip(" /")

    if not args.command:
        console = maloja.console.create_console(operations, results, args, path, loop=loop)
        results = [
            i.result()
            for i in concurrent.futures.as_completed(set(console.tasks.values()))
            if i.done()
        ]
        return 0

    elif args.command == "plan":
        with open(args.input, "r") as data:
            return maloja.planner.report(data)

    # Other commands require a broker
    broker = maloja.broker.create_broker(operations, results, max_workers=64, loop=loop)

    reply = None
    while not isinstance(reply, Token):
        password = getpass.getpass(prompt="Enter your API password: "******"survey":
        operations.put((1, Survey(path)))

    elif args.command == "build":
        objs = []
        with open(args.input, "r") as data:
            objs = list(maloja.planner.read_objects(data.read()))
            objs = maloja.planner.check_objects(objs)

        if not objs:
            log.warning("Design failed object check. Please wait...")
        else:
            operations.put((1, Design(objs)))

    elif args.command == "inspect":
        objs = []
        with open(args.input, "r") as data:
            objs = list(maloja.planner.read_objects(data.read()))
            objs = maloja.planner.check_objects(objs)

        operations.put((1, Inspection(args.name, objs)))

    while not isinstance(reply, Stop):
        try:
            status, reply = results.get(block=True, timeout=30)
        except queue.Empty:
            break
        else:
            if isinstance(status, Status):
                level = os.path.splitext(getattr(status.path, "file", ""))[0]
                log.info("{0:^10} update {1.job:04}".format(level, status))
            if reply is not None:
                log.info(reply)
            time.sleep(0)

    operations.put((2, Stop()))
    time.sleep(1)

    done, not_done = tasks = concurrent.futures.wait(
        set(broker.tasks.values()), timeout=6,
        return_when=concurrent.futures.FIRST_EXCEPTION
    )
    for task in not_done:
        log.warning("Not completed: {0}".format(task))
        log.debug(task.cancel())
    return 0
示例#5
0
 def test_project_version_miss(self):
     path, proj = make_project(self.drcty.name)
     self.assertRaises(
         StopIteration, find_project, self.drcty.name, Project(version="0.0.0")
     )
示例#6
0
 def test_project_has_version(self):
     path, proj = make_project(self.drcty.name)
     self.assertTrue(hasattr(proj, "version"))
     self.assertTrue(proj.version)