Skip to content

Commit

Permalink
more elegant use of array and best case scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
s-pace committed Oct 15, 2018
1 parent 311d011 commit 8813de6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions deployer/src/config_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@

def extract_root_from_input(input_string):
# We cant parse the url since user might have not enter a proper link
domain = re.match(".+?([^\/]\/(?!\/))", input_string) # extracting substring before the first isolated / (not //)

if input_string.endswith('/'): # We assume that the string is already the proper root
return input_string

domain = re.match(".+?([^\/]\/(?!\/))", input_string) # extracting substring before the first isolated / (not //)
try:
url_parsed = urlparse(input_string);
# Removing unused parameters
url_parsed._replace(params='', query='', fragment='')
path_splited = url_parsed.path.split('/')
path_length = len(path_splited)

# Path is redirecting to a page
if ('html' in path_splited[path_length - 1]):
if ('html' in path_splited[-1]):
url_parsed = url_parsed._replace(path='/'.join(path_splited[: -1]))
# Path note ending by /
elif (path_splited[path_length - 1]):
url_parsed = url_parsed._replace(path='/'.join(path_splited) + '/')
# We are fine
else:
pass
Expand Down

0 comments on commit 8813de6

Please sign in to comment.