Skip to content

Commit

Permalink
test 1 (shhossain#720)
Browse files Browse the repository at this point in the history
* test 1

* fix test and cpp code
  • Loading branch information
shhossain authored Oct 31, 2023
1 parent c8aaab7 commit f789b74
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 112 deletions.
36 changes: 14 additions & 22 deletions .github/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import shutil
import re
import hashlib
from glob import glob


# this file is in .github\test_code.py
Expand Down Expand Up @@ -132,7 +133,12 @@ def error(*msg, **kwargs):
error_level[0] = max(error_level[0], level)
else:
kwargs.pop("threaded", None)
print(termcolor.colored(s, 'red'), **kwargs)
for m in msg:
if isinstance(m, tuple):
for mm in m:
print(termcolor.colored(mm, 'red'), **kwargs)
else:
print(termcolor.colored(m, 'red'), **kwargs)

@staticmethod
def warn(*msg, **kwargs):
Expand Down Expand Up @@ -384,6 +390,7 @@ def __init__(self, local_repo_path, remote_repo_url) -> None:
self.repo_name = remote_repo_url.split('/')[-1]
self.local_files_hash = {}
self.remote_files_hash = {}
self.file_path = {}
self.ignore_files = [".gitignore", ".git", ".github", "temp"]
self.clone_repo()

Expand All @@ -400,37 +407,21 @@ def get_files(self, path):
for root, dirs, file in os.walk(path):
dirs[:] = [d for d in dirs if d not in self.ignore_files]
for f in file:
files.append(os.path.join(root, f))
files.append(os.path.abspath(os.path.join(root, f)))
return files

def get_local_files(self) -> list:
# files = []
# for root, dirs, file in os.walk(self.local_repo_path):
# dirs[:] = [d for d in dirs if d not in self.ignore_files]
# for f in file:
# if not f.endswith('.md'):
# continue
# files.append(os.path.join(root, f))


def get_local_files(self) -> list:
return self.get_files(self.local_repo_path)

def get_remote_files(self) -> list:
# files = []
# for root, dirs, file in os.walk("temp"):
# dirs[:] = [d for d in dirs if d not in self.ignore_files]
# for f in file:
# if not f.endswith('.md'):
# continue
# files.append(os.path.join(root, f))
return self.get_files(os.path.join("temp", self.repo_name))

def compare(self):
local_files = self.get_local_files()
remote_files = self.get_remote_files()

# print("Local files", local_files)
# print("Remote files", remote_files)

threads = []
for file in local_files:
t = threading.Thread(target=self.get_hash, args=(file, "local"))
Expand Down Expand Up @@ -460,12 +451,12 @@ def compare(self):
# get modified files
for file in common_files:
if self.local_files_hash[file] != self.remote_files_hash[file]:
modified_files.append(file)
modified_files.append(self.file_path[file])

# get new files that are in local but not in remote
for file in self.local_files_hash.keys():
if not file in common_files:
new_files.append(file)
new_files.append(self.file_path[file])

Log.info("Files modified")
for mf in modified_files:
Expand All @@ -485,6 +476,7 @@ def get_hash(self, file, repo):
if repo == "local":
f = self.get_file_name(file)
self.local_files_hash[f] = file_hash
self.file_path[f] = file
else:
f = self.get_file_name(file)
self.remote_files_hash[f] = file_hash
Expand Down
Loading

0 comments on commit f789b74

Please sign in to comment.