<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import os <EOL> import re <EOL> import shutil <EOL> import tarfile <EOL> import tempfile <EOL> import time <EOL> import urllib <EOL> import zipfile <EOL> from invoke import task , run <EOL> assert os . getcwd ( ) == os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> VERSION_RE = re . compile ( '<STR_LIT>' ) <EOL> VERSION_FILE = os . path . join ( '<STR_LIT:src>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ task ( default = True ) <EOL> def help ( ) : <EOL> """<STR_LIT>""" <EOL> run ( '<STR_LIT>' ) <EOL> @ task <EOL> def tag_release ( version ) : <EOL> """<STR_LIT>""" <EOL> version = set_version ( version , push = True ) <EOL> run ( "<STR_LIT>" . format ( version ) ) <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def set_version ( version , push = False ) : <EOL> """<STR_LIT>""" <EOL> if version and version != '<STR_LIT>' : <EOL> version = validate_version ( version ) <EOL> write_version_file ( version ) <EOL> write_pom_file ( version ) <EOL> version = get_version_from_file ( ) <EOL> print ( '<STR_LIT>' , version ) <EOL> if push : <EOL> git_commit ( [ VERSION_FILE , '<STR_LIT>' ] , <EOL> '<STR_LIT>' . format ( version ) , push = True ) <EOL> return version <EOL> def validate_version ( version ) : <EOL> if version == '<STR_LIT>' : <EOL> version = get_dev_version ( ) <EOL> if version . endswith ( '<STR_LIT>' ) : <EOL> version += time . strftime ( '<STR_LIT>' ) <EOL> if not VERSION_RE . match ( version ) : <EOL> raise ValueError ( "<STR_LIT>" . format ( version ) ) <EOL> return version <EOL> def get_dev_version ( ) : <EOL> previous = get_version_from_file ( ) <EOL> major , minor , pre = VERSION_RE . match ( previous ) . groups ( ) [ <NUM_LIT:1> : <NUM_LIT:4> ] <EOL> if not pre : <EOL> minor = '<STR_LIT>' . format ( int ( minor [ <NUM_LIT:1> : ] ) + <NUM_LIT:1> if minor else <NUM_LIT:1> ) <EOL> if not minor : <EOL> minor = '<STR_LIT>' <EOL> return '<STR_LIT>' . format ( major , minor ) <EOL> def write_version_file ( version ) : <EOL> update_file ( VERSION_FILE , "<STR_LIT>" , version ) <EOL> def write_pom_file ( version ) : <EOL> update_file ( '<STR_LIT>' , '<STR_LIT>' , version ) <EOL> def update_file ( path , pattern , replacement ) : <EOL> replacement = pattern . replace ( '<STR_LIT>' , replacement ) <EOL> with open ( path ) as version_file : <EOL> content = '<STR_LIT>' . join ( re . sub ( pattern , replacement , line ) <EOL> for line in version_file ) <EOL> with open ( path , '<STR_LIT:w>' ) as version_file : <EOL> version_file . write ( content ) <EOL> def get_version_from_file ( ) : <EOL> namespace = { } <EOL> execfile ( VERSION_FILE , namespace ) <EOL> return namespace [ '<STR_LIT>' ] ( ) <EOL> def git_commit ( paths , message , push = False ) : <EOL> paths = paths if isinstance ( paths , basestring ) else '<STR_LIT:U+0020>' . join ( paths ) <EOL> run ( "<STR_LIT>" . format ( message , paths ) ) <EOL> if push : <EOL> run ( '<STR_LIT>' ) <EOL> @ task <EOL> def clean ( remove_dist = True , create_dirs = False ) : <EOL> """<STR_LIT>""" <EOL> directories = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> for name in directories : <EOL> if os . path . isdir ( name ) and ( name != '<STR_LIT>' or remove_dist ) : <EOL> shutil . rmtree ( name ) <EOL> if create_dirs and not os . path . isdir ( name ) : <EOL> os . mkdir ( name ) <EOL> for directory , _ , files in os . walk ( '<STR_LIT:.>' ) : <EOL> for name in files : <EOL> if name . endswith ( ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> os . remove ( os . path . join ( directory , name ) ) <EOL> @ task <EOL> def sdist ( deploy = False , remove_dist = False ) : <EOL> """<STR_LIT>""" <EOL> clean ( remove_dist , create_dirs = True ) <EOL> run ( '<STR_LIT>' <EOL> + ( '<STR_LIT>' if deploy else '<STR_LIT>' ) ) <EOL> announce ( ) <EOL> def announce ( ) : <EOL> print ( ) <EOL> print ( '<STR_LIT>' ) <EOL> for name in os . listdir ( '<STR_LIT>' ) : <EOL> print ( os . path . join ( '<STR_LIT>' , name ) ) <EOL> @ task <EOL> def jar ( jython_version = '<STR_LIT>' , pyyaml_version = '<STR_LIT>' , remove_dist = False ) : <EOL> """<STR_LIT>""" <EOL> clean ( remove_dist , create_dirs = True ) <EOL> jython_jar = get_jython_jar ( jython_version ) <EOL> print ( '<STR_LIT>' . format ( jython_jar ) ) <EOL> compile_java_files ( jython_jar ) <EOL> unzip_jar ( jython_jar ) <EOL> copy_robot_files ( ) <EOL> pyaml_archive = get_pyyaml ( pyyaml_version ) <EOL> extract_and_copy_pyyaml_files ( pyyaml_version , pyaml_archive ) <EOL> compile_python_files ( jython_jar ) <EOL> filename = create_robot_jar ( get_version_from_file ( ) ) <EOL> announce ( ) <EOL> return os . path . abspath ( filename ) <EOL> def get_jython_jar ( version ) : <EOL> filename = '<STR_LIT>' . format ( version ) <EOL> url = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( version , filename ) <EOL> return get_extlib_file ( filename , url ) <EOL> def get_pyyaml ( version ) : <EOL> filename = '<STR_LIT>' . format ( version ) <EOL> url = '<STR_LIT>' . format ( filename ) <EOL> return get_extlib_file ( filename , url ) <EOL> def get_extlib_file ( filename , url ) : <EOL> lib = '<STR_LIT>' <EOL> path = os . path . join ( lib , filename ) <EOL> if os . path . exists ( path ) : <EOL> return path <EOL> print ( '<STR_LIT>' . format ( filename , url ) ) <EOL> if not os . path . exists ( lib ) : <EOL> os . mkdir ( lib ) <EOL> urllib . urlretrieve ( url , path ) <EOL> return path <EOL> def extract_and_copy_pyyaml_files ( version , filename , build_dir = '<STR_LIT>' ) : <EOL> t = tarfile . open ( filename ) <EOL> extracted = os . path . join ( tempfile . gettempdir ( ) , '<STR_LIT>' ) <EOL> if os . path . isdir ( extracted ) : <EOL> shutil . rmtree ( extracted ) <EOL> print ( '<STR_LIT>' . format ( filename , extracted ) ) <EOL> t . extractall ( extracted ) <EOL> source = os . path . join ( extracted , '<STR_LIT>' . format ( version ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> target = os . path . join ( build_dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> shutil . copytree ( source , target , ignore = shutil . ignore_patterns ( '<STR_LIT>' ) ) <EOL> def compile_java_files ( jython_jar , build_dir = '<STR_LIT>' ) : <EOL> root = os . path . join ( '<STR_LIT:src>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> files = [ os . path . join ( root , name ) for name in os . listdir ( root ) <EOL> if name . endswith ( '<STR_LIT>' ) ] <EOL> print ( '<STR_LIT>' . format ( len ( files ) ) ) <EOL> run ( '<STR_LIT>' . format ( <EOL> target = build_dir , cp = jython_jar , files = '<STR_LIT:U+0020>' . join ( files ) ) ) <EOL> def unzip_jar ( path , target = '<STR_LIT>' ) : <EOL> zipfile . ZipFile ( path ) . extractall ( target ) <EOL> def copy_robot_files ( build_dir = '<STR_LIT>' ) : <EOL> source = os . path . join ( '<STR_LIT:src>' , '<STR_LIT>' ) <EOL> target = os . path . join ( build_dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> shutil . copytree ( source , target , ignore = shutil . ignore_patterns ( '<STR_LIT>' ) ) <EOL> shutil . rmtree ( os . path . join ( target , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def compile_python_files ( jython_jar , build_dir = '<STR_LIT>' ) : <EOL> run ( "<STR_LIT>" . format ( jython_jar , build_dir ) ) <EOL> for directory , _ , files in os . walk ( os . path . join ( build_dir , '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> for name in files : <EOL> if name . endswith ( '<STR_LIT>' ) : <EOL> os . remove ( os . path . join ( directory , name ) ) <EOL> def create_robot_jar ( version , source = '<STR_LIT>' ) : <EOL> write_manifest ( version , source ) <EOL> target = os . path . join ( '<STR_LIT>' , '<STR_LIT>' . format ( version ) ) <EOL> run ( '<STR_LIT>' . format ( target , source ) ) <EOL> return target <EOL> def write_manifest ( version , build_dir = '<STR_LIT>' ) : <EOL> with open ( os . path . join ( build_dir , '<STR_LIT>' , '<STR_LIT>' ) , '<STR_LIT:w>' ) as mf : <EOL> mf . write ( '''<STR_LIT>''' . format ( version = version ) ) </s>
