<s> from __future__ import absolute_import , print_function , unicode_literals <EOL> import os <EOL> import sys <EOL> from six import text_type <EOL> from . import compat <EOL> from . config . data import CMS_VERSION_MATRIX , DJANGO_VERSION_MATRIX , VERSION_MATRIX <EOL> def query_yes_no ( question , default = None ) : <EOL> """<STR_LIT>""" <EOL> valid = { '<STR_LIT:yes>' : True , '<STR_LIT:y>' : True , '<STR_LIT>' : True , '<STR_LIT>' : False , '<STR_LIT:n>' : False } <EOL> if default is None : <EOL> prompt = '<STR_LIT>' <EOL> elif default == '<STR_LIT:yes>' : <EOL> prompt = '<STR_LIT>' <EOL> elif default == '<STR_LIT>' : <EOL> prompt = '<STR_LIT>' <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' . format ( default ) ) <EOL> while True : <EOL> sys . stdout . write ( question + prompt ) <EOL> choice = compat . input ( ) . lower ( ) <EOL> if default is not None and choice == '<STR_LIT>' : <EOL> return valid [ default ] <EOL> elif choice in valid : <EOL> return valid [ choice ] <EOL> else : <EOL> sys . stdout . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def supported_versions ( django , cms ) : <EOL> """<STR_LIT>""" <EOL> cms_version = None <EOL> django_version = None <EOL> try : <EOL> cms_version = float ( cms ) <EOL> except ValueError : <EOL> try : <EOL> cms_version = CMS_VERSION_MATRIX [ cms ] <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> django_version = float ( django ) <EOL> except ValueError : <EOL> try : <EOL> django_version = DJANGO_VERSION_MATRIX [ django ] <EOL> except KeyError : <EOL> pass <EOL> try : <EOL> if ( <EOL> cms_version and django_version and <EOL> not ( VERSION_MATRIX [ cms_version ] [ <NUM_LIT:0> ] <= django_version <= <EOL> VERSION_MATRIX [ cms_version ] [ <NUM_LIT:1> ] ) <EOL> ) : <EOL> raise RuntimeError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( django_version , cms_version ) <EOL> ) <EOL> except KeyError : <EOL> raise RuntimeError ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( django_version , cms_version ) <EOL> ) <EOL> return django_version , cms_version <EOL> def less_than_version ( value ) : <EOL> """<STR_LIT>""" <EOL> items = list ( map ( int , str ( value ) . split ( "<STR_LIT:.>" ) ) ) <EOL> if len ( items ) == <NUM_LIT:1> : <EOL> items . append ( <NUM_LIT:0> ) <EOL> items [ <NUM_LIT:1> ] += <NUM_LIT:1> <EOL> return "<STR_LIT:.>" . join ( map ( str , items ) ) <EOL> class chdir ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , newPath ) : <EOL> self . newPath = newPath <EOL> def __enter__ ( self ) : <EOL> self . savedPath = os . getcwd ( ) <EOL> os . chdir ( self . newPath ) <EOL> def __exit__ ( self , etype , value , traceback ) : <EOL> os . chdir ( self . savedPath ) <EOL> def format_val ( val ) : <EOL> """<STR_LIT>""" <EOL> val = text_type ( val ) <EOL> if val . isdigit ( ) : <EOL> return int ( val ) <EOL> else : <EOL> return '<STR_LIT>' . format ( val ) </s>
