def actually_create_android_project(package_name, target_version, java_package_name, is_library): path = os.path.join(os.getcwd(), package_name.lower()) console.pretty_println("\nCreating android project ", console.bold) console.pretty_print(" Name : ", console.cyan) console.pretty_println("%s" % package_name, console.yellow) console.pretty_print(" Target Ver: ", console.cyan) console.pretty_println("%s" % target_version, console.yellow) console.pretty_print(" Java Name : ", console.cyan) console.pretty_println("%s" % java_package_name, console.yellow) if is_library: console.pretty_print(" Library : ", console.cyan) console.pretty_println("yes\n", console.yellow) cmd = [ 'android', 'create', 'lib-project', '-n', package_name, '-p', path, '-k', java_package_name, '-t', 'android-' + target_version, ] else: activity_name = utils.camel_case(package_name) console.pretty_print(" Activity : ", console.cyan) console.pretty_println("%s\n" % activity_name, console.yellow) cmd = [ 'android', 'create', 'project', '-n', package_name, '-p', path, '-k', java_package_name, '-t', 'android-' + target_version, '-a', activity_name ] print("Command: %s" % cmd) try: subprocess.check_call(cmd) print("Command: %s" % cmd) except subprocess.CalledProcessError: print("Error") raise subprocess.CalledProcessError( "failed to create android project.") # This is in the old form, let's shovel the shit around to the new form utils.mkdir_p(os.path.join(path, 'src', 'main', 'java')) os.remove(os.path.join(path, 'local.properties')) os.remove(os.path.join(path, 'project.properties')) os.remove(os.path.join(path, 'ant.properties')) os.remove(os.path.join(path, 'proguard-project.txt')) os.remove(os.path.join(path, 'build.xml')) os.rmdir(os.path.join(path, 'bin')) os.rmdir(os.path.join(path, 'libs')) shutil.move(os.path.join(path, 'AndroidManifest.xml'), os.path.join(path, 'src', 'main')) shutil.move(os.path.join(path, 'res'), os.path.join(path, 'src', 'main')) if not is_library: shutil.move(os.path.join(path, 'src', java_package_name.split('.')[0]), os.path.join(path, 'src', 'main', 'java'))
def create_rosjava_project_common(args, template_directory): project_name = args.name[0] console.pretty_println("\nCreating rosjava project ", console.bold) console.pretty_print(" Name : ", console.cyan) console.pretty_println("%s" % project_name, console.yellow) utils.mkdir_p(os.path.join(os.getcwd(), project_name.lower())) # This is in the old form, let's shovel the shit around to the new form create_gradle_package_files(args, template_directory) add_to_root_gradle_settings(args.name[0])
def create_dummy_java_class(project_name): path = os.path.join(os.getcwd(), project_name.lower()) package_name = os.path.basename(os.getcwd()) java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name) utils.mkdir_p(java_package_path) filename = os.path.join(java_package_path, 'Dude.java') java_class = "package com.github.%s.%s;\n" % (package_name, project_name) java_class += "\n" java_class += "public class Dude {\n" java_class += "}\n" console.pretty_print(' File : ', console.cyan) console.pretty_println('Dude.class', console.yellow) with open(filename, 'w') as dude_class: dude_class.write(java_class)
def create_talker_listener_classes(project_name, template_directory, author): path = os.path.join(os.getcwd(), project_name.lower()) package_name = os.path.basename(os.getcwd()) java_package_path = os.path.join(path, 'src', 'main', 'java', 'com', 'github', package_name, project_name) utils.mkdir_p(java_package_path) try: for template_name in ['Talker.java', 'Listener.java']: filename = os.path.join(java_package_path, template_name) template = utils.read_template_file(template_directory, template_name) contents = instantiate_code_template(template, package_name, project_name, author) try: f = open(filename, 'w') f.write(contents) console.pretty_print(' File : ', console.cyan) console.pretty_println(template_name, console.yellow) finally: f.close() except Exception: raise