-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathis_rails_file.py
32 lines (27 loc) · 932 Bytes
/
is_rails_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def is_rails_file(file_name):
try:
# check to see if os.path has already been imported
# this just needs to be something simple that will
# raise an exception if it fails
os.path.supports_unicode_filenames
except Exception:
import os.path
path = os.path.dirname(file_name)
file_name = os.path.basename(file_name).lower()
name, extension = os.path.splitext(file_name)
if name == 'gemfile':
return True
result = False
# I doubt this is the most elegant way of identifying a Rails directory structure,
# but it does work. The idea here is to work up the tree, checking at each level for
# the existence of config/routes.rb. If it's found, the assumption is made that it's
# a Rails app.
while path != '':
if os.path.exists(path + '\\config\\routes.rb'):
result = True
break
else:
dirs = path.split('\\')
dirs.pop()
path = '\\'.join(dirs)
return extension in ['.rb', '.rake'] and result