Skip to content

Commit

Permalink
Fileparser2 (#26)
Browse files Browse the repository at this point in the history
* Rule class is created, third rule is developing.

* #18 rule defined, #14 rule formatting completed, #20 rule defined, #22 rule class is defined, #17 documentation is started. Ruff check and black check completed.

* #15 new rule implemented.

* #19 implemented (CALL JOB:TRIGGER around ARCON/ARCOFF commands)

* Script is modified to work on a multiple file (#24) and pre-commit created (#23)

* Test folder with two JBI files is created.

* Working on GitHub Actions.

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Update githubaction.yml

* Set USERFRAME bug is corrected.

* Extra test files are added.

* check_E (#15) bug is corrected.

* check_B (#11) bug is corrected.

* check_D (#18) int bug argument is corrected.

* Not UTF-8 encoded file handling is added.

* Error Flag is implemented.

* No Foldername is accepted.

* Black applied.

* Some reformating.

* Some reformating.

* Apply suggestions from code review

Co-authored-by: Çağtay Fabry <cagtay.fabry@bam.de>

* Files folder is deleted.

* check_D bug solved.

* check_D bug solved.

* Review notes are implemented and updated.

* Comments are corrected. Segmentation of the classes and error handling improved.

---------

Co-authored-by: Çağtay Fabry <cagtay.fabry@bam.de>
  • Loading branch information
barisccolak and CagtayFabry authored Oct 25, 2023
1 parent 037c8e7 commit b455372
Show file tree
Hide file tree
Showing 10 changed files with 580 additions and 118 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/githubaction.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run Fileparser over all the JOB Files
on:
push:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
run_fileparser:
name: Run Fileparser on JOB Files
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.10.12

- name: Run Python script on JOB files
run: |
find . -name "*.JBI" -exec python testmodule/fileparser.py {} \;
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black


ci:
autofix_commit_msg: |
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
autofix_prs: true
autoupdate_branch: ''
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
autoupdate_schedule: weekly
skip: []
submodules: false
90 changes: 17 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,28 @@


## Markdown links

1. [Basic Syntax](https://www.markdownguide.org/basic-syntax/)
2. [Advanced Syntax](https://daringfireball.net/projects/markdown/syntax)


## Git Commands

1. `git add . -n` : Shows the dry changes
2. `git add .` : Adds the changes
3. `git commit -m "message"` : Commits
4. `git <x> --help` : Documentation for x
5. `git --help` : Documentation for Git
6. `git push` : Pushes the commit
7. `git checkout branch_name` : Changes the branch
8. `git checkout -b branch_name` : Create and changes the branch
9. `git push --set-upstream origin sidebranch` : Pushes and sets upstream for current branch
10. `git status` : Shows the status
11. `git checkout -b <new-branch>` : Creates and changes to new branch


## Conda Commands

1. `conda create -n test-env <python=3.10 numpy pandas> -y` : Creates a test environment and installs the listed packages
2. `conda activate test-env`: Activates test environment
3. `conda list`: show all packages installed in the currently active environment
3. `conda list pandas`: show all packages that contain the name `pandas` installed in the currently active environment
3. `conda uninstall <package_name>`: uninstall a package from the envrionment
3. `conda env remove -n <envrionment_name>`: remove a conda environment completely


## Pip Commands

1. `pip install pint` : Install a package from the internet (PyPi)
1. `pip uninstall pint` : remove a package previously installed using `pip`
1. `pip install -e .` : Installs the local folder as python package

## Command Shell

1. `python`
2. `ipython`
2. `python -m ipykernel install --user --name test-env --display-name "test-env"`: register a conda environment as a jupyter kernel (you need this to make the environment selectable in Jupyter notebook)


## Ruff Commands

1. pip install ruff
2. ruff check .
3. ruff check --fix .
4. git diff : Shows the differences.
5.

***
## quickstart

This version of Fileparser contains two functions: `write` and `read`.
## quickstart
Fileparser package contains various rules to verify the a JBI data.

## user guide

### Installation

Install using `pip` locally:

`pip install -e .`
`pip install lorem`

### Writing a text file

To generate a text using `testmodule.write`:

`python -m testmodule.write`
Install the python package:

Give a path to create `text.txt`
pip install testmodule

### Reading a text file
To check the rules for a single `.JBI` file:

To read a text file use class method `testmodule.read`:
python fileparser.py <your-file>

`python -m testmodule.read`
To check the rules for all files in a folder:

Supply the path of the target file.
python fileparser.py <your-path>

## List of error codes

- w1 : job should start with a comment line
directly after the NOP statement.
- w2 : program command `SETREG MREG#` should only be allowed when the job is listed under `FOLDERNAME TWINCAT_KOMMUNIKATION`
- w3 : if the job is in the folder `STANDARD` or `MAIN`, the line `SET USERFRAME n` must be present, where n is any numerical value. The command `SET USERFRAME` must be executed before the command `CALL JOB:TRIGGER ARGF"PROGRAMM_EIN"` is called.
- w4 : if a the `TCPON` command is called, the previous line must be a call to CALL `JOB:SET_TCPON` with the same argument number in both cases.
- w5 : for all jobs in folder `MAIN`: The first program line (after initial comments) as well as the final program line should be `CALL JOB:TRIGGER_RESET`.
- w6 : `ARCON` and `ARCOFF` commands should be enclosed in a call of `CALL JOB:TRIGGER ARGF"SCHWEISSEN_EIN"` immediately before the `ARCON` command and a call to `CALL JOB:TRIGGER ARGF"SCHWEISSEN_AUS"` immediately after the `ARCOFF` command.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ select = [
]

[tool.ruff.pydocstyle]
convention = "numpy"
convention = "numpy"
50 changes: 50 additions & 0 deletions testmodule/CHECK_DOUBLE.JBI
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/JOB
//NAME CHECK_DOUBLE
///FOLDERNAME TWINCAT_KOMMUNIKATION
//POS
///NPOS 0,0,0,0,0,0
//ALIAS
///LVARS 1,0,3,0,0,0,0,0
LB000 STATUS
LD000 VALUE
LD001 LOW
LD002 HIGH
//ARGINFO
///ARGTYPE D,,,,,,,
///COMMENT
VALUE







//INST
///DATE 2020/06/24 14:11
///ATTR SC,RW
///LVARS 1,0,3,0,0,0,0,0
NOP
'--------------------------------
'Pr�ft ob Wert 1 im Wertebereich
'zwischen Wert 2 und Wert 3 liegt
'
' R�ckgabewert 0 wenn nicht
'R�ckgabewerte 1 bei Erfolg
'--------------------------------
'--------------------------------
'Einlesen der Argumente
'--------------------------------
GETARG VALUE IARG#(1)
GETARG LOW IARG#(2)
GETARG HIGH IARG#(3)
'--------------------------------
'Wertebereich pr�fen
SET STATUS 0
IFTHENEXP VALUE>=LOW
IFTHENEXP VALUE<=HIGH
SET STATUS 1
ENDIF
ENDIF
RET STATUS
END
Loading

0 comments on commit b455372

Please # to comment.