Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
add an md5 dir_hash as a version to static files
Browse files Browse the repository at this point in the history
  • Loading branch information
jmancewicz committed Jul 13, 2016
1 parent 1c1119c commit 4494da7
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 31 deletions.
4 changes: 2 additions & 2 deletions digits/templates/error.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<html>
<head>
<link rel="icon" href="{{url_for('static', filename='images/nvidia.ico')}}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-theme.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css', ver=dir_hash) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-theme.min.css', ver=dir_hash) }}">
</head>

<body>
Expand Down
12 changes: 6 additions & 6 deletions digits/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
{% extends "layout.html" %}

{% block head %}
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery.time_filters.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/angular.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/ngStorage.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery.sparkline.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/home_app.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/table_selection.css') }}">
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery.time_filters.js', ver=dir_hash) }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/angular.min.js', ver=dir_hash) }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/ngStorage.min.js', ver=dir_hash) }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/jquery.sparkline.min.js', ver=dir_hash) }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/home_app.js', ver=dir_hash) }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/table_selection.css', ver=dir_hash) }}">

{% with namespace = "/jobs" %}
{% set room = "job_management" %}
Expand Down
32 changes: 16 additions & 16 deletions digits/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
<!doctype html>
<head>
<link rel="icon" href="{{url_for('static', filename='images/nvidia.ico')}}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-theme.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/c3.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css', ver=dir_hash) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-theme.min.css', ver=dir_hash) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css', ver=dir_hash) }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/c3.min.css', ver=dir_hash) }}">
<title>{% block title %}DIGITS{% endblock %}</title>

<script src="{{ url_for('static', filename='js/jquery-1.11.1.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/bootbox.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/digits.js') }}"></script>
<script src="{{ url_for('static', filename='js/d3.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/c3.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.autocomplete.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/file_field.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery-1.11.1.min.js', ver=dir_hash) }}"></script>
<script src="{{ url_for('static', filename='js/bootstrap.min.js', ver=dir_hash) }}"></script>
<script src="{{ url_for('static', filename='js/bootbox.min.js', ver=dir_hash) }}"></script>
<script src="{{ url_for('static', filename='js/digits.js', ver=dir_hash) }}"></script>
<script src="{{ url_for('static', filename='js/d3.min.js', ver=dir_hash) }}"></script>
<script src="{{ url_for('static', filename='js/c3.min.js', ver=dir_hash) }}"></script>
<script src="{{ url_for('static', filename='js/jquery.autocomplete.min.js', ver=dir_hash) }}"></script>
<script src="{{ url_for('static', filename='js/file_field.js', ver=dir_hash) }}"></script>

<script src="{{ url_for('static', filename='js/ace/ace.js') }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/mode-python.js') }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/mode-lua.js') }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/theme-chrome.js') }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/ace.js', ver=dir_hash) }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/mode-python.js', ver=dir_hash) }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/mode-lua.js', ver=dir_hash) }}" type="text/javascript" charset="utf-8"></script>
<script src="{{ url_for('static', filename='js/ace/theme-chrome.js', ver=dir_hash) }}" type="text/javascript" charset="utf-8"></script>
{% block head %}
{% endblock %}
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% block job_content %}

<script src="{{ url_for('static', filename='js/jquery.elevateZoom.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.elevateZoom.min.js', ver=dir_hash) }}"></script>

<div class="page-header">
<h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% endblock %}

{% block head %}
<script src="{{ url_for('static', filename='js/model-graphs.js') }}"></script>
<script src="{{ url_for('static', filename='js/model-graphs.js', ver=dir_hash) }}"></script>
{% endblock %}

{% block nav %}
Expand Down
2 changes: 1 addition & 1 deletion digits/templates/models/images/classification/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% block job_content %}

<script src="{{ url_for('static', filename='js/model-graphs.js') }}"></script>
<script src="{{ url_for('static', filename='js/model-graphs.js', ver=dir_hash) }}"></script>

{% set task = job.train_task() %}

Expand Down
2 changes: 1 addition & 1 deletion digits/templates/models/images/generic/infer_one.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% block job_content %}

<script src="{{ url_for('static', filename='js/jquery.elevateZoom.min.js') }}"></script>
<script src="{{ url_for('static', filename='js/jquery.elevateZoom.min.js', ver=dir_hash) }}"></script>

<div class="page-header">
<h1>
Expand Down
2 changes: 1 addition & 1 deletion digits/templates/models/images/generic/large_graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% endblock %}

{% block head %}
<script src="{{ url_for('static', filename='js/model-graphs.js') }}"></script>
<script src="{{ url_for('static', filename='js/model-graphs.js', ver=dir_hash) }}"></script>
{% endblock %}

{% block nav %}
Expand Down
2 changes: 1 addition & 1 deletion digits/templates/models/images/generic/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% block job_content %}

<script src="{{ url_for('static', filename='js/model-graphs.js') }}"></script>
<script src="{{ url_for('static', filename='js/model-graphs.js', ver=dir_hash) }}"></script>

{% set task = job.train_task() %}

Expand Down
28 changes: 27 additions & 1 deletion digits/utils/filesystem.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright (c) 2014-2016, NVIDIA CORPORATION. All rights reserved.
from __future__ import absolute_import

import hashlib
import os.path
import shutil
import platform
import re
import shutil

def get_tree_size(start_path):
"""
Expand Down Expand Up @@ -57,3 +59,27 @@ def tail(file, n=40):
tailing_lines.popleft()
output = ''.join(tailing_lines)
return output

def dir_hash(dir_name):
"""
Return a hash for the files in a directory tree, excluding hidden
files and directoies. If any files are renamed, added, removed, or
modified the hash will change.
"""
if not os.path.isdir(dir_name):
raise TypeError('{} is not a directory.'.format(dir_name))

md5 = hashlib.md5()
for root, dirs, files in os.walk(dir_name, topdown=True):
# Skip if the root has a hidden directory in its path
if not re.search(r'/\.', root):
for f in files:
# Skip if the file is hidden
if not f.startswith('.') and not re.search(r'/\.', f):
# Change the hash if the file name changes
file_name = os.path.join(root, f)
md5.update(hashlib.md5(file_name).hexdigest())
# Change the hash if the file content changes
data = open(file_name, 'rb').read()
md5.update(hashlib.md5(data).hexdigest())
return md5.hexdigest()
2 changes: 2 additions & 0 deletions digits/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .config import config_value
from digits import utils
from digits.utils import filesystem as fs
import digits.scheduler

### Create Flask, Scheduler and SocketIO objects
Expand All @@ -27,6 +28,7 @@
app.jinja_env.globals['server_version'] = digits.__version__
app.jinja_env.globals['caffe_version'] = config_value('caffe_root')['ver_str']
app.jinja_env.globals['caffe_flavor'] = config_value('caffe_root')['flavor']
app.jinja_env.globals['dir_hash'] = fs.dir_hash('digits/static')
app.jinja_env.filters['print_time'] = utils.time_filters.print_time
app.jinja_env.filters['print_time_diff'] = utils.time_filters.print_time_diff
app.jinja_env.filters['print_time_since'] = utils.time_filters.print_time_since
Expand Down

0 comments on commit 4494da7

Please sign in to comment.