Skip to content

Commit

Permalink
added new function-extractAssignedSring and edit example usage part o…
Browse files Browse the repository at this point in the history
…f README.md.
  • Loading branch information
Yoda-Canada committed Oct 16, 2021
1 parent 53d64b7 commit 862486d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Nirjas is a fully dedicated python library to extract the comments and source co
Apart from that the library serves you with all the required metadata about your Code, Comments and File(s)

## Requirements

- Python 3

Installing Python on Linux machines:
Expand Down Expand Up @@ -72,27 +73,29 @@ The Languages we support till now:
### Install using pip

You’ll need to make sure you have pip available. You can check this by running:

```sh
pip --version
```

If you installed Python from source, with an installer from python.org, you should already have pip. If you’re on Linux and installed using your OS package manager, you may have to install pip separately.

> Haven’t installed pip? Visit: [https://pip.pypa.io/en/stable/installing/ ](https://pip.pypa.io/en/stable/installing/ )
> Haven’t installed pip? Visit: [https://pip.pypa.io/en/stable/installing/ ](https://pip.pypa.io/en/stable/installing/)
Install the latest official release via pip. This is the best approach for most users. It will provide a stable version and are available for most platforms.

* Update pip to the latest stable version
- Update pip to the latest stable version

```sh
pip3 install --upgrade pip
```

* Install Nirjas
- Install Nirjas

```sh
pip3 install nirjas
```

- Upgrading Nirjas

Upgrade already installed Nirjas library to the latest version from [PyPI](https://pypi.org/).
Expand All @@ -105,32 +108,31 @@ pip3 install --upgrade Nirjas

If you are interested in contributing to [Nirjas](https://github.com/fossology/Nirjas) development, running the latest source code, or just like to build everything yourself, it is not difficult to install & build [Nirjas](https://github.com/fossology/Nirjas) from the source.

* Fork the [repo](https://github.com/fossology/Nirjas)
- Fork the [repo](https://github.com/fossology/Nirjas)

* Clone on your local system
- Clone on your local system

```sh
git clone https://github.com/fossology/Nirjas.git
```

* Change directory
- Change directory

```sh
cd Nirjas/
```

* Install the package
- Install the package

```sh
pip3 install .
```

> This will install Nirjas on your system.
- Check if Nirjas is installed correctly or get help, Run:

* Check if Nirjas is installed correctly or get help, Run:

`nirjas -h` or `nirjas --help`
`nirjas -h` or `nirjas --help`

## Example Usage

Expand All @@ -146,6 +148,12 @@ nirjas -h
nirjas -p <path to file>
```

- To extract strings which assigned to variables from a source code file

```sh
nirjas -p <path to source code file>
```

- To extract comments from all the files in directory/sub-directory

```sh
Expand All @@ -171,14 +179,14 @@ To run a test for Nirjas, execute the following script:
```sh
python3 testScript.py
```

This will download all the test files into `nirjas/languages/tests/TestFiles` folder and will run the tests as well.

## Documentation

We maintain our entire documentation at GitHub wiki.
Feel free to switch from `code` to `wiki` or just click here - [Nirjas Documentation](https://github.com/fossology/Nirjas/wiki)


## Contributing

All contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are welcome.
Expand All @@ -188,4 +196,5 @@ A detailed overview on how to contribute can be found in the [contributing guide
Feel free to ask questions or discuss suggestions on [Slack](https://fossology.slack.com/)

## License

This repository is licensed under the terms of [LGPL-2.1](/LICENSE). Check the [LICENSE](/LICENSE) file for more details.
24 changes: 23 additions & 1 deletion nirjas/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,37 @@ def readMultiLineDiff(file, startSyntax: str, endSyntax: str):
for idx, _ in enumerate(endLine):
line_of_comments = line_of_comments + (endLine[idx] - startLine[idx]) + 1
line_of_comments += len(output)
output = [s.strip(startSyntax).strip(endSyntax).strip() for s in output]
output = [s.strip(startSyntax).strip(endSyntax).strip()for s in output]
return startLine, endLine, output, line_of_comments, total_lines, blank_lines


def extractAssignedString(file):
'''
Read file line by line and match string type variable to get string.
Return the content of the string.
'''
content = []
regex = r'(?<=(=\s*[\'\"]))(.*?)(?=[\'\"])'
total_lines, line_of_assignedString = 0, 0
with open(file) as f:
for line_number, line in enumerate(f, start=1):
total_lines += 1
output = re.findall(regex, line, re.S)
if len(output) >= 2:
line_of_assignedString += 1
output = ''.join(output)
if output and len(output) > 1:
content.append([line_number, output.strip()])
line = line.strip()
return content, line_of_assignedString


class CommentSyntax:
'''
Class to hold various regex and helper functions based on comment format
used by a language.
'''

def __init__(self):
self.sign = None
self.pattern = None
Expand Down

0 comments on commit 862486d

Please sign in to comment.