Example #1
0
def run(slug):
    folder = Folder(slug)
    print('Congratulation!!!')
    print('You have new mission created with slug {}'.format(slug))
    print('In the folder {} you find all files that explains what this mission about'
          .format(os.path.join(folder.mission_folder(), 'info')))
    print('Change initial user code in folder {}'
          .format(os.path.join(folder.mission_folder(), 'initial')))
Example #2
0
def run(slug):
    folder = Folder(slug)
    print('Congratulation!!!')
    print('You have new mission created with slug {}'.format(slug))
    print(
        'In the folder {} you find all files that explains what this mission about'
        .format(os.path.join(folder.mission_folder(), 'info')))
    print('Change initial user code in folder {}'.format(
        os.path.join(folder.mission_folder(), 'initial')))
Example #3
0
def use(parser):
    mission_slug = sys.argv[2]
    folder = Folder(mission_slug)
    os.system('cd {mission_path}; git {command}'.format(
        mission_path=folder.mission_folder(),
        command=' '.join(sys.argv[3:])
    ))
Example #4
0
def make_mission_from_template(mission, template, force_remove=False):
    template_full_path = None
    for template_folder in settings.TEMPLATES_FOLDERS:
        template_full_path = os.path.join(template_folder, template)
        if os.path.exists(template_full_path):
            break
        else:
            template_full_path = None

    if template_full_path is None:
        raise TemplateWasntFound(template, settings.TEMPLATES_FOLDERS)

    folder = Folder(mission)
    mission_folder = folder.mission_folder()
    if os.path.exists(mission_folder):
        if force_remove:
            shutil.rmtree(mission_folder)
        else:
            raise MissionFolderExistsAlready(mission_folder)

    os.mkdir(mission_folder)

    from distutils.dir_util import copy_tree
    copy_tree(os.path.join(template_full_path, 'source'), mission_folder)

    GG = {}
    exec(open(os.path.join(template_full_path, 'run.py')).read(), GG)
    GG['run'](mission)

    folder.mission_config_write({
        'type': 'local',
        'url': mission_folder
    })
Example #5
0
def mission_git_getter(url, slug):
    # TODO: checkout into mission solder
    # compile it
    # build docker
    # prepare cli interface
    folder = Folder(slug)
    destination_path = folder.mission_folder()

    logging.info('Getting a new mission through the git...')
    logging.info('from %s to %s', url, destination_path)

    if os.path.exists(destination_path):
        answer = raw_input(
            'Folder {} exists already.'
            ' Do you want to overwite it? [y]/n :'.format(destination_path))
        if answer is '' or answer.lower().startswith('y'):
            shutil.rmtree(destination_path)
        else:
            return

    re_ret = re.search(RE_REPO_BRANCH, url)
    if re_ret:
        checkout_url, branch = re_ret.groups()
    else:
        checkout_url = url
        branch = 'master'

    logging.debug('URL info: checkioout url:%s branch:%s', url, branch)

    try:
        git.Repo.clone_from(checkout_url, destination_path, branch=branch)
    except git.GitCommandError as e:
        raise Exception(u"{}, {}".format(e or '', e.stderr))
    folder.mission_config_write({'type': 'git', 'url': url})
    print('Prepare mission {} from {}'.format(slug, url))
Example #6
0
def make_mission_from_template(mission, template, force_remove=False):
    template_full_path = None
    for template_folder in settings.TEMPLATES_FOLDERS:
        template_full_path = os.path.join(template_folder, template)
        if os.path.exists(template_full_path):
            break
        else:
            template_full_path = None

    if template_full_path is None:
        raise TemplateWasntFound(template, settings.TEMPLATES_FOLDERS)

    folder = Folder(mission)
    mission_folder = folder.mission_folder()
    if os.path.exists(mission_folder):
        if force_remove:
            shutil.rmtree(mission_folder)
        else:
            raise MissionFolderExistsAlready(mission_folder)

    os.mkdir(mission_folder)

    from distutils.dir_util import copy_tree
    copy_tree(os.path.join(template_full_path, 'source'), mission_folder)

    GG = {}
    exec(open(os.path.join(template_full_path, 'run.py')).read()) in GG
    GG['run'](mission)

    folder.mission_config_write({'type': 'local', 'url': mission_folder})
Example #7
0
def mission_git_getter(url, slug):
    # TODO: checkout into mission solder
    # compile it
    # build docker
    # prepare cli interface
    folder = Folder(slug)
    destination_path = folder.mission_folder()

    logging.info("Getting a new mission through the git...")
    logging.info("from %s to %s", url, destination_path)

    if os.path.exists(destination_path):
        answer = raw_input("Folder {} exists already." " Do you want to overwite it? [y]/n :".format(destination_path))
        if answer is "" or answer.lower().startswith("y"):
            shutil.rmtree(destination_path)
        else:
            return

    re_ret = re.search(RE_REPO_BRANCH, url)
    if re_ret:
        checkout_url, branch = re_ret.groups()
    else:
        checkout_url = url
        branch = "master"

    logging.debug("URL info: checkioout url:%s branch:%s", url, branch)

    try:
        git.Repo.clone_from(checkout_url, destination_path, branch=branch)
    except git.GitCommandError as e:
        raise Exception(u"{}, {}".format(e or "", e.stderr))
    folder.mission_config_write({"type": "git", "url": url})
    print("Prepare mission {} from {}".format(slug, url))
Example #8
0
def recompile_mission(slug):
    folder = Folder(slug)
    compiled_path = folder.compiled_folder_path()
    logging.info("Relink folder to %s", compiled_path)
    if os.path.exists(compiled_path):
        shutil.rmtree(compiled_path)

    mission_source = MissionFilesCompiler(compiled_path)
    mission_source.compile(source_path=folder.mission_folder(), use_link=True)
Example #9
0
def recompile_mission(slug):
    folder = Folder(slug)
    compiled_path = folder.compiled_folder_path()
    logging.info("Relink folder to %s", compiled_path)
    if os.path.exists(compiled_path):
        shutil.rmtree(compiled_path)

    mission_source = MissionFilesCompiler(compiled_path)
    mission_source.compile(source_path=folder.mission_folder(), use_link=True)
Example #10
0
def mission_git_init(mission, original_url):
    folder = Folder(mission)
    mission_folder = folder.mission_folder()
    logging.info("Init git repository for folder %s", mission_folder)
    repo = git.Repo.init(mission_folder)
    for root, dirs, files in os.walk(mission_folder):
        if root.endswith(".git") or "/.git/" in root:
            continue

        for file_name in files:
            abs_file_name = os.path.join(root, file_name)
            logging.debug("Add file to local git repository %s", abs_file_name)
            repo.index.add([abs_file_name])

    repo.index.commit("initial commit")
    origin = repo.create_remote("origin", original_url)
    origin.push(repo.refs)
    origin.fetch()
    repo.create_head("master", origin.refs.master).set_tracking_branch(origin.refs.master)
    folder.mission_config_write({"type": "git", "url": original_url})
Example #11
0
def mission_git_init(mission, original_url):
    folder = Folder(mission)
    mission_folder = folder.mission_folder()
    logging.info('Init git repository for folder %s', mission_folder)
    repo = git.Repo.init(mission_folder)
    for root, dirs, files in os.walk(mission_folder):
        if root.endswith('.git') or '/.git/' in root:
            continue

        for file_name in files:
            abs_file_name = os.path.join(root, file_name)
            logging.debug('Add file to local git repository %s', abs_file_name)
            repo.index.add([abs_file_name])

    repo.index.commit("initial commit")
    origin = repo.create_remote('origin', original_url)
    origin.push(repo.refs)
    origin.fetch()
    repo.create_head('master', origin.refs.master).set_tracking_branch(
        origin.refs.master)
    folder.mission_config_write({'type': 'git', 'url': original_url})
Example #12
0
def mission_git_init(mission, original_url):
    folder = Folder(mission)
    mission_folder = folder.mission_folder()
    logging.info('Init git repository for folder %s', mission_folder)
    repo = git.Repo.init(mission_folder)
    for root, dirs, files in os.walk(mission_folder):
        if root.endswith('.git') or '/.git/' in root:
            continue

        for file_name in files:
            abs_file_name = os.path.join(root, file_name)
            logging.debug('Add file to local git repository %s', abs_file_name)
            repo.index.add([abs_file_name])

    repo.index.commit("initial commit")
    origin = repo.create_remote('origin', original_url)
    origin.push(repo.refs)
    origin.fetch()
    repo.create_head('master', origin.refs.master).set_tracking_branch(origin.refs.master)
    folder.mission_config_write({
        'type': 'git',
        'url': original_url
    })
Example #13
0
def use(parser):
    mission_slug = sys.argv[2]
    folder = Folder(mission_slug)
    os.system('cd {mission_path}; git {command}'.format(
        mission_path=folder.mission_folder(), command=' '.join(sys.argv[3:])))