def create(self):
        """Create an application context on the server"""

        self.before_create()

        puts(green('Creating app context'))
        tdir = os.path.dirname(__file__)

        # Ensure the app context user exists
        user_ensure(self.user, home='/home/' + self.user)
        dir_ensure('/home/%s/.ssh' % self.user)

        t = '/home/%s/.ssh/authorized_keys'
        app_authorized_keys = t % env.user
        ctx_authorized_keys = t % self.user

        # Ensure the app user has the same authorized_keys as the admin user
        if file_exists(app_authorized_keys) and \
           not file_exists(ctx_authorized_keys):
            sudo('cp %s %s' % (app_authorized_keys, ctx_authorized_keys))
            file_attribs(ctx_authorized_keys, mode=755,
                         owner=self.user, group=self.user)

        # Actions to be performed with the app context user
        with settings(user=self.user):
            # Make sure the dot files exist
            # This is mostly necessary for virtualenvwrapper to work properly
            for f in ['bashrc', 'bash_profile', 'profile']:
                lfn = os.path.join(tdir, 'templates', '%s.tmpl' % f)
                contents = file_local_read(lfn) % self.__dict__
                rfn = '/home/%s/.%s' % (self.user, f)
                file_ensure(rfn, owner=self.user, group=self.user)
                file_update(rfn, lambda _: contents)

            # Make sure the sites folder exists
            dir_ensure('/home/%s/sites' % self.user)

            # Make sure the app's required folders exist
            for d in [self.root_dir, self.releases_dir, self.etc_dir,
                      self.log_dir, self.run_dir, self.shared_dir]:
                dir_ensure(d)

            # Create the virtualenv
            run('mkvirtualenv ' + self.name)

        self.after_create()
def create ( self ) : self . before_create ( ) puts ( green ( 'Creating app context' ) ) tdir = os . path . dirname ( __file__ ) user_ensure ( self . user , home = '/home/' + self . user ) dir_ensure ( '/home/%s/.ssh' % self . user ) t = '/home/%s/.ssh/authorized_keys' app_authorized_keys = t % env . user ctx_authorized_keys = t % self . user if file_exists ( app_authorized_keys ) and not file_exists ( ctx_authorized_keys ) : sudo ( 'cp %s %s' % ( app_authorized_keys , ctx_authorized_keys ) ) file_attribs ( ctx_authorized_keys , mode = 755 , owner = self . user , group = self . user ) with settings ( user = self . user ) : for f in [ 'bashrc' , 'bash_profile' , 'profile' ] : lfn = os . path . join ( tdir , 'templates' , '%s.tmpl' % f ) contents = file_local_read ( lfn ) % self . __dict__ rfn = '/home/%s/.%s' % ( self . user , f ) file_ensure ( rfn , owner = self . user , group = self . user ) file_update ( rfn , lambda _ : contents ) dir_ensure ( '/home/%s/sites' % self . user ) for d in [ self . root_dir , self . releases_dir , self . etc_dir , self . log_dir , self . run_dir , self . shared_dir ] : dir_ensure ( d ) run ( 'mkvirtualenv ' + self . name ) self . after_create ( )
Create an application context on the server