Ejemplo n.º 1
0
    def initialize(self, name, user):
        """
        Utility to create a project on the filesystem.
        
        #. Create a unix user for the project.
        #. Create home directory for code.
        #. Create a bare git repository for code.
        
        """
        from cannula.utils import shell
        project = self.get(name)
        user = api.users.get(user)

        if not user.has_perm('add', project.group):
            raise PermissionError("You can not create projects in this group")

        # TODO: Create unix user for project

        log.info("Creating project directories for: %s", project)
        if not os.path.isdir(project.repo_dir):
            os.makedirs(project.repo_dir)

        if not os.path.isdir(project.project_dir):
            os.makedirs(project.project_dir)

        # Create the git repo
        args = {'git_cmd': CANNULA_GIT_CMD, 'repo': project.repo_dir}
        shell(self.git_init_cmd % args)

        ctx = {
            'project': project,
            'cannula_admin': CANNULA_CMD,
            # The current setting file
            'settings': os.environ['DJANGO_SETTINGS_MODULE'],
            # The current python executable (could be in a virtualenv)
            'python': sys.executable
        }
        # Update git config in new repo
        write_file(project.git_config, 'git/git-config.txt', ctx)
        # Write out post-recieve hook and make it executable
        write_file(project.post_receive, 'git/post-receive.sh', ctx)
        shell('chmod 755 %s' % project.post_receive)
        # Write out a description file
        write_file(project.git_description, 'git/description.txt', ctx)

        log.info("Project %s initialized", project)
        api.log.create("Project %s initialized" % project,
                       user=user,
                       group=project.group,
                       project=project)
Ejemplo n.º 2
0
 def initialize(self, name, user):
     """
     Utility to create a project on the filesystem.
     
     #. Create a unix user for the project.
     #. Create home directory for code.
     #. Create a bare git repository for code.
     
     """
     from cannula.utils import shell
     project = self.get(name)
     user = api.users.get(user)
     
     if not user.has_perm('add', project.group):
         raise PermissionError("You can not create projects in this group")
     
     # TODO: Create unix user for project
     
     log.info("Creating project directories for: %s", project)
     if not os.path.isdir(project.repo_dir):
         os.makedirs(project.repo_dir)
     
     if not os.path.isdir(project.project_dir):
         os.makedirs(project.project_dir)
     
     # Create the git repo
     args = {
         'git_cmd': CANNULA_GIT_CMD,
         'repo': project.repo_dir
     }
     shell(self.git_init_cmd % args)
     
     ctx = {
         'project': project,
         'cannula_admin': CANNULA_CMD,
         # The current setting file
         'settings': os.environ['DJANGO_SETTINGS_MODULE'],
         # The current python executable (could be in a virtualenv)
         'python': sys.executable}
     # Update git config in new repo
     write_file(project.git_config, 'git/git-config.txt', ctx)
     # Write out post-recieve hook and make it executable
     write_file(project.post_receive, 'git/post-receive.sh', ctx)
     shell('chmod 755 %s' % project.post_receive)
     # Write out a description file
     write_file(project.git_description, 'git/description.txt', ctx)
     
     log.info("Project %s initialized", project)
     api.log.create("Project %s initialized" % project, user=user, group=project.group, project=project)
Ejemplo n.º 3
0
 def write_project_conf(self, project, extra_ctx):
     ctx = self.context.copy()
     ctx.update(extra_ctx)
     return write_file(project.supervisor_conf, self.project_template, ctx)
Ejemplo n.º 4
0
 def write_vhost_conf(self, project, extra_context={}):
     ctx = self.context.copy()
     ctx.update(extra_context)
     template = posixpath.join(self.template_base, 'vhost.conf')
     return write_file(project.vhost_conf, template, ctx)
Ejemplo n.º 5
0
 def write_startup_script(self):
     """Write out startup script for worker type."""
     file_name = os.path.join(CANNULA_BASE, 'config', self.project.name, 
         self.script_name())
     
     write_file(file_name, self.template, self.defaults)
Ejemplo n.º 6
0
 def write_vhost_conf(self, project, extra_context={}):
     ctx = self.context.copy()
     ctx.update(extra_context)
     template = posixpath.join(self.template_base, 'vhost.conf')
     return write_file(project.vhost_conf, template, ctx)