Ejemplo n.º 1
0
    def init(self, delete_if_exists, python_path=""):
        if self.use_virtualenv:
            virtualenv_full_path = path(self.virtualenv_path).joinpath(self.virtualenv_name)
            if cuisine.dir_exists(virtualenv_full_path) and delete_if_exists:
                dir_delete(virtualenv_full_path)

            with cuisine_sudo():
                pip_install(['virtualenv'])

            with cuisine_sudo():
                dir_ensure(self.virtualenv_path, recursive=True, mode=777)
                dir_attribs(self.virtualenv_path, mode=777, recursive=True)

            # make lib synlinks to install PIL correctly
            with cuisine_sudo():
                if not file_exists("/usr/lib/libfreetype.so"):
                    run("ln -sf /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/")

                if not file_exists("/usr/lib/libz.so"):
                    run("ln -sf /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/")

                if not file_exists("/usr/lib/libjpeg.so"):
                    run("ln -sf /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/")

            with cd(self.virtualenv_path):
                run('VIRTUALENV_EXTRA_SEARCH_DIR="%s" && virtualenv %s' % (python_path, self.virtualenv_name))
Ejemplo n.º 2
0
    def upload_code(self, update_submodules=True):
        self.before_upload_code()

        # we need to ensure the directory is open for writing
        with cuisine_sudo():
            dir_attribs(self.remote_project_path, mode="777")

        temp_dir_prefix = "django_temp_"

        # zip and upload file
        temp_dir = temp_dir_prefix + self.project_name + "_" + timestamp_str()

        temp_remote_path = path(remote_home()).joinpath("tmp").joinpath(temp_dir)
        temp_local_path = path(self.project_local_path).joinpath(temp_dir)
        local_dir_ensure(temp_local_path)
        with cuisine_sudo():
            dir_ensure(temp_remote_path, recursive=True, mode="666")

        files = self.scm.local_archive(temp_local_path, include_submodules=update_submodules)

        # upload files
        for dir, file in files.iteritems():
            local_archive_path = temp_local_path.joinpath(file)
            remote_archive_path = temp_remote_path.joinpath(file)
            operations.put(str(local_archive_path), str(temp_remote_path), use_sudo=True)
            local_file_delete(local_archive_path)

        # reset project dir
        self.reset_project_dir()

        # unpack files
        for dir, file in files.iteritems():
            remote_archive_path = temp_remote_path.joinpath(file)

            # unzip file
            with cuisine_sudo():
                if self.webserver:
                    self.webserver.stop()

                extdir = path(self.remote_project_path).joinpath(dir).abspath()
                dir_ensure(extdir, recursive=True, mode="777")
                file_unzip(remote_archive_path, extdir)
                file_delete(remote_archive_path)

        cuisine.run("cd %s" % self.src_root)
        cuisine.run("pwd")

        with cuisine_sudo():
            cuisine.dir_attribs(self.remote_project_path, mode="777", recursive=True)

        for precomp in self.precompilers:
            precomp.compile()

        # clear old archives
        local_dirs_delete(self.project_local_path, "%s%s.*" % (temp_dir_prefix, self.project_name))

        ## upload ends here
        self.after_upload_code()
Ejemplo n.º 3
0
    def media_restore_local_latest(self):
        dump_basename = self.latest_media_dump_basename()
        dump_local_path = self.local_media_dump_dir.joinpath(dump_basename)

        dir_delete(self.local_media_root)
        dir_ensure(self.local_media_root)

        with cd(self.local_media_root):
            run("tar -xvzf %s" % dump_local_path)
Ejemplo n.º 4
0
    def collect_static(self, clear=False):
        for dir in self.static_dirs:
            dir_ensure(dir, recursive=True, mode="777")

        command = "collectstatic --noinput"

        if clear:
            command += " --clear"

        self.manage(command)
Ejemplo n.º 5
0
    def compile(self):
        super(CoffeePrecompiler, self).compile()

        abs_dir_from = self.abs_dir_from()
        abs_dir_to = self.abs_dir_to()

        with cuisine.cuisine_sudo():
            dir_ensure(abs_dir_to, mode='777', recursive=True)
        
        cuisine.sudo('sudo coffee --compile --output %(abs_dir_to)s %(abs_dir_from)s' % {'abs_dir_from': abs_dir_from, 'abs_dir_to': abs_dir_to})
Ejemplo n.º 6
0
    def backup_database(self, filename, zip=False, folder=None):
        folder = folder or self.db_backup_folder

        with cuisine.cuisine_sudo():
            cuisine.dir_ensure(folder, recursive=True, mode="777")

        file_full_path = "/".join([folder, filename])

        with self.pg_pass():
            sudo_pipeline(("pg_dump -O -x %s | gzip > %s" if zip else "pg_dump %s > %s")
            % (self.database_name, file_full_path), user=self.superuser_login)
