Skip to content

Commit

Permalink
Change print statements to Python 3 style (function), for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
ffund committed Jun 1, 2023
1 parent adcfe63 commit 392acde
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 68 deletions.
4 changes: 2 additions & 2 deletions dist/client/adaptation/netflix_dash.py
Expand Up @@ -56,7 +56,7 @@ def get_rate_netflix(bitrates, current_buffer_occupancy, buffer_size=config_dash
# Calculate the current buffer occupancy percentage
try:
buffer_percentage = current_buffer_occupancy/buffer_size
print buffer_percentage
print(buffer_percentage)
except ZeroDivisionError:
config_dash.LOG.error("Buffer Size was found to be Zero")
return None
Expand Down Expand Up @@ -107,4 +107,4 @@ def netflix_dash(bitrates, dash_player, segment_download_rate, curr_bitrate, ave
state = "RUNNING"
else:
next_bitrate = get_rate_netflix(bitrates, available_video_segments, config_dash.NETFLIX_BUFFER_SIZE, rate_map)
return next_bitrate, rate_map, state
return next_bitrate, rate_map, state
6 changes: 3 additions & 3 deletions dist/client/buffer_test.py
Expand Up @@ -51,12 +51,12 @@ def run_test(segment_arrival_times=SEGMENT_ARRIVAL_TIMES):
db.write(segment)
break
if actual_time > arrival_time:
print "ERROR: Missed the time slot for segemt {}".format(count)
print("ERROR: Missed the time slot for segemt {}".format(count))
break
time.sleep(1)
if time.time() - start_time >= 40:
print "Killing the player after 40 seconds"
print("Killing the player after 40 seconds")
db.stop()


run_test()
run_test()
6 changes: 3 additions & 3 deletions dist/client/dash_buffer.py
Expand Up @@ -21,8 +21,8 @@ def __init__(self, video_length, segment_duration):
self.playback_start_time = None
self.playback_duration = video_length
self.segment_duration = segment_duration
#print "video_length = {}".format(video_length)
#print "segment_duration = {}".format(segment_duration)
#print("video_length = {}".format(video_length))
#print("segment_duration = {}".format(segment_duration))
# Timers to keep track of playback time and the actual time
self.playback_timer = StopWatch()
self.actual_start_time = None
Expand Down Expand Up @@ -253,4 +253,4 @@ def log_entry(self, action, bitrate=0):
result_writer.writerow(header_row)
result_writer.writerow(str_stats)
config_dash.LOG.info("BufferStats: EpochTime=%s,CurrentPlaybackTime=%s,CurrentBufferSize=%s,"
"CurrentPlaybackState=%s,Action=%s,Bitrate=%s" % tuple(str_stats))
"CurrentPlaybackState=%s,Action=%s,Bitrate=%s" % tuple(str_stats))
52 changes: 26 additions & 26 deletions dist/client/dash_client.py
Expand Up @@ -67,7 +67,7 @@ def __init__(self):

def get_mpd(url):
""" Module to download the MPD from the URL and save it to file"""
print url
print(url)
try:
connection = urllib2.urlopen(url, timeout=10)
except urllib2.HTTPError, error:
Expand All @@ -76,7 +76,7 @@ def get_mpd(url):
except urllib2.URLError:
error_message = "URLError. Unable to reach Server.Check if Server active"
config_dash.LOG.error(error_message)
print error_message
print(error_message)
return None
except IOError, httplib.HTTPException:
message = "Unable to , file_identifierdownload MPD file HTTP Error."
Expand Down Expand Up @@ -138,8 +138,8 @@ def download_segment(segment_url, dash_folder):
break
connection.close()
segment_file_handle.close()
#print "segment size = {}".format(segment_size)
#print "segment filename = {}".format(segment_filename)
#print("segment size = {}".format(segment_size))
#print("segment filename = {}".format(segment_filename))
return segment_size, segment_filename


Expand Down Expand Up @@ -173,9 +173,9 @@ def make_sure_path_exists(path):

def print_representations(dp_object):
""" Module to print the representations"""
print "The DASH media has the following video representations/bitrates"
print("The DASH media has the following video representations/bitrates")
for bandwidth in dp_object.video:
print bandwidth
print(bandwidth)


def start_playback_smart(dp_object, domain, playback_type=None, download=False, video_segment_duration=None):
Expand Down Expand Up @@ -211,12 +211,12 @@ def start_playback_smart(dp_object, domain, playback_type=None, download=False,
dp_object.video[bitrate].initialization = dp_object.video[bitrate].initialization.replace(
"$Bandwidth$", str(bitrate))
media_urls = [dp_object.video[bitrate].initialization] + dp_object.video[bitrate].url_list
#print "media urls"
#print media_urls
#print("media urls")
#print(media_urls)
for segment_count, segment_url in enumerate(media_urls, dp_object.video[bitrate].start):
# segment_duration = dp_object.video[bitrate].segment_duration
#print "segment url"
#print segment_url
#print("segment url")
#print(segment_url)
dp_list[segment_count][bitrate] = segment_url
bitrates = dp_object.video.keys()
bitrates.sort()
Expand Down Expand Up @@ -248,8 +248,8 @@ def start_playback_smart(dp_object, domain, playback_type=None, download=False,
if segment_number > int(SEGMENT_LIMIT):
config_dash.LOG.info("Segment limit reached")
break
print "segment_number ={}".format(segment_number)
print "dp_object.video[bitrate].start={}".format(dp_object.video[bitrate].start)
print("segment_number ={}".format(segment_number))
print("dp_object.video[bitrate].start={}".format(dp_object.video[bitrate].start))
if segment_number == dp_object.video[bitrate].start:
current_bitrate = bitrates[0]
else:
Expand Down Expand Up @@ -307,16 +307,16 @@ def start_playback_smart(dp_object, domain, playback_type=None, download=False,
current_bitrate, average_dwn_time = basic_dash.basic_dash(segment_number, bitrates, average_dwn_time,
segment_download_time, current_bitrate)
segment_path = dp_list[segment][current_bitrate]
#print "domain"
#print domain
#print "segment"
#print segment
#print "current bitrate"
#print current_bitrate
#print segment_path
#print("domain")
#print(domain)
#print("segment")
#print(segment)
#print("current bitrate")
#print(current_bitrate)
#print(segment_path)
segment_url = urlparse.urljoin(domain, segment_path)
#print "segment url"
#print segment_url
#print("segment url")
#print(segment_url)
config_dash.LOG.info("{}: Segment URL = {}".format(playback_type.upper(), segment_url))
if delay:
delay_start = time.time()
Expand All @@ -327,10 +327,10 @@ def start_playback_smart(dp_object, domain, playback_type=None, download=False,
config_dash.LOG.debug("SLEPT for {}seconds ".format(time.time() - delay_start))
start_time = timeit.default_timer()
try:
#print 'url'
#print segment_url
#print 'file'
#print file_identifier
#print('url')
#print(segment_url)
#print('file')
#print(file_identifier)
segment_size, segment_filename = download_segment(segment_url, file_identifier)
config_dash.LOG.info("{}: Downloaded segment {}".format(playback_type.upper(), segment_url))
except IOError, e:
Expand Down Expand Up @@ -501,7 +501,7 @@ def main():
configure_log_file(playback_type=PLAYBACK.lower())
config_dash.JSON_HANDLE['playback_type'] = PLAYBACK.lower()
if not MPD:
print "ERROR: Please provide the URL to the MPD file. Try Again.."
print("ERROR: Please provide the URL to the MPD file. Try Again..")
return None
config_dash.LOG.info('Downloading MPD file %s' % MPD)
# Retrieve the MPD files for the video
Expand Down
18 changes: 9 additions & 9 deletions dist/client/read_mpd.py
Expand Up @@ -111,7 +111,7 @@ def get_url_list(media, segment_duration, playback_duration, bitrate):
total_playback += segment_duration
elif FORMAT == 1:
media.url_list = URL_LIST
#print media.url_list
#print(media.url_list)
return media


Expand Down Expand Up @@ -139,7 +139,7 @@ def read_mpd(mpd_file, dashplayback):
elif "Period" in get_tag_name(root[1].tag):
child_period = root[1]
FORMAT = 1
#print child_period
#print(child_period)
video_segment_duration = None
if FORMAT == 0:
for adaptation_set in child_period:
Expand Down Expand Up @@ -206,8 +206,8 @@ def read_mpd(mpd_file, dashplayback):
media_object[bandwidth].base_url = root[0].text
tempcut_url = root[0].text.split('/',3)[2:]
cut_url = tempcut_url[1]
print "cut_url = {}".format(cut_url)
#print root[0].text
print("cut_url = {}".format(cut_url))
#print(root[0].text)
for segment_info in representation:
if "SegmentBase" in get_tag_name(segment_info.tag):
for init in segment_info:
Expand All @@ -223,22 +223,22 @@ def read_mpd(mpd_file, dashplayback):
Ssize = segment_URL.attrib['media'].split('/')[0]
Ssize = Ssize.split('_')[-1];
Ssize = Ssize.split('kbit')[0];
#print "ssize"
#print Ssize
#print("ssize")
#print(Ssize)
segment_size = float(Ssize) * float(
SIZE_DICT["Kbits"])
except KeyError, e:
config_dash.LOG.error("Error in reading Segment sizes :{}".format(e))
continue
segurl = cut_url + segment_URL.attrib['media']
#print segurl
#print(segurl)
URL_LIST.append(segurl)
media_object[bandwidth].segment_sizes.append(segment_size)



else:

print "Error: UknownFormat of MPD file!"
print("Error: UknownFormat of MPD file!")

return dashplayback, int(video_segment_duration)
return dashplayback, int(video_segment_duration)
2 changes: 1 addition & 1 deletion dist/server/bandwidth_changer.py
Expand Up @@ -16,7 +16,7 @@ def update_tc():
next = gauss(GAUSS_MU, GAUSS_SIGMA)
tc_command = TC_COMMAND_TEMPLATE.format(next)
current_time = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
print current_time, " : ", tc_command
print(current_time, " : ", tc_command)
sys.stdout.flush()
tc_command = tc_command.split()
subprocess.call(tc_command)
Expand Down
26 changes: 13 additions & 13 deletions dist/server/dash_server.py
Expand Up @@ -99,10 +99,10 @@ def do_GET(self):
dir_listing = list_directory(request)
duration = dir_write(self.wfile, dir_listing)
elif request in HTML_PAGES:
print "Request HTML %s" % request
print("Request HTML %s" % request)
duration = normal_write(self.wfile, request)
elif request in MPD_FILES:
print "Request for MPD %s" % request
print("Request for MPD %s" % request)
duration = normal_write(self.wfile, request) #, **kwargs)
# assuming that the new session always
# starts with the download of the MPD file
Expand All @@ -111,7 +111,7 @@ def do_GET(self):
if connection_id in ACTIVE_DICT:
del (ACTIVE_DICT[connection_id])
elif request.split('.')[-1] in ['m4f', 'mp4']:
print "Request for DASH Media %s" % request
print("Request for DASH Media %s" % request)
if connection_id not in ACTIVE_DICT:
ACTIVE_DICT[connection_id] = {
'file_list': [os.path.basename(request)],
Expand All @@ -121,14 +121,14 @@ def do_GET(self):
os.path.basename(request))

duration, file_size = normal_write(self.wfile, request)
print 'Normal: Request took {} seconds for size of {}'.format(duration, file_size)
print('Normal: Request took {} seconds for size of {}'.format(duration, file_size))

# if ACTIVE_DICT[connection_id]['iter'].next() == 0:
# duration = slow_write(output=self.wfile, request=request, rate=SLOW_RATE)
# print 'Slow: Request took %f seconds' % duration
# print('Slow: Request took %f seconds' % duration)
# else:
# duration = normal_write(self.wfile, request)
# print 'Normal: Request took %f seconds' % duration
# print('Normal: Request took %f seconds' % duration)
else:
self.send_error(404)
return
Expand Down Expand Up @@ -178,15 +178,15 @@ def slow_write(output, request, rate=None):
"""Function to write the video onto output stream with interruptions in
the stream
"""
print "Slow write of %s" % request
print("Slow write of %s" % request)
with open(request, 'r') as request_file:
start_time = time.time()
data = request_file.read(BLOCK_SIZE)
output.write(data)
last_send = time.time()
current_stream = len(data)
while data != '':
print "In loop"
print("In loop")
if rate:
if curr_send_rate(BLOCK_SIZE, last_send - time.time()) > rate:
continue
Expand All @@ -198,8 +198,8 @@ def slow_write(output, request, rate=None):
data = request_file.read(BLOCK_SIZE)
now = time.time()
output.flush()
print 'Served %d bytes of file: %s in %f seconds' % (
current_stream, request, now - start_time)
print('Served %d bytes of file: %s in %f seconds' % (
current_stream, request, now - start_time))
return now - start_time


Expand All @@ -222,8 +222,8 @@ def start_server():
""" Module to start the server"""
http_server = BaseHTTPServer.HTTPServer((HOSTNAME, PORT),
MyHTTPRequestHandler)
print " ".join(("Listening on ", HOSTNAME, " at Port ",
str(PORT), " - press ctrl-c to stop"))
print(" ".join(("Listening on ", HOSTNAME, " at Port ",
str(PORT), " - press ctrl-c to stop")))
# Use this Version of HTTP Protocol
http_server.protocol_version = HTTP_VERSION
http_server.serve_forever()
Expand Down Expand Up @@ -252,7 +252,7 @@ def main():
parser = ArgumentParser(description='Process server parameters')
create_arguments(parser)
args = parser.parse_args()
#print "Len of args", len(args)
#print("Len of args", len(args))
update_config(args)
start_server()

Expand Down
4 changes: 2 additions & 2 deletions dist/server/list_directory.py
Expand Up @@ -16,10 +16,10 @@ def list_directory(path):
From SimpleHTTPServer.py
"""
print "Get DIR listing for ", path
print("Get DIR listing for ", path )
try:
dir_list = os.listdir(path)
print "The path for ", path, " is ", list
print("The path for ", path, " is ", list)
except os.error:
response = "404 No permission to list directory"
dir_list.sort(key=lambda a: a.lower())
Expand Down
8 changes: 4 additions & 4 deletions dist/server/list_filesize.py
Expand Up @@ -27,7 +27,7 @@ def create_filelist(list_filename=LIST_FILE, path="."):
try:
list_file = open(list_filename, 'w')
except IOError:
print "Unable to open file: ", list_filename
print("Unable to open file: ", list_filename)
return None
for file_path, size in get_filesize(path):
list_file.write(" ".join((file_path, str(size), "\n")))
Expand All @@ -44,12 +44,12 @@ def main():
create_arguments(parser)
args = parser.parse_args()
if not args.list_file or not args.path:
print "Please Eneter the list_file and path.\n Exitting..."
print args.list_file, args.path
print("Please Eneter the list_file and path.\n Exitting...")
print(args.list_file, args.path)
return
list_file = args.list_file
path = args.path
print "list_file", list_file, 'path', path
print("list_file", list_file, 'path', path)
create_filelist(list_file, path)

if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions dist/server/parserXml.py
Expand Up @@ -4,12 +4,12 @@
xmldoc = minidom.parse("C:\\Users\\pjuluri\\Documents\\GitHub\\AStream\\dist\\server\\media\\mpd\\x4ukwHdACDw.mpd")
itemlist = xmldoc.getElementsByTagName('Representation')

print ("Number of itens: " , len(itemlist))
#print len(itemlist)
#print itemlist[0].attributes['id'].value
print("Number of itens: " , len(itemlist))
#print(len(itemlist))
#print(itemlist[0].attributes['id'].value)
for s in itemlist:
print (s.attributes['id'].value , s.attributes['bandwidth'].value)
#print s.attributes['bandwidth'].value
print(s.attributes['id'].value , s.attributes['bandwidth'].value)
#print(s.attributes['bandwidth'].value)

#dom1 = parse('C:\\Users\\Thiago\\Desktop\\teste\\xml.mpd')

Expand Down

0 comments on commit 392acde

Please sign in to comment.