virtualenv/setup/create_python_env.py
author grandjoncl
Thu, 20 Dec 2012 15:22:42 +0100
branchmodifications_relative_ldtxml
changeset 1044 e3902e1bd785
parent 668 b52724db32ab
permissions -rw-r--r--
modifications to have relative src for media in the xml ldt of a project. - Migration in order to set all the project ldt with the new values in the xml. If the media has a content that doesn't exist, the media is erased. If the project has no valid media, the project is deleted. There is a test in project_tests. - The migration uses the command : set_projectldtiri - The command set_projectldtiri uses the function in utils relative_src_xml that returns an xml. The command deletes the projects that have no ldt or the ldt isn't valid (empty string) - Modifications in lignesdetemps to have absolute urls in the xml when we open a project or in the research when we display the results in lignes de temps

"""
Call this like ``python create_python_env.py``; it will
refresh the project-boot.py script

-prerequisite:

- virtualenv

- python project-boot.py --unzip-setuptools --no-site-packages --clear --type-install=local <path_to_venv>

"""

import os
import subprocess
import re
import sys


here = os.path.dirname(os.path.abspath(__file__))
base_dir = here
script_name = os.path.join(base_dir, 'project-boot.py')

import virtualenv

src_base = os.path.abspath(os.path.join(here,"..","res","src")).replace("\\","/")
lib_path = os.path.abspath(os.path.join(here,"..","res","lib")).replace("\\","/")
patch_path = os.path.abspath(os.path.join(here,"res","patch")).replace("\\","/")


EXTRA_TEXT  = "import sys\n"
EXTRA_TEXT += "sys.path.append('%s')\n" % (lib_path)
EXTRA_TEXT += "sys.path.append('%s')\n" % (os.path.abspath(os.path.join(here,"res")).replace("\\","/"))
EXTRA_TEXT += "from res_create_env import generate_install_methods\n"
EXTRA_TEXT += "adjust_options, extend_parser, after_install = generate_install_methods(path_locations, '%s', Logger, call_subprocess)\n" % (src_base)


def main():
    python_version = ".".join(map(str,sys.version_info[0:2]))
    text = virtualenv.create_bootstrap_script(EXTRA_TEXT, python_version=python_version)
    if os.path.exists(script_name):
        f = open(script_name)
        cur_text = f.read()
        f.close()
    else:
        cur_text = ''
    print 'Updating %s' % script_name
    if cur_text == 'text':
        print 'No update'
    else:
        print 'Script changed; updating...'
        f = open(script_name, 'w')
        f.write(text)
        f.close()

if __name__ == '__main__':
    main()