Coverage for pylucid/pylucid_admin.py : 39%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# pylucid.pylucid_boot.in_virtualenv
# PyLucid
# Used to check if pip-compiles runs fine, see: PyLucidShell.do_upgrade_requirements() "django==1.11.", "django-cms==3.4.", )
# Used in PyLucidShell.do_update_env() # TODO: Remove "--pre" after v3 release "--pre", # https://pip.pypa.io/en/stable/reference/pip_install/#pre-release-versions "pylucid>=%s" % __version__ ]
# print("SELF_FILEPATH: %s" % SELF_FILEPATH) # print("BOOT_FILEPATH: %s" % BOOT_FILEPATH) # print("ROOT_PATH: %s" % ROOT_PATH) # print("OWN_FILENAME: %s" % OWN_FILENAME)
# Maybe this is not the best way?!?
else: print("We are not in a virtualenv, ok.")
""" A subprocess with tee ;) """ print("Call: %s" % " ".join(popenargs))
env = dict(os.environ) env["PYTHONUNBUFFERED"]="1" # If a python script called ;)
proc=subprocess.Popen(popenargs, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, env=env, universal_newlines=True, **kwargs ) return iter(proc.stdout.readline,'')
DEVELOPER_INSTALL: "developer_installation.txt", NORMAL_INSTALL: "normal_installation.txt", } else: print("PyLucid is installed as packages here: %s" % ROOT_PATH) self.install_mode=self.NORMAL_INSTALL
def normal_mode(self):
""" :return: Path(.../pylucid/requirements/) """ requirement_path = Path(ROOT_PATH, "pylucid", "requirements").resolve() if not requirement_path.is_dir(): raise RuntimeError("Requirements directory not found here: %s" % requirement_path) return requirement_path
""" :return: Path(.../pylucid/requirements/<mode>_installation.txt) """ requirement_path = self.get_requirement_path() filename = self.REQUIREMENTS[self.install_mode]
requirement_file_path = Path(requirement_path, filename).resolve() if not requirement_file_path.is_file(): raise RuntimeError("Requirements file not found here: %s" % requirement_file_path)
return requirement_file_path
return self._complete_path(text, line, begidx, endidx)
""" Create a PyLucid page instance. Needs two arguments: - destination: filesystem point to create a new instance - name: The project name (Should be ASCII without spaces)
Direct start with: $ pylucid_admin create_page_instance [destination] [name]
tbd. """ except ValueError as err: print("ERROR: %s" % err) print("There are two arguments needed: [destination] [name]") return
print("ERROR: destination is needed!") return
print("ERROR: name not given!") return
""" run django development server with test project
Direct call: $ ./pylucid_admin.py run_test_project_dev_server
Optional arguments are passed to ./manage.py
(We call pylucid.management.commands.run_test_project_dev_server.Command) """ cwd = Path(ROOT_PATH, "pylucid_page_instance") assert cwd.is_dir(), "Path not exists: %r" % cwd args = arg.split(" ")
VerboseSubprocess( "./manage.py", "createcachetable", cwd=cwd ).verbose_call( check=True # sys.exit(return_code) if return_code != 0 )
run_dev_server = VerboseSubprocess( "./manage.py", "run_test_project_dev_server", *args, cwd=cwd, timeout=None ) while True: try: print("\n") print("="*79) print("="*79) return_code = run_dev_server.verbose_call( check=False # Don't sys.exit(return_code) if return_code != 0 ) for x in range(3,0,-1): print("Reload in %i sec..." % x) time.sleep(1) except KeyboardInterrupt: print("\n") return # return back to the cmd loop
""" Run tests via pytest """ try: import pytest except ImportError as err: print("ERROR: Can't import pytest: %s (pytest not installed, in normal installation!)") else: root_path = str(ROOT_PATH) print("chdir %r" % root_path) os.chdir(root_path)
args = sys.argv[2:] print("Call Pytest with args: %s" % repr(args)) exit_code = pytest.main(args=args) sys.exit(exit_code)
""" Just run 'pip freeze' """ return_code = VerboseSubprocess("pip3", "freeze").verbose_call(check=False)
""" Update all packages in virtualenv.
Direct start with: $ pylucid_admin update_env
(Call this command only in a activated virtualenv.) """ if not in_virtualenv(): self.stdout.write("\nERROR: Only allowed in activated virtualenv!\n\n") return
pip3_path = Path(sys.prefix, "bin", "pip3") if not pip3_path.is_file(): print("ERROR: pip not found here: '%s'" % pip3_path) return
print("pip found here: '%s'" % pip3_path) pip3_path = str(pip3_path)
return_code = VerboseSubprocess( pip3_path, "install", "--upgrade", "pip" ).verbose_call(check=False)
req = Requirements()
# Update the requirements files by... if req.normal_mode: # ... update 'pylucid' PyPi package return_code = VerboseSubprocess( pip3_path, "install", "--upgrade", *PYLUCID_NORMAL_REQ ).verbose_call(check=False) else: # ... git pull pylucid sources return_code = VerboseSubprocess( "git", "pull", "origin", cwd=ROOT_PATH ).verbose_call(check=False)
return_code = VerboseSubprocess( pip3_path, "install", "--editable", ".", cwd=ROOT_PATH ).verbose_call(check=False)
requirement_file_path = str(req.get_requirement_file_path())
# Update with requirements files: self.stdout.write("Use: '%s'\n" % requirement_file_path) return_code = VerboseSubprocess( "pip3", "install", "--exists-action", "b", # action when a path already exists: (b)ackup "--upgrade", "--requirement", requirement_file_path, timeout=120 # extended timeout for slow Travis ;) ).verbose_call(check=False)
if not req.normal_mode: # Run pip-sync only in developer mode return_code = VerboseSubprocess( "pip-sync", requirement_file_path, cwd=ROOT_PATH ).verbose_call(check=False)
# 'reinstall' pylucid editable, because it's not in 'requirement_file_path': return_code = VerboseSubprocess( pip3_path, "install", "--editable", ".", cwd=ROOT_PATH ).verbose_call(check=False)
self.stdout.write("Please restart %s\n" % self.own_filename) sys.exit(0)
#_________________________________________________________________________ # Developer commands:
""" 1. Convert via 'pip-compile' *.in requirements files to *.txt 2. Append 'piprot' informations to *.txt requirements.
Direct start with: $ pylucid_admin upgrade_requirements """ assert BOOT_FILEPATH.is_file(), "Bootfile not found here: %s" % BOOT_FILEPATH
req = Requirements() requirements_path = req.get_requirement_path()
for requirement_in in requirements_path.glob("*.in"): requirement_in = Path(requirement_in).name
if requirement_in.startswith("basic_"): continue
requirement_out = requirement_in.replace(".in", ".txt")
self.stdout.write("_"*79 + "\n")
# We run pip-compile in ./requirements/ and add only the filenames as arguments # So pip-compile add no path to comments ;)
return_code = VerboseSubprocess( "pip-compile", "--verbose", "--upgrade", "-o", requirement_out, requirement_in, cwd=requirements_path ).verbose_call(check=True)
if not requirement_in.startswith("test_"): req_out = Path(requirements_path, requirement_out) with req_out.open("r") as f: requirement_out_content = f.read()
for version_prefix in VERSION_PREFIXES: if not version_prefix in requirement_out_content: raise RuntimeError("ERROR: %r not found!" % version_prefix)
self.stdout.write("_"*79 + "\n") output = [ "\n#\n# list of out of date packages made with piprot:\n#\n" ] for line in iter_subprocess_output("piprot", "--outdated", requirement_out, cwd=requirements_path): print(line, flush=True) output.append("# %s" % line)
self.stdout.write("\nUpdate file %r\n" % requirement_out) filepath = Path(requirements_path, requirement_out).resolve() assert filepath.is_file(), "File not exists: %r" % filepath with open(filepath, "a") as f: f.writelines(output)
""" Replace git remote url from github read-only 'https' to 'git@' e.g.:
OLD: https://github.com/jedie/PyLucid.git NEW: git@github.com:jedie/PyLucid.git
**This is only developer with github write access ;)**
git remote set-url origin https://github.com/jedie/python-creole.git
Direct start with: $ pylucid_admin change_editable_address """ print("ERROR: Only available in 'developer' mode!") return
"git", "remote", "-v", cwd=str(p), ).verbose_output(check=False) except subprocess.CalledProcessError: print("Skip.") continue
if __name__ == '__main__': main() |