forked from ddrdushy/FCC-Status
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathversion.py
executable file
·82 lines (69 loc) · 1.88 KB
/
version.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# Inspired by
# https://gitfu.wordpress.com/2008/05/25/git-describe-great-another-way-to-refer-to-commits/
# http://gitready.com/beginner/2009/02/03/tagging.html
versionFile = "version.js"
defaultRepo = "http://github.com/kgisl/FCC-Status"
#####################
## Get Version details
######################
import commands
status, repo = commands.getstatusoutput ("git ls-remote --get-url")
if status:
repo = defaultRepo
else:
#repo = repo.split (".git")[0]
import re
repo = re.sub('\.git$', '', repo)
status, version = commands.getstatusoutput ("git describe --tags --long")
if not status:
print ("Version: " + version)
else:
print "git describe returned bad status!"
version = "NA"
previous = None
try:
fo = open (versionFile, "r")
#print "Name of file opened ", fo.name
previous = fo.read()
#print (previous)
fo.close()
except:
print ("Creating new version file...")
######
# Is it really necessary to update?
######
if version == "NA":
pass
elif previous and previous.find (version) != -1:
print (versionFile + " already up-to-date!")
else:
####################
## build JS code
####################
fileContent = \
'''\n\
/*This file is auto-generated by the Python script version.py. */
\n\
\n\
$(document).ready(function() {\n\
var link = '<a href="https://github.com/kgisl/FCC-Status/issues/new" target="_blank">';\n\
'''
fileContent = fileContent + ' link += "' + version + '";\n'
#link += "Version 1.0";\n\
fileContent2 = \
''' link += '</a>';\n\
//console.log (link);\n\
$("#feedback").html(link);\n\
});\n\
'''
fileContent = fileContent + fileContent2
##################
## Just to be safe, we must backing up previous versionFile
##################
pass # Not yet implemented
fo = open (versionFile, "w+")
fo.write (fileContent)
#print (fileContent)
print (versionFile + " updated with " + version)
fo.close()