Skip to content

Commit c18e565

Browse files
Merge pull request avinashkranjan#207 from antrikshmisri/master
Added file change listen script
2 parents ae30d63 + d022aea commit c18e565

File tree

7 files changed

+99
-0
lines changed

7 files changed

+99
-0
lines changed

File-Change-Listen/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/venv
2+
/__pycache__

File-Change-Listen/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# File-Change
2+
3+
## About This Project
4+
This is a python script that keeps track of all files change in the current working directory
5+
6+
## How To Run
7+
8+
To run the script use following commands
9+
10+
11+
1. Run the installation script
12+
```bash
13+
python install.py
14+
```
15+
2. Enter the project directory where changes are to be listened
16+
```bash
17+
Enter installation directory: project_dir
18+
```
19+
3. goto your project directory
20+
```bash
21+
cd project_dir
22+
```
23+
24+
4. Run the python script to listen for changes
25+
```python
26+
python main.py
27+
```
28+

File-Change-Listen/filechange.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
from os import listdir
3+
from os.path import isfile, join
4+
import time
5+
mypath = os.getcwd()
6+
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
7+
def read_file():
8+
filecontent = []
9+
for file in onlyfiles:
10+
with open(onlyfiles[onlyfiles.index(file)], "r") as f:
11+
filecontent.append(f.readlines())
12+
return filecontent
13+
14+
def ischanged():
15+
changedfile = []
16+
print('Listening for changes....')
17+
initial = list(read_file())
18+
while True:
19+
current = list(read_file())
20+
changeditem = []
21+
previtem = []
22+
if(current != initial):
23+
24+
for ele in initial:
25+
if ele not in current:
26+
for item in ele:
27+
previtem.append(item)
28+
for ele in current:
29+
if ele not in initial:
30+
changeditem.append(ele)
31+
32+
# changedDiff = list(set(changeditem[0]) - set(previtem))
33+
# prevDiff = list(set(previtem) - set(changeditem[0]))
34+
for i in range(0 ,len(changeditem)):
35+
print('loop :-' , i)
36+
changedfile.append(onlyfiles[current.index(changeditem[i])])
37+
print('Changed file is:-' , changedfile)
38+
# print('changed lines are:- ' ,prevDiff,' -> ',changedDiff)
39+
initial = current
40+
41+
42+
43+

File-Change-Listen/install.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from shutil import copy , copyfile
2+
import os
3+
print(dir)
4+
files = ['filechange.py' , 'main.py']
5+
def copyfiles(file:str , dst:str):
6+
copy(file , dst)
7+
print('Installation Successful\n')
8+
9+
def installfiles():
10+
location = input('Enter installation directory: ')
11+
print('Installing Files')
12+
for file in files:
13+
print('Installing %s' % file)
14+
copyfiles(file , location)
15+
16+
17+
installfiles()

File-Change-Listen/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import filechange
2+
def init():
3+
filechange.ischanged()
4+
5+
if __name__ == '__main__':
6+
init()

File-Change-Listen/requirements.txt

Whitespace-only changes.

File-Change-Listen/samplefile.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# make changes to this file for testing
2+
This is sample file
3+
Deleted the line

0 commit comments

Comments
 (0)