Skip to content

Commit

Permalink
scan gits recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
Pullusb committed Mar 28, 2024
1 parent cff1312 commit f14da42
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions snippets/dev/scan_git_folders_recursively.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## scan repositories in a directory recursively, printing git directory and the remote adress

import os
from pathlib import Path
import subprocess


### --- arguments (could be converted to argparse):

target_dir = 'Directory to scan'
cmd = 'git remote --v'

## --- /

target_dir = Path(target_dir)
cmd = cmd.strip().split(' ')
print('splitted command: ', cmd)
print(f'--- Scanning repos in: {target_dir}:\n')

for R,D,F in os.walk(target_dir):
for dir_name in D:
folder = Path(R, dir_name)

## Skip folder inside of .git and cache
if any(x in str(folder) for x in ('.git', '__pycache__')):
continue

if (folder / '.git').exists():
output = subprocess.check_output(cmd, cwd=str(folder))
output = output.decode()

## Possible Skip condition
# if not 'gitlab' in output:
# continue

print(f'Git: {folder}\n')
print('output: ', output)

print('Scan Done.')

0 comments on commit f14da42

Please sign in to comment.