Ejemplo n.º 7
0
    def upload_code(self, update_submodules=True):
        if self.webserver:
            self.webserver.stop()

        self.before_upload_code()

        # we need to ensure the directory is open for writing
        with cuisine_sudo():
            dir_attribs(self.remote_project_path, mode='777')

        self.clear_remote_project_path_save_site()

        temp_dir_prefix = 'django_temp_'

        # zip and upload file
        temp_dir = temp_dir_prefix + self.project_name + '_' + timestamp_str()

        temp_remote_path = path(self.remote_project_path).joinpath(temp_dir)
        temp_local_path = path(self.project_local_path).joinpath(temp_dir)
        local_dir_ensure(temp_local_path)
        dir_ensure(temp_remote_path)

        files = self.scm.local_archive(temp_local_path, include_submodules=update_submodules)

        for dir, file in files.iteritems():
            local_archive_path = temp_local_path.joinpath(file)
            remote_archive_path = temp_remote_path.joinpath(file)
            put(str(local_archive_path), str(temp_remote_path), use_sudo=True)
            local_file_delete(local_archive_path)

            #unzip file
            with cuisine_sudo():
                extdir = path(self.remote_project_path).joinpath(dir).abspath()
                dir_ensure(extdir, recursive=True, mode='777')
                file_unzip(remote_archive_path, extdir)
                file_delete(remote_archive_path)

        cuisine.run("cd %s" % self.src_root)
        cuisine.run("pwd")

        with cuisine_sudo():
            cuisine.dir_attribs(self.remote_project_path, mode="777", recursive=True)

        for precomp in self.precompilers:
            precomp.compile()

        # clear old archives
        local_dirs_delete(self.project_local_path, '%s%s.*' % (temp_dir_prefix, self.project_name))

        ## upload ends here
        self.after_upload_code()

        if self.webserver:
            self.webserver.start()
Ejemplo n.º 8
0
    def download_db_dump(self):
        remote_file_basename = self._create_db_backup_name()
        remote_dir = "/tmp"
        remote_file_path = "%s/%s" % (remote_dir, remote_file_basename)

        dir_ensure(remote_dir, mode='777')
        self.database.backup_database(remote_file_basename, folder=remote_dir, zip=True)

        local_dir_ensure(self.local_db_dump_dir)
        get(remote_file_path, self.local_db_dump_dir)

        with cuisine_sudo(): file_delete(remote_file_path)
Ejemplo n.º 9
0
    def compile(self):
        super(CoffeePrecompiler, self).compile()

        abs_dir_from = self.abs_dir_from()
        abs_dir_to = self.abs_dir_to()

        with cuisine.cuisine_sudo():
            dir_ensure(abs_dir_to, mode="777", recursive=True)

        cuisine.sudo(
            "sudo coffee --compile --output %(abs_dir_to)s %(abs_dir_from)s"
            % {"abs_dir_from": abs_dir_from, "abs_dir_to": abs_dir_to}
        )
Ejemplo n.º 10
0
    def init(self, delete_if_exists, python_path=""):
        if self.use_virtualenv:
            virtualenv_full_path = path(self.virtualenv_path).joinpath(self.virtualenv_name)
            if cuisine.dir_exists(virtualenv_full_path) and delete_if_exists:
                dir_delete(virtualenv_full_path)

            with cuisine_sudo():
                pip_install(['virtualenv'])

            with cuisine_sudo():
                dir_ensure(self.virtualenv_path, recursive=True, mode=777)
                dir_attribs(self.virtualenv_path, mode=777, recursive=True)

            with cd(self.virtualenv_path):
                run('VIRTUALENV_EXTRA_SEARCH_DIR="%s" && virtualenv %s' % (python_path, self.virtualenv_name))
Ejemplo n.º 11
0
    def compile(self):
        super(LessPrecompiler, self).compile()
        abs_dir_from = self.abs_dir_from()
        abs_dir_to = self.abs_dir_to()

        with cuisine.cuisine_sudo():
            dir_ensure(abs_dir_to, mode='777', recursive=True)

        for a_file in ls_re(abs_dir_from, '.*\\.less'):
            cuisine.sudo('%(lessc_path)s %(dir_from)s/%(basename)s.less %(dir_to)s/%(basename)s.css' % \
             {
                 'lessc_path': self.lessc_path(),
                 'dir_from': abs_dir_from,
                 'dir_to': abs_dir_to,
                 'basename': a_file[:-5]
             })
Ejemplo n.º 12
0
    def reset_project_dir(self):
        home_dir = remote_home()
        site_path_basename = path(self.remote_site_path).name
        with cuisine_sudo():
            cuisine.dir_ensure(self.remote_site_path, recursive=True, mode="777")
            cuisine.dir_ensure("%s/tmp" % home_dir, mode="777")
            dir_delete("%(home_dir)s/tmp/%(site_path_basename)s" % locals())
            cuisine.run("mv %(site_dir)s %(home_dir)s/tmp" % {"site_dir": self.remote_site_path, "home_dir": home_dir})

            clear_dir(self.remote_project_path)

            # restore site dir
            cuisine.run(
                "mv %(home_dir)s/tmp/%(site_dir_basename)s %(proj_path)s"
                % {"site_dir_basename": site_path_basename, "proj_path": self.remote_project_path, "home_dir": home_dir}
            )
