Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
We're almost there! Let's wrap things up and discuss some ideas of how you can expand this project further.
-
0:00
All right, let's write these last two functions.
-
0:03
They're gonna be very similar, they're basically just mirrors of each other.
-
0:06
And so again I'm going to do these up here near the top,
-
0:09
just because they're not involved in a lot of the stuff.
-
0:13
So flask_template_prepare will take a string, and
-
0:17
we're gonna just do a bunch of transforms to the string.
-
0:20
So we're gonna do re.sub.
-
0:23
And we're going to escape any opening braces and any percent signs.
-
0:33
And then we're going to replace that with a less than and a percent sign.
-
0:38
We're gonna do that for all of string.
-
0:42
And then I can actually copy this and I'm gonna do, I need four.
-
0:46
Three, four.
-
0:48
Okay, on the second one here, we're gonna reverse this and
-
0:53
we're gonna do a percent sign and then a closing curly brace.
-
0:59
And that would go to a percent sign and a greater than symbol.
-
1:04
And then here we're gonna do two of those, which would go to two of these.
-
1:10
And here we'll go to two of those, which would go to two of these.
-
1:15
So we're basically just swapping each of these things around.
-
1:19
So now for, and we need to return the string.
-
1:26
So now for flask_template_repair,
-
1:31
we wanna do basically the same work but wanna do this in reverse, right?
-
1:34
So let's actually just copy this.
-
1:37
This might be a little faster.
-
1:39
It might not be too.
-
1:40
I'm not sure.
-
1:42
So here, let's just say that we're gonna take and turn that
-
1:47
into that.
-
1:51
And we actually shouldn't need to root.
-
1:55
We might need to escape these.
-
1:56
We shouldn't need to escape these over here.
-
2:00
So here we're going to do that and that goes to that and that.
-
2:04
That and that goes
-
2:09
to that and that.
-
2:14
And finally greater than, greater than goes to close close on curly braces.
-
2:21
So yeah.
-
2:24
So less 10% goes to {%, greater than goes to %} less than and
-
2:29
less than goes to {{ and greater than greater than goes to {{ and
-
2:35
greater than greater than goes to }} and return the string.
-
2:40
So for both of these it's just a bunch of reg x substitutions,
-
2:46
nothing ridiculously crazy.
-
2:48
We're just taking brace percent combos, turning them into chevron percent combos.
-
2:53
Double braces and two double chevrons, and
-
2:55
then we undo those things by swapping them back out.
-
2:58
We're already using them in our create_files function,
-
3:01
but we're not using create_files yet.
-
3:03
So we should create_files and we can do that right here.
-
3:07
We can do create_files and we wanna pass in the project_root,
-
3:11
the project_slug, and the project_name.
-
3:16
Now, assuming everything is done correctly, we should be able to use this.
-
3:20
So let's go ahead and test it out.
-
3:23
So python3 builder.py, I want to do this in
-
3:28
users/Kenneth/Projects/files_systems/de- mo/.
-
3:35
I wanna call this Demo Project, I'm gonna do this with a space in name now.
-
3:39
Says it created it, let's go over here and look.
-
3:42
We have demo, we have demo project, we certainly have thing.
-
3:47
I'm wanna look at this in here a little easier.
-
3:50
So that's demo_project, so let's look at app.py.
-
3:54
Yeah, that looks like our app.py.
-
3:56
We have the index.html and everything.
-
3:58
Cool, requirements has everything in there.
-
4:02
Let's look at the index template.
-
4:05
We can see that we have our demoproject.css, demoproject.js and
-
4:08
we have the correct curly braces and everything, so that's nice.
-
4:13
And if we were to look in say,
-
4:15
static css, demo_project.css, we have the demo project project.
-
4:20
Great, there's all of our stuff.
-
4:22
If we wanted to, we could install Flask and we could run our app right now, and
-
4:26
it would all work.
-
4:28
I'm sure you've seen places, and
-
4:30
I know I pointed a few, where this project could be improved and expanded.
-
4:33
You can add a licensed feature, so people can pick MIT, GPL,
-
4:36
BSD, or whatever license they wanted.
-
4:39
You can ask for their legal name, and
-
4:40
put it in the copyright notice, with their name and the date into each of the files.
-
4:44
You can create a placeholder readme file, for
-
4:46
the user to fill out with information about their project.
-
4:48
I'm sure there are many other improvements you all will come up with that I haven't
-
4:51
mentioned or even thought of.
-
4:52
If you do, share it in the community and let me know.
-
4:55
Thanks for learning about using Python to control your file system with me.
-
4:58
I know this is an area that I personally hadn't explored too much until recently,
-
5:02
but it's a really useful part of Python and very powerful.
-
5:05
Python gives me more and more reasons to use it every day.
-
5:07
I'll see you all next time.
You need to sign up for Treehouse in order to download course files.
Sign up