def copy_in_data(self): """Copy over sqlite3 database, then run syncdb""" if settings.DATABASES['default'][ 'ENGINE'] != 'django.db.backends.sqlite3': sys.stdout.write("Nothing to do for non-sqlite3 database.\n") return elif not os.path.exists(settings.DATABASES['default']['NAME']): sys.stdout.write("KA Lite not yet installed; no data to copy.\n") return else: # Copy over data for sqlite sys.stdout.write( "* Copying over database to the server update location\n") shutil.copy( settings.DATABASES['default']['NAME'], os.path.realpath(self.working_dir + "/kalite/database/data.sqlite")) # Run the syncdb sys.stdout.write("* Syncing database...") sys.stdout.flush() call_outside_command_with_output("setup", interactive=False, manage_py_dir=os.path.join( self.working_dir, "kalite")) sys.stdout.write("\n")
def test_server_weak(self): sys.stdout.write("* Testing the new server (simple)\n") out = call_outside_command_with_output("update", "test", manage_py_dir=os.path.join( self.working_dir, "kalite")) if "Success!" not in out[0]: raise CommandError(out[1] if out[1] else out[0])
def copy_in_data(self): """Copy over sqlite3 database, then run syncdb""" if settings.DATABASES['default']['ENGINE'] != 'django.db.backends.sqlite3': sys.stdout.write("Nothing to do for non-sqlite3 database.\n") return elif not os.path.exists(settings.DATABASES['default']['NAME']): sys.stdout.write("KA Lite not yet installed; no data to copy.\n") return else: # Copy over data for sqlite sys.stdout.write("* Copying over database to the server update location\n") shutil.copy(settings.DATABASES['default']['NAME'], os.path.realpath(self.working_dir + "/kalite/database/data.sqlite")) # Run the syncdb sys.stdout.write("* Syncing database...") sys.stdout.flush() call_outside_command_with_output("setup", interactive=False, manage_py_dir=os.path.join(self.working_dir, "kalite")) sys.stdout.write("\n")
def update_via_git(self, branch=None, *args, **kwargs): """ Full update via git """ self.stages = [ "clean_pyc", "git", "download", "syncdb", ] # step 1: clean_pyc (has to be first) call_command("clean_pyc", path=os.path.join(settings.PROJECT_PATH, "..")) self.start(notes="Clean up pyc files") # Step 2: update via git self.next_stage(notes="Updating via git%s" % (" to branch %s" % branch if branch else "")) repo = git.Repo() try: if not branch: # old behavior--assume you're pulling to remote self.stdout.write(repo.git.pull() + "\n") elif "/" not in branch: self.stdout.write(repo.git.fetch() + "\n") # update all branches across all repos, to make sure all branches exist self.stdout.write(repo.git.checkout(branch) + "\n") else: self.stdout.write(repo.git.fetch("--all", "-p"), "\n") # update all branches across all repos, to make sure all branches exist self.stdout.write(repo.git.checkout("-t", branch) + "\n") except git.errors.GitCommandError as gce: if not (branch and "There is no tracking information for the current branch" in gce.stderr): # pull failed because the branch is local only. this is OK when you specify a branch (switch), but not when you don't (has to be a remote pull) self.stderr.write("Error running %s\n" % gce.command) self.stderr.write("%s\n" % gce.stderr) exit(1) # step 3: get other remote resources self.next_stage("Download remote resources") get_dubbed_video_map(force=True) # force a remote download # step 4: syncdb / migrate, via setup # NOTE: this MUST be done via an external process, # to guarantee all the new code is begin used. self.next_stage("Update the database [please wait; no interactive output]") # should be interactive=False, but this method is a total hack (out, err, rc) = call_outside_command_with_output("setup", noinput=True, manage_py_dir=settings.PROJECT_PATH) sys.stderr.write(out) if rc: sys.stderr.write(err) # Done! self.complete()
def test_server_weak(self): sys.stdout.write("* Testing the new server (simple)\n") out = call_outside_command_with_output("update", "test", manage_py_dir=os.path.join(self.working_dir, "kalite")) if "Success!" not in out[0]: raise CommandError(out[1] if out[1] else out[0])
def update_via_git(self, branch=None, *args, **kwargs): """ Full update via git """ self.stages = [ "clean_pyc", "git", "download", "syncdb", ] # step 1: clean_pyc (has to be first) call_command("clean_pyc", path=os.path.join(settings.PROJECT_PATH, "..")) self.start(notes="Clean up pyc files") # Step 2: update via git self.next_stage(notes="Updating via git%s" % (" to branch %s" % branch if branch else "")) repo = git.Repo() try: if not branch: # old behavior--assume you're pulling to remote self.stdout.write(repo.git.pull() + "\n") elif "/" not in branch: self.stdout.write( repo.git.fetch() + "\n" ) # update all branches across all repos, to make sure all branches exist self.stdout.write(repo.git.checkout(branch) + "\n") else: self.stdout.write( repo.git.fetch("--all", "-p"), "\n" ) # update all branches across all repos, to make sure all branches exist self.stdout.write(repo.git.checkout("-t", branch) + "\n") except git.errors.GitCommandError as gce: if not (branch and "There is no tracking information for the current branch" in gce.stderr): # pull failed because the branch is local only. this is OK when you specify a branch (switch), but not when you don't (has to be a remote pull) self.stderr.write("Error running %s\n" % gce.command) self.stderr.write("%s\n" % gce.stderr) exit(1) # step 3: get other remote resources self.next_stage("Download remote resources") get_dubbed_video_map(force=True) # force a remote download # step 4: syncdb / migrate, via setup # NOTE: this MUST be done via an external process, # to guarantee all the new code is begin used. self.next_stage( "Update the database [please wait; no interactive output]") # should be interactive=False, but this method is a total hack (out, err, rc) = call_outside_command_with_output( "setup", noinput=True, manage_py_dir=settings.PROJECT_PATH) sys.stderr.write(out) if rc: sys.stderr.write(err) # Done! self.complete()