Ejemplo n.º 13
0
    def clear_remote_project_path_save_site(self):
        home_dir = remote_home()
        site_path_basename = path(self.remote_site_path).name
        with cuisine_sudo():
            cuisine.dir_ensure(self.remote_site_path, recursive=True, mode='777')
            cuisine.dir_ensure("%s/tmp" % home_dir, mode='777')
            dir_delete("%(home_dir)s/tmp/%(site_path_basename)s" % locals())
            cuisine.run('mv %(site_dir)s %(home_dir)s/tmp' % {'site_dir': self.remote_site_path, 'home_dir': home_dir})

            clear_dir(self.remote_project_path)


            #restore site dir
            cuisine.run('mv %(home_dir)s/tmp/%(site_dir_basename)s %(proj_path)s' % {
                'site_dir_basename': site_path_basename,
                'proj_path': self.remote_project_path,
                'home_dir': home_dir
            })
Ejemplo n.º 14
0
    def compile(self):
        super(LessPrecompiler, self).compile()
        abs_dir_from = self.abs_dir_from()
        abs_dir_to = self.abs_dir_to()

        with cuisine.cuisine_sudo():
            dir_ensure(abs_dir_to, mode="777", recursive=True)

        for a_file in ls_re(abs_dir_from, ".*\\.less"):
            cuisine.sudo(
                "%(lessc_path)s %(dir_from)s/%(basename)s.less %(dir_to)s/%(basename)s.css"
                % {
                    "lessc_path": self.lessc_path(),
                    "dir_from": abs_dir_from,
                    "dir_to": abs_dir_to,
                    "basename": a_file[:-5],
                }
            )
Ejemplo n.º 15
0
    def backup_database(self, filename, zip=False, folder=None, ignore_tables=None):
        folder = folder or self.db_backup_folder

        with cuisine.cuisine_sudo():
            cuisine.dir_ensure(folder, recursive=True, mode="777")

        file_full_path = "/".join([folder, filename])

        additional_argument = ""

        if ignore_tables:
            for table in ignore_tables:
                additional_argument = "%s -T '%s'" % (additional_argument, table)

        with self.pg_pass():
            sudo_pipeline(
                ("pg_dump -O -x %s %s | gzip > %s" if zip else "pg_dump %s %s > %s")
                % (self.database_name, additional_argument, file_full_path),
                user=self.superuser_login,
            )
Ejemplo n.º 16
0
    def init(self):
        """
        Should be called at least one before uploading the code. Creates project dirs and copies static_upload files.
        """
        with cuisine_sudo():
            cuisine.dir_ensure(self.remote_project_path, recursive=True,
                owner=self.webserver.webserver_user, group=self.webserver.webserver_group)

            cuisine.dir_ensure(self.remote_site_path, recursive=True,
                owner=self.webserver.webserver_user, group=self.webserver.webserver_group)

            cuisine.dir_ensure(self.log_path, recursive=True,
                owner=self.webserver.webserver_user, group=self.webserver.webserver_group)

            cuisine.dir_ensure(self.media_root, recursive=True,
                owner=self.webserver.webserver_user, group=self.webserver.webserver_group)

            cuisine.dir_ensure(self.static_root, recursive=True,
                owner=self.webserver.webserver_user, group=self.webserver.webserver_group)

        self.configure_virtualenv()
Ejemplo n.º 17
0
    def setup_dependencies(self):
        # file_dependencies = []
        # if self.req_file:
        #    with open(self.req_file, 'r') as file:
        #        dep_str = file.read()
        #        file_dependencies = [str.split('==') for str in dep_str.split('\n') if str != '']
        #

        temp_path = path(remote_home()).joinpath("tmp")
        with cuisine_sudo():
            dir_ensure(temp_path)

        operations.put(self.req_file, str(temp_path), use_sudo=True)

        remote_req_file = temp_path.joinpath(path(self.req_file).basename())

        if self.use_virtualenv:
            with virtualenv(self.virtualenv_path, self.virtualenv_name):
                pip_install(self.dependencies)
                pip_install_file_requirements(remote_req_file)
        else:
            with cuisine_sudo():
                pip_install(self.dependencies)
                pip_install_file_requirements(remote_req_file)
Ejemplo n.º 18
0
 def collect_static(self):
     for dir in self.static_dirs:
         dir_ensure(dir, recursive=True, mode='777')
     self.manage("collectstatic --noinput")
Ejemplo n.º 19
0
 def compile(self):
     dir_ensure(self.abs_dir_to())
     return self.dir_to