Skip to content

Commit b9f48b6

Browse files
committed
2 parents d59a6fa + 5fd88dd commit b9f48b6

File tree

2 files changed

+130
-38
lines changed

2 files changed

+130
-38
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/python
2+
3+
import os
4+
import sys
5+
6+
filename = sys.argv[1:]
7+
8+
def renamer(file_to_be_renamed):
9+
10+
path = os.getcwd()
11+
12+
files = os.listdir(path)
13+
14+
if file_to_be_renamed in files:
15+
16+
new_name = raw_input( "The current filename is {}, what would you like to call it instead? ".format(file_to_be_renamed))
17+
18+
os.rename(file_to_be_renamed, new_name)
19+
20+
else:
21+
print "It doesn't look like that file is present"
22+
23+
map(renamer,filename)
24+
25+
26+
###UNUSED CODE FROM BEFORE I READ THE ASSIGNMENT ALL THE WAY###
27+
28+
29+
#print filename
30+
31+
#path = os.getcwd()
32+
#
33+
#files = os.listdir(path)
34+
#
35+
#count = 1
36+
#file_dict = {}
37+
#while count<=len(files):
38+
#
39+
# for i in files:
40+
# file_dict[count] = i
41+
# #print str(count) + ': '+ i
42+
# count = count + 1
43+
#
44+
#for key, value in file_dict.iteritems():
45+
# print key, value
46+
#
47+
#which_file = raw_input('\nWhich file would you like to rename? Please use the integer value. ')
48+
#
49+
#which_file = int(which_file)
50+
#
51+
#"print file_dict[which_file]
52+
#
53+
#file_to_be_renamed = file_dict[which_file]
54+
#
55+
#new_name = raw_input( "The current filename is {}, what would you like to call it instead? ".format(file_to_be_renamed))
56+
#
57+
#os.rename(file_to_be_renamed, new_name)
58+
#
59+
#
Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#!/usr/bin/python
22

3-
class element(object):
4-
tag = 'html'
3+
class Element(object):
54

5+
#tag = 'html'
66
indent = ' '
7-
87
def __init__(self, content=None, **attributes):
9-
8+
109
self.content = []
10+
11+
self.attributes = attributes
1112

1213
if content is not None:
14+
1315
self.content.append(content)
14-
self.attributes = attributes
15-
def append(self, content):
16+
def append(self, content):
1617

1718
self.content.append(content)
1819

1920
def render_tag(self, current_ind):
2021

2122
attrs = "".join([' {}={}'.format(key,val) for key, val in self.attributes.items()])
2223

23-
tag_str = "{}<{}{}>").format(current_ind,self.tag, attrs)
24+
tag_str = "{}<{}{}>".format(current_ind,self.tag,attrs)
2425

2526
return tag_str
2627

@@ -29,72 +30,104 @@ def render(self, file_out, current_ind=""):
2930
file_out.write(self.render_tag(current_ind))
3031
file_out.write('\n')
3132

32-
for c in self.content:
33+
for con in self.content:
3334
try:
3435
file_out.write(current_ind + self.indent + con + '\n')
36+
3537
except TypeError:
3638
con.render(file_out, current_ind + self.indent)
3739

38-
file_out.write("{}<{}> + \n".format(current_ind, self.tag))
39-
40-
41-
class Html(element):
40+
file_out.write("{}</{}> \n".format(current_ind, self.tag))
4241

42+
class Html(Element):
4343
tag = 'html'
44+
def render(self, file_out,current_ind=""):
4445

45-
class Body(element):
46+
file_out.write("<!DOCTYPE html>\n")
47+
Element.render(self,file_out, current_ind=current_ind)
4648

49+
class Body(Element):
4750
tag = 'body'
48-
49-
class P(element):
50-
51+
52+
class P(Element):
5153
tag = 'p'
5254

53-
class Head(element):
54-
55+
class Head(Element):
5556
tag = 'head'
56-
57-
class OneLineTag(element):
58-
57+
58+
class OneLineTag(Element):
59+
5960
def render(self, file_out, current_ind=""):
6061

6162
file_out.write(self.render_tag(current_ind))
62-
63-
for c in self.content:
64-
file_out.write(con)
6563

66-
file_out.write("</{}>\n").format(self.tag))
64+
for con in self.content:
65+
file_out.write(con)
66+
67+
file_out.write("</{}> \n".format(self.tag))
68+
69+
class Title(OneLineTag):
6770

68-
class SelfClosingTag(OneLineTag):
71+
tag = 'title'
72+
73+
class SelfClosingTag(Element):
6974

75+
def render_tag(self, current_ind):
76+
77+
attrs = "".join([' {}={}'.format(key,val) for key, val in self.attributes.items()])
78+
79+
tag_str = "{}<{}{} />".format(current_ind,self.tag,attrs)
80+
81+
return tag_str
82+
7083
def render(self, file_out, current_ind=""):
84+
7185
file_out.write(self.render_tag(current_ind))
72-
file_out.write(" />\n")
7386

87+
for con in self.content:
88+
try:
89+
file_out.write(current_ind + self.indent + con)
7490

75-
class Hr(SelfClosingTag):
91+
except TypeError:
92+
con.render(file_out, current_ind + self.indent)
7693

94+
#file_out.write("{}</{}> \n".format(current_ind, self.tag))
95+
file_out.write("\n")
7796

7897

79-
class title(OneLineTag):
98+
class Hr(SelfClosingTag):
99+
tag = 'hr'
80100

81-
tag = 'title'
101+
class Br(SelfClosingTag):
102+
tag = 'br'
82103

83104
class A(OneLineTag):
84105
tag = 'a'
85-
def __init__(self, link, content):
86-
OneLineTag.___init__(self, content=None, **attributes)
106+
107+
def __init__(self, link, content=None, **attributes):
108+
109+
OneLineTag.__init__(self, content, **attributes)
87110
self.attributes["href"] = link
88-
111+
112+
class Ul(Element):
113+
114+
tag = 'ul'
115+
116+
class Li(Element):
117+
118+
tag = 'li'
119+
89120
class H(OneLineTag):
90121

91122
tag = 'h'
92-
123+
93124
def __init__(self, level, content=None, **attributes):
125+
126+
OneLineTag.__init__(self, content, **attributes)
94127
self.tag = 'h{}'.format(level)
95128

96-
class Ul(element):
97-
tag = 'ul'
129+
class Meta(SelfClosingTag):
98130

99-
class li(element):
100-
tag = 'li'
131+
tag = 'meta'
132+
133+

0 commit comments

Comments
 (0)