-
-
Save Jee-Bee/44936dcabc45d83829f3ced4a5602cb6 to your computer and use it in GitHub Desktop.
Convert Payrus SysML1.4 projects to SysML1.6 Projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Mar 30 18:09:37 2022 | |
@author: jbtw | |
Convert Papyrus SysMl1.4 project to SysML1.6 Project | |
""" | |
import sys | |
import os | |
import os.path as path | |
import shutil | |
def convertsysml(cpname, npname, fpath, copy=True): | |
"""Convert SysML | |
convertsysml convert a sysml1.4 project to a 1.6 project | |
Inputs: | |
- cpname = current project name | |
- npname = new project name | |
- fpath = filepath or current location to be desided | |
- copy = make copy of the project(default=True) | |
Outputs: | |
- new project in sysML 1.6 format | |
""" | |
print("Path to project is: {}".format(fpath)) | |
# copy structure | |
spath = path.join(fpath, cpname) | |
dpath = path.join(fpath, npname) | |
shutil.copytree(spath, dpath) | |
for root, dirs, files in os.walk(dpath): | |
for file in files: | |
if file == '.project': | |
(file, path.splitext(file)[1]) | |
# replace project name in .project file | |
with open(path.join(dpath, file), 'r+') as rf: | |
fdata = rf.read() | |
fdata = fdata.replace(cpname, npname) | |
rf.seek(0) | |
rf.write(fdata) | |
rf.truncate() | |
elif path.splitext(file)[1] == ".properties": | |
text_locale = path.splitext(file.rsplit(cpname)[1])[0] | |
os.rename(path.join(dpath, cpname + text_locale + path.splitext(file)[1]), path.join(dpath, npname + text_locale + path.splitext(file)[1])) | |
else: | |
nfile = path.join(dpath, npname + path.splitext(file)[1]) | |
os.rename(path.join(dpath, cpname + path.splitext(file)[1]), nfile) | |
# replac | |
with open(path.join(dpath, nfile), 'r+') as rf: | |
fdata = rf.read() | |
# replace project name in file | |
print("Replacing filename references /n") | |
fdata = fdata.replace(cpname, npname) | |
# replace SysML 1.4 references in file | |
print("Replacing SysML references /n") | |
fdata = fdata.replace('sysml/1.4', 'sysml/1.6') | |
fdata = fdata.replace('SysML14', 'SysML16') | |
rf.seek(0) | |
rf.write(fdata) | |
rf.truncate() | |
if __name__ == '__main__': | |
print(sys.argv, len(sys.argv)) | |
if len(sys.argv) == 5: | |
project14 = sys.argv[1] | |
project16 = sys.argv[2] | |
fpath = sys.argv[3] | |
copyfolder = sys.argv[4] | |
convertsysml(project14, project16, fpath, copyfolder) | |
elif len(sys.argv) == 4: | |
project14 = sys.argv[1] | |
project16 = sys.argv[2] | |
fpath = sys.argv[3] | |
convertsysml(project14, project16, fpath) | |
elif len(sys.argv) == 3: | |
project14 = sys.argv[1] | |
project16 = sys.argv[2] | |
fpath = os.getcwd() | |
convertsysml(project14, project16, fpath) | |
else: | |
raise ValueError("Wrong number of parameters given. At least 2 parameters are required and {} are given".format(len(sys.argv) - 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment