Skip to content

Commit

Permalink
back to old python version for compatibilities
Browse files Browse the repository at this point in the history
  • Loading branch information
jszheng committed Dec 25, 2018
1 parent 157088f commit 34cec36
Showing 1 changed file with 18 additions and 33 deletions.
51 changes: 18 additions & 33 deletions pull_all.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,33 @@

path_done = set()


# copy from os.walk
def walk(top, onerror=None, followlinks=False):

top = os.fspath(top)
dirs = []
nondirs = []
walk_dirs = []

try:
scandir_it = os.scandir(top)
entries = list(scandir_it)
except OSError as error:
if onerror is not None:
onerror(error)
return

with scandir_it:
while True:
try:
try:
entry = next(scandir_it)
except StopIteration:
break
except OSError as error:
if onerror is not None:
onerror(error)
return

try:
is_dir = entry.is_dir()
except OSError:
# If is_dir() raises an OSError, consider that the entry is not
# a directory, same behaviour than os.path.isdir().
is_dir = False

if is_dir:
dirs.append(entry.name)
else:
nondirs.append(entry.name)
for entry in entries:
try:
is_dir = entry.is_dir()
except OSError:
is_dir = False

if is_dir:
dirs.append(entry.name)
else:
nondirs.append(entry.name)

############################################
#yield top, dirs, nondirs
# yield top, dirs, nondirs
if '.git' in dirs:
path_done.add(os.path.abspath(top))
print("[GIT]", top)
Expand All @@ -60,17 +45,17 @@ def walk(top, onerror=None, followlinks=False):
# Recurse into sub-directories
islink, join = os.path.islink, os.path.join
for dirname in dirs:
new_path = join(top, dirname)
if followlinks or not islink(new_path):
walk(new_path, onerror, followlinks)
new_path = join(top, dirname)
if followlinks or not islink(new_path):
walk(new_path, onerror, followlinks)


if __name__ == '__main__':
# deal with command line path
if len(sys.argv) > 1 :
paths = sys.argv[1:]
if len(sys.argv) > 1:
paths = sys.argv[1:]
script_path = sys.argv[0]
else: # or use current directory as default
else: # or use current directory as default
paths = ['.']

# iterate each top
Expand Down

0 comments on commit 34cec36

Please sign in to comment.