Skip to content

Commit

Permalink
Move included subdomain lists from data_files to package_data
Browse files Browse the repository at this point in the history
Data included under package_data is better suite for files that will be
referenced by code within the package. This is what Fierce does, so
let's use package_data.
  • Loading branch information
mschwager committed Jan 23, 2018
1 parent 1d6686c commit 7c666e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
34 changes: 14 additions & 20 deletions fierce.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,16 @@ def find_subdomain_list_file(filename):
#
# https://github.com/pypa/pip/blob/master/pip/commands/show.py
#
package_filename_path = os.path.join("lists", filename)
try:
fierce = pkg_resources.get_distribution('fierce')
except pkg_resources.DistributionNotFound:
full_package_path = pkg_resources.resource_filename(
'fierce',
package_filename_path
)
except ImportError:
return filename

if isinstance(fierce, pkg_resources.Distribution):
paths = []
if fierce.has_metadata('RECORD'):
lines = fierce.get_metadata_lines('RECORD')
paths = [l.split(',')[0] for l in lines]
paths = [os.path.join(fierce.location, p) for p in paths]
elif fierce.has_metadata('installed-files.txt'):
lines = fierce.get_metadata_lines('installed-files.txt')
paths = [l for l in lines]
paths = [os.path.join(fierce.egg_info, p) for p in paths]

for p in paths:
if filename == os.path.basename(p):
return p

# If we couldn't find anything just return the original list file
return filename
return full_package_path


def head_request(url, timeout=2):
Expand Down Expand Up @@ -186,7 +174,13 @@ def get_stripped_file_lines(filename):
"""
Return lines of a file with whitespace removed
"""
return [line.strip() for line in open(filename).readlines()]
try:
lines = [line.strip() for line in open(filename).readlines()]
except FileNotFoundError:
print("Could not find subdomain file '{}'".format(filename))
return []

return lines


def get_subdomains(subdomains, subdomain_filename):
Expand Down
8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
'fierce = fierce:main',
],
},
data_files=[
('lists', data_files_lists),
],
package_data={
'fierce': [
'lists/*',
]
},
)

0 comments on commit 7c666e4

Please sign in to comment.