Commit 42df134e authored by François Fortin's avatar François Fortin
Browse files

Merge branch 'sasa_master_python3_migration' into 'master'

Sasa master python3 migration

See merge request !8
parents 6b2d2261 d48609d0
Pipeline #187441 failed with stage
in 44 seconds
*.pyc
*.o
*.so
macadam.py
metro.log
.idea/
src/frontend/model
usr/share/metro/data/selftest/roadcast.xml
......@@ -40,11 +40,11 @@ fi
echo ""
echo "* link to model ( src/frontend/model -> usr/share/metro/model )"
ln -sf ../../usr/share/metro/model src/frontend/model
ln -sTf ../../usr/share/metro/model src/frontend/model
echo ""
if which python-config >/dev/null; then
PYTHON_INC=`python-config --includes`
PYTHON_INC=`python3-config --includes`
echo "* Python include path = "$PYTHON_INC
fi
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
#
#
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
# Copyright (C) Her Majesty The Queen in Right of Canada, Environment Canada, 2006
#
# Questions or bugs report: metro@ec.gc.ca
# METRo repository: https://framagit.org/metroprojects/metro
# Documentation: https://framagit.org/metroprojects/metro/wikis/home
#
#
# Code contributed by:
# Miguel Tremblay - Canadian meteorological center
#
# $LastChangedDate$
# $LastChangedRevision$
#
########################################################################
###################################################################################
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
......@@ -34,43 +31,39 @@
"""
Nom: check_translation
Nom: check_translation
Auteur: Miguel Tremblay
Auteur: Miguel Tremblay
Date: November 10th 2004
Description: Crer les fichiers .po correspondant au .py .
Ecrit ces fichiers dans /tmp/translate
Pour chacun de ces fichiers, il faut mettre la meme string qu'il y a dans
msgid a l'interieur de msgstr.
Compare ensuite les fichier dans /locale/en/LC_MESSAGES/*.po avec ceux
contenu dans /tmp/translate
S'il y a une difference, on fait un merge avec les fichiers dans en et fr.
Le fichier issue du merge porte le nom filename_merge.po.
On affiche la liste des fichiers qui ont ete modifies dans le fichier
merge.txt
Date: November 10th 2004
Description: Crer les fichiers .po correspondant au .py. Ecrit ces fichiers dans /tmp/translate pour chacun de
ces fichiers, il faut mettre la meme string qu'il y a dans msgid a l'interieur de msgstr.
Compare ensuite les fichier dans /locale/en/LC_MESSAGES/*.po avec ceux contenu dans /tmp/translate
s'il y a une difference, on fait un merge avec les fichiers dans en et fr.
Le fichier issue du merge porte le nom filename_merge.po.
On affiche la liste des fichiers qui ont ete modifies dans le fichier merge.txt
"""
import os
import os.path
import sys
import filecmp
from copy_msgid_msgstr import copy_msgid_msgstr
from scripts.copy_msgid_msgstr import copy_msgid_msgstr
sTemporaryDirectory = '/tmp/metro_translation/'
def main():
# Check if the .tar of the documentation is in argument.
if len(sys.argv) < 2:
sMessage = 'Usage: ' + sys.argv[0] + ' ../src/frontend/'
print sMessage
print(sMessage)
return
else:
check_translation(sys.argv[1])
def check_translation(sDirectory):
# Get a list of all the files in the directory
lAllFiles = []
......@@ -85,7 +78,7 @@ def check_translation(sDirectory):
nIndice = sFile.rfind('en/LC_MESSAGES/')
if nIndice < 0:
continue
sFilename = sFile[sFile.rfind('/')+1:len(sFile)-3]
sFilename = sFile[sFile.rfind('/') + 1:len(sFile) - 3]
if sExtension == 'po':
lPoFilepath.append(sFile)
lPoFilename.append(sFilename)
......@@ -94,17 +87,17 @@ def check_translation(sDirectory):
lPythonFilename = []
for sFile in lAllFiles:
sExtension = sFile[-2:]
sFilename = sFile[sFile.rfind('/')+1:len(sFile)-3]
sFilename = sFile[sFile.rfind('/') + 1:len(sFile) - 3]
if sExtension == 'py' and sFilename in lPoFilename:
lPythonFilepath.append(sFile)
# Create the temporary directory
if not os.path.exists(sTemporaryDirectory):
os.mkdir(sTemporaryDirectory)
# Create the .po files.
# Create the .po files.
for sFilepath in lPythonFilepath:
sFilename = sFilepath[sFilepath.rfind('/')+1:len(sFilepath)-3]
sPoFile = sTemporaryDirectory+sFilename+'.po'
sCommand = 'pygettext -o ' +sPoFile +' '+ sFilepath
sFilename = sFilepath[sFilepath.rfind('/') + 1:len(sFilepath) - 3]
sPoFile = sTemporaryDirectory + sFilename + '.po'
sCommand = 'pygettext -o ' + sPoFile + ' ' + sFilepath
# Create po file
os.system(sCommand)
# Copy directly msgid in msgstr
......@@ -114,65 +107,62 @@ def check_translation(sDirectory):
nIndice = sPoFilepath.rfind('/')
if nIndice < 0:
continue
sPoFilename = sPoFilepath[nIndice+1:len(sPoFilepath)-3]
sPoFilename = sPoFilepath[nIndice + 1:len(sPoFilepath) - 3]
if sFilename == sPoFilename:
sOriginalPoFilepath = sPoFilepath
break
# Compare the file with the famous command "msgcmp"
sCommand = 'msgcmp ' +sOriginalPoFilepath +' ' +sPoFile +\
" > /dev/null 2>&1"
# If the files are not compatible, the sys.command returns
# something that is not 0.
sCommand = 'msgcmp ' + sOriginalPoFilepath + ' ' + sPoFile + " > /dev/null 2>&1"
# If the files are not compatible, the sys.command returns something that is not 0.
if os.system(sCommand):
# Create the merge file for english
sMergeFilenameEn = sFilename + '_merge_en.po'
sCommand = 'msgmerge ' +sOriginalPoFilepath +' ' +sPoFile\
+' -o ' +sMergeFilenameEn +\
sCommand = 'msgmerge ' + sOriginalPoFilepath + ' ' + sPoFile + ' -o ' + sMergeFilenameEn + \
" > /dev/null 2>&1"
os.system(sCommand)
# Get the file in french
sMergeFilenameFr = sFilename + '_merge_fr.po'
sPoFileFr = sPoFile.replace('/en/','/fr/')
sOriginalPoFilepathFr = sOriginalPoFilepath.\
replace('/en/','/fr/')
sCommand = 'msgmerge ' +sOriginalPoFilepathFr +' ' +\
sPoFileFr\
+' -o ' +sMergeFilenameFr +\
sMergeFilenameFr = sFilename + '_merge_fr.po'
sPoFileFr = sPoFile.replace('/en/', '/fr/')
sOriginalPoFilepathFr = sOriginalPoFilepath.replace('/en/', '/fr/')
sCommand = 'msgmerge ' + sOriginalPoFilepathFr + ' ' + sPoFileFr + ' -o ' + sMergeFilenameFr + \
" > /dev/null 2>&1"
os.system(sCommand)
# Add the file names in the list
lPoChanged.append(sOriginalPoFilepathFr)
lPoChanged.append(sOriginalPoFilepath)
print sMergeFilenameFr
print sMergeFilenameEn
print(sMergeFilenameFr)
print(sMergeFilenameEn)
# Write the file if there is any changed
if len(lPoChanged) > 0:
lPoChanged = map(lambda x:x+"\n", lPoChanged)
lPoChanged = [x + "\n" for x in lPoChanged]
file_with_filenames = open('changed_files', 'w')
file_with_filenames.writelines(lPoChanged)
####################################
# --------------------------------------------------------------------------------------------------------------------
# Name listAllFile_directory
#
# Parameters: list lFileNames : list of string to be returned with new string
# representing files.
# string sDir : directory in which an ls is performed.
# list lFiles : list of files to append in the directory.
#
#
# Author: Ben Park
# See post: http://groups.google.com/groups?hl=en&lr=&safe=off&selm=4cc96c48.0204031030.53bfb69f%40posting.google.com
#
####################################
# --------------------------------------------------------------------------------------------------------------------
def listAllFile_directory(lFileNames, sDir, lFiles):
def f1(a,sDir=sDir):
return os.path.join(sDir,a)
lFiles2 = map(f1, lFiles)
def f1(a, sDir=sDir):
return os.path.join(sDir, a)
lFiles2 = list(map(f1, lFiles))
lFileNames.extend(lFiles2)
if __name__ == "__main__":
main()
......
......@@ -4,19 +4,17 @@
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
# Copyright (C) Her Majesty The Queen in Right of Canada, Environment Canada, 2006
#
# Questions or bugs report: metro@ec.gc.ca
# METRo repository: https://framagit.org/metroprojects/metro
# Documentation: https://framagit.org/metroprojects/metro/wikis/home
#
#
# Code contributed by:
# Miguel Tremblay - Canadian meteorological center
#
# $LastChangedDate$
# $LastChangedRevision$
#
########################################################################
###################################################################################
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
......@@ -30,69 +28,51 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
"""
Nom: copy_msgid_msgstr
Nom: copy_msgid_msgstr
Auteur: Miguel Tremblay
Auteur: Miguel Tremblay
Date: November 10th 2004
Date: November 10th 2004
Description: Prend un fichier .po et copy le contenu de chaque msgid dans
le msgstr en bas de lui.
Description: Prend un fichier .po et copy le contenu de chaque msgid dans le msgstr en bas de lui.
"""
import os
import sys
def copy_msgid_msgstr(sFilename):
######## Open file ##############################
def copy_msgid_msgstr(sFilename):
# ------------------------------------------- Open file -------------------------------------------------------
file_original_po = open(sFilename)
sFile_ori_po = file_original_po.read()
file_original_po.close()
######## Split the file to msgid ##########################
# --------------------------------- Split the file to msgid -----------------------------------------------------
l_msgid = sFile_ori_po.split('msgid')
l_msgstr = sFile_ori_po.split('msgstr')
l_file = l_msgstr
# Display the msgid until msgstr is encontered
for i in range(1,len(l_msgid)):
# Display the msgid until msgstr is encountered
for i in range(1, len(l_msgid)):
sItem_msgid = l_msgid[i]
sItem_msgstr = l_msgstr[i]
# print sItem_msgid
# print sItem_msgstr
sReplace = sItem_msgid[:sItem_msgid.find('msgstr')]
# print sReplace
# Replace "" in msgstr by this string
sItem_msgstr = sItem_msgstr.replace('""', 'msgstr' + sReplace,1)
sItem_msgstr = sItem_msgstr.replace('""', 'msgstr' + sReplace, 1)
sItem_msgstr = sItem_msgstr[1:len(sItem_msgstr)]
# print "---"
# continue
l_file[i] = sItem_msgstr
# print "-----"
file_translated_po = open(sFilename, 'w')
file_translated_po.writelines(l_file)
return
def main():
if len(sys.argv) != 2:
print "Usage: copy_msgid_msgstr.py filename.po"
print("Usage: copy_msgid_msgstr.py filename.po")
return
copy_msgid_msgstr(sys.argv[1])
if __name__ == "__main__":
main()
if __name__ == "__main__":
main()
......@@ -4,20 +4,18 @@
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
# Copyright (C) Her Majesty The Queen in Right of Canada, Environment Canada, 2006
#
# Questions or bugs report: metro@ec.gc.ca
# METRo repository: https://framagit.org/metroprojects/metro
# Documentation: https://framagit.org/metroprojects/metro/wikis/home
#
#
# Code contributed by:
# Miguel Tremblay - Canadian meteorological center
# Francois Fortin - Canadian meteorological center
#
# $LastChangedDate$
# $LastChangedRevision$
#
########################################################################
################################################################################
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
......@@ -31,50 +29,43 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
"""
Nom: create_mo
Nom: create_mo
Auteur: Miguel Tremblay
Date: November 17th 2004
Auteur: Miguel Tremblay
Description: Crer les fichiers .mo correspondant au .po
dans un rpertoire.
Date: November 17th 2004
Description: Crer les fichiers .mo correspondant au .po dans un rpertoire.
"""
import sys
import os
def create_mo(sFile_with_filenames):
file_with_filenames = open(sFile_with_filenames)
def create_mo(sFile_with_filenames):
file_with_filenames = open(sFile_with_filenames)
lPoFiles = file_with_filenames.readlines()
for sPoFile in lPoFiles:
sMoFile = sPoFile[:-3]+'mo'
sCommand = 'msgfmt -o ' +sMoFile +' ' +sPoFile
print sCommand
sMoFile = sPoFile[:-3] + 'mo'
sCommand = 'msgfmt -o ' + sMoFile + ' ' + sPoFile
print(sCommand)
os.system(sCommand)
def main():
# Check if the .tar of the documentation is in argument.
if len(sys.argv) < 2:
sMessage = 'Usage: ' + sys.argv[0] + ' files.txt'
print sMessage
print(sMessage)
return
else:
create_mo(sys.argv[1])
create_mo(sys.argv[1])
if __name__ == "__main__":
main()
......@@ -62,28 +62,28 @@ if [ -n "$PYTHON_INCLUDE" ] ; then
exit 1
fi
PYTHON_INC=-I$PYTHON_INCLUDE
elif which python-config >/dev/null; then
echo "Using python-config to detect python settings."
elif which python3-config >/dev/null; then
echo "Using python3-config to detect python settings."
echo "You can override detected values by setting"
echo "enviroment variable PYTHON_INCLUDE."
echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python2.4\""
PYTHON_INC=`python-config --includes`
echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python3.6\""
PYTHON_INC=`python3-config --includes`
else
echo "----------------------------------------------------------"
echo "WARNING!"
echo "No python path defined."
echo "Will try to used the default path for python 2.4"
echo "Will try to used the default path for python 3.6"
echo "If it still doesn't work,"
echo "please set environment variable PYTHON_INCLUDE to your"
echo "python include directory."
echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python2.4\""
echo "Ex: export PYTHON_INCLUDE=\"/usr/local/include/python3.6\""
echo "----------------------------------------------------------"
echo ""
PYTHON_INC="-I/usr/include/python2.4/"
PYTHON_INC="-I/usr/include/python3.6/"
fi
echo " Python include path = "$PYTHON_INC
PLATFORM=`python -c "import platform;print platform.architecture()[0]"`
PLATFORM=`python3 -c "import platform;print(platform.architecture()[0])"`
if [ $PLATFORM = "64bit" ]; then
FORTRAN_DEFAULT_INTEGER="-fdefault-integer-8"
echo " 64 bit architecture detected"
......@@ -93,7 +93,7 @@ fi
echo " Using SWIG"
echo ' macadam.i :'
swig -python macadam.i
swig -python macadam.i
echo " C compilation"
gcc -c -fPIC -Wall -Wno-implicit macadam.c $PYTHON_INC
......@@ -133,6 +133,3 @@ if [ ! -d $destination_path/usr/lib/metro ]; then
mkdir -p $destination_path/usr/lib/metro
fi
cp _macadam.so $destination_path/usr/lib/metro/
#cp -v _macadam.so macadam.py ../frontend/model/
......@@ -3,20 +3,18 @@
#
# METRo : Model of the Environment and Temperature of Roads
# METRo is Free and is proudly provided by the Government of Canada
# Copyright (C) Her Majesty The Queen in Right of Canada, Environment Canada, 2006
# Copyright (C) Her Majesty The Queen in Right of Canada, Environment Canada, 2006
#
# Questions or bugs report: metro@ec.gc.ca
# METRo repository: https://framagit.org/metroprojects/metro
# Documentation: https://framagit.org/metroprojects/metro/wikis/home
#
#
# Code contributed by:
# Francois Fortin - Canadian meteorological center
#
# $LastChangedDate$
# $LastChangedRevision$
#
########################################################################
###################################################################################
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
......@@ -31,20 +29,20 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
#
# Every file in the source directories is listed separatly so that we don't
# include unwanted files. This way, we are forced to consider what goes in the
# package and what doesn't each time we make modifications. We don't blindly
# Every file in the source directories is listed separately so that we don't
# include unwanted files. This way, we are forced to consider what goes in the
# package and what doesn't each time we make modifications. We don't blindly
# add a directory with all the temporary and test files and it helps us to keep
# clean the distribution package.
#
import sys
import os
import re
sPackage_list = \
"""
"""
src/frontend/metro.py
src/frontend/metro_config.py
src/frontend/metro_logger.py
......@@ -144,42 +142,30 @@ README
LICENSE
INSTALL
setup.sh
"""
import string
import sys
import os
import re
import shutil
"""
VERSION_FILE = "../src/frontend/metro_config.py"
LINE_REGEX = 'CFG_METRO_VERSION\s*\=\s*[\"|\'][0-9]\.[0-9]\.[0-9][\"|\']'
VERSION_REGEX = '[0-9]\.[0-9]\.[0-9]'
def chomp(x):
while x != "" and x[-1] in "\r\n":
x = x[:-1]
return x
def extract_version_number( sFilename ):
def extract_version_number(sFilename):
sVersion_number = None
file = open(sFilename)
text = file.read()
file.close()
match_version_line =\
re.compile(LINE_REGEX)
match_version_line = re.compile(LINE_REGEX)
match_version_number = re.compile(VERSION_REGEX)
match_obj_version_line = match_version_line.search(text)
if match_obj_version_line:
start, stop = match_obj_version_line.span(0)
sVersion_line = text[start:stop]
......@@ -188,72 +174,62 @@ def extract_version_number( sFilename ):
start, stop = match_obj_version_number.span(0)
sVersion_number = sVersion_line[start:stop]
else:
print "Could not find the line containing the version number.\n" +\
"The regex is: '%s'." % LINE_REGEX
print("Could not find the line containing the version number.\n" + "The regex is: '%s'." % LINE_REGEX)
return sVersion_number
sVersion_number = extract_version_number(VERSION_FILE)
if not sVersion_number:
print "Could not find version number in file:'%s'. Aborting" % VERSION_FILE
print("Could not find version number in file:'%s'. Aborting" % VERSION_FILE)
sys.exit(1)
sMetro_dir = "metro-" + sVersion_number
# get path of metro parent directory
lPath = string.split(sys.path[0],"/")
lPath = sys.path[0].split("/")
sSvn_root_dir = lPath[-2]
sRoot_path = string.join(lPath[:-2],"/")
sMetro_real_dir = string.join(lPath[:-1],"/")
sPackage_path = string.join(lPath[:-2],"/")
sRoot_path = "/".join(lPath[:-2])
sMetro_real_dir = "/".join(lPath[:-1])
sPackage_path = "/".join(lPath[:-2])
# add leading metro directory name to each filename
sPackage_list = string.replace(sPackage_list,"\n","\n" + sSvn_root_dir + "/")
sPackage_list = sPackage_list.replace("\n", "\n" + sSvn_root_dir + "/")
# replace \n by a space character
sPackage_list = string.replace(sPackage_list,"\n"," ")
sPackage_list = sPackage_list.replace("\n", " ")
# remove any single sMetro_dir entry
sPackage_list = sPackage_list + " "
# do it 2 time (dirty hack)