def import_project(self, directory): project_name = os.path.basename( directory ) if project_name in self.projects: print("A project named '{0}' already exists.".format(project_name)) sys.exit(1) # Create project entry in database new_pb_project = Project(project_name, self, None) # Copy files shutil.copytree( directory, new_pb_project.work_dir) original_dir = os.getcwd() print("Creating public git repo '{0}'".format(new_pb_project.public_dir)) os.makedirs( new_pb_project.public_dir ) original_dir = os.getcwd() os.chdir(new_pb_project.public_dir) git.init(True) os.chdir(new_pb_project.work_dir) # Initialize git repo if it doesn't exist if not os.path.isdir(".git"): # Create first import with initial content git.init(False) git.add(["."]) git.commit("Import from {0}.".format(directory)) # Create public repository if 'public' in git.remote_list(): print("Renaming old public repo to public.orig") git.remote_rename('public', 'public.orig') print("Adding 'public' remote") git.remote_add("public", new_pb_project.public_dir) os.chdir( original_dir ) # Open by default self.projects[project_name] = new_pb_project new_pb_project.state = "open" # why save? -> to update the state to 'open' new_pb_project.save()
def import_project(self, options ): if not os.path.isdir(self.work_path): print("No directory named '{0}' exist in '{1}'.".format( self.name, options.work)) sys.exit(1) os.chdir(self.work_path) if not os.path.isfile( os.path.join( self.work_path, ".git" ) ): git.init(False) remotes = git.remote_list() if "public" not in remotes: git.remote_add("public", self.public_path) if not os.path.isdir( self.public_path ): os.makedirs( self.public_path ) os.chdir( self.public_path ) git.init(True) self.state = "open"
def create(self, project_name, language): """ Create a bare project. """ if project_name in self.projects: print("A project named '{0}' already exists.".format(project_name)) sys.exit(1) new_pb_project = Project(project_name, self, language) print("Creating project '{0}' ({1}).".format(project_name, language)) new_pb_project.save() # Create bare project os.makedirs(new_pb_project.work_dir) original_dir = os.getcwd() os.chdir(new_pb_project.work_dir) if language in self.languages: print("I have templates for a '{0}' project.".format(language)) for root, dirs, files in os.walk( new_pb_project.templates_dir ): # print root, dirs, files rel_dir = root[len(new_pb_project.templates_dir)+1:] for d in dirs: o = os.path.join(root, d) w = os.path.join(new_pb_project.work_dir, rel_dir, d) os.makedirs(w) print( "{0} -> {1}".format(o, w) ) for f in files: dest_file, ext = os.path.splitext(f) o = os.path.join(root, f) if ext == ".tmpl": w = os.path.join(new_pb_project.work_dir, rel_dir, dest_file) print( "{0} -> {1}".format(o, w) ) t = Template( file=o ) t.project = new_pb_project.name of = open(dest_file, 'w') of.write(str(t)) else: w = os.path.join(new_pb_project.work_dir, rel_dir, f) print( "{0} -> {1}".format(o, w) ) shutil.copy(o, w) else: print("No templates available.") print("Creating public git repo '{0}'".format(new_pb_project.public_dir)) os.makedirs( new_pb_project.public_dir ) original_dir = os.getcwd() os.chdir(new_pb_project.public_dir) git.init(True) os.chdir(original_dir) print("Initializing git repository.") git.init(False) print("Adding 'public' remote") git.remote_add("public", new_pb_project.public_dir) if language in self.languages: # Commit the templates git.add(["."]) git.commit("Original import") # git.push("public") os.chdir(original_dir) # Open by default self.projects[project_name] = new_pb_project new_pb_project.state = "open" # why save? -> to update the state to 'open' new_pb_project.save()