コード例 #1
0
ファイル: shutitfile.py プロジェクト: shoaibjdev/shutit
def shutitfile_to_shutit_module(shutit, skel_shutitfile, skel_path,
                                skel_domain, skel_module_name,
                                skel_domain_hash, skel_delivery, skel_depends,
                                order, total, skel_module_modifier):

    if not os.path.exists(skel_shutitfile):
        if urlparse(skel_shutitfile)[0] == '':
            shutit.fail('Dockerfile/ShutItFile "' + skel_shutitfile +
                        '" must exist')
        shutitfile_contents = urlopen(skel_shutitfile).read()
        shutitfile_dirname = None
    else:
        shutitfile_contents = open(skel_shutitfile).read()
        shutitfile_dirname = os.path.dirname(skel_shutitfile)
        if shutitfile_dirname == '':
            shutitfile_dirname = './'
        if os.path.exists(shutitfile_dirname):
            if os.path.exists(skel_path + '/context'):
                shutil.rmtree(skel_path + '/context')
                shutil.copytree(shutitfile_dirname, skel_path + '/context')
            else:
                # Copy any other files that do not already exist on the target
                os.system('cp -r -n ' + shutitfile_dirname + '/* ' + skel_path)
        # Change to this context
        os.chdir(shutitfile_dirname)

    # Process the shutitfile
    shutitfile_representation, ok = shutit_skeleton.process_shutitfile(
        shutit, shutitfile_contents)
    if not ok:
        return '', '', '', '', '', False

    # Check the shutitfile representation
    check_shutitfile_representation(shutit, shutitfile_representation,
                                    skel_delivery)

    # Get the shutit module as a string
    sections, module_id, module_name, depends, default_include = generate_shutit_module_sections(
        shutit, shutitfile_representation, skel_domain, skel_module_name,
        skel_module_modifier, skel_shutitfile, skel_depends, order, total)
    if module_id == skel_module_name:
        module_id = skel_domain + """.""" + skel_module_name + skel_module_modifier

    # Final section
    final_section = """

def module():
	return """ + skel_module_name + skel_module_modifier + """(
		'""" + module_id + """', """ + skel_domain_hash + str(order * 0.0001) + str(
        random.randint(1, 999)) + """,
		description='""" + shutitfile_representation['shutitfile'][
            'description'] + """',
		delivery_methods=[('""" + skel_delivery + """')],
		maintainer='""" + shutitfile_representation['shutitfile'][
                'maintainer'] + """',
		depends=[""" + depends + """]
	)
"""
    sections.update({'final_section': final_section})

    # Return program to main shutit_dir
    if shutitfile_dirname:
        os.chdir(sys.path[0])
    return sections, module_id, skel_module_name, default_include, ok
コード例 #2
0
ファイル: shutitfile.py プロジェクト: Kafkamorph/shutit
def shutitfile_to_shutit_module(skel_shutitfile,
                                skel_path,
                                skel_domain,
                                skel_module_name,
                                skel_domain_hash,
                                skel_delivery,
                                skel_depends,
                                order,
	                            total,
	                            skel_module_modifier):
	shutit = shutit_global.shutit

	if not os.path.exists(skel_shutitfile):
		if urlparse(skel_shutitfile)[0] == '':
			shutit.fail('Dockerfile/ShutItFile "' + skel_shutitfile + '" must exist')
		shutitfile_contents = urlopen(skel_shutitfile).read()
		shutitfile_dirname = None
	else:
		shutitfile_contents = open(skel_shutitfile).read()
		shutitfile_dirname = os.path.dirname(skel_shutitfile)
		if shutitfile_dirname == '':
			shutitfile_dirname = './'
		if os.path.exists(shutitfile_dirname):
			if os.path.exists(skel_path + '/context'):
				shutil.rmtree(skel_path + '/context')
				shutil.copytree(shutitfile_dirname, skel_path + '/context')
			else:
				# Copy any other files that do not already exist on the target
				os.system('cp -r -n ' + shutitfile_dirname + '/* ' + skel_path)
		# Change to this context
		os.chdir(shutitfile_dirname)

	# Process the shutitfile
	shutitfile_representation, ok = shutit_skeleton.process_shutitfile(shutitfile_contents)
	if not ok:
		return '', '', '', '', '', False

	# Check the shutitfile representation
	check_shutitfile_representation(shutitfile_representation, skel_delivery)

	# Get the shutit module as a string
	sections, module_id, module_name, depends, default_include = generate_shutit_module_sections(shutitfile_representation, skel_domain, skel_module_name, skel_module_modifier, skel_shutitfile, skel_depends, order, total)
	if module_id == skel_module_name:
		module_id = skel_domain + """.""" + skel_module_name + skel_module_modifier

	# Final section
	final_section  = """

def module():
	return """ + skel_module_name + skel_module_modifier + """(
		'""" + module_id + """', """ + skel_domain_hash + str(order * 0.0001) + str(random.randint(1,999)) + """, 
		description='""" + shutitfile_representation['shutitfile']['description'] + """',
		delivery_methods=[('""" + skel_delivery + """')],
		maintainer='""" + shutitfile_representation['shutitfile']['maintainer'] + """',
		depends=[""" + depends + """]
	)
"""
	sections.update({'final_section':final_section})

	# Return program to main shutit_dir
	if shutitfile_dirname:
		os.chdir(sys.path[0])
	return sections, module_id, skel_module_name, default_include, ok