[minor] fixed globals and patch for wsgi migration
diff --git a/patches/august_2013/p06_fix_sle_against_stock_entry.py b/patches/august_2013/p06_fix_sle_against_stock_entry.py
index 02588be..2e6c383 100644
--- a/patches/august_2013/p06_fix_sle_against_stock_entry.py
+++ b/patches/august_2013/p06_fix_sle_against_stock_entry.py
@@ -1,10 +1,9 @@
 import webnotes
 
-cancelled = []
-uncancelled = []
-
 def execute():
-	global cancelled, uncancelled
+	cancelled = []
+	uncancelled = []
+
 	stock_entries = webnotes.conn.sql("""select * from `tabStock Entry` 
 		where docstatus >= 1 and date(modified) >= "2013-08-16" 
 		and ifnull(production_order, '') != '' and ifnull(bom_no, '') != '' 
@@ -17,14 +16,12 @@
 					where voucher_type='Stock Entry' and voucher_no=%s
 					and is_cancelled='No'""", entry.name, as_dict=True)
 				if res:
-					make_stock_entry_detail(entry, res)
+					make_stock_entry_detail(entry, res, cancelled, uncancelled)
 				
 	if cancelled or uncancelled:
-		send_email()
+		send_email(cancelled, uncancelled)
 			
-def make_stock_entry_detail(entry, res):
-	global cancelled, uncancelled
-	
+def make_stock_entry_detail(entry, res, cancelled, uncancelled):
 	fg_item = webnotes.conn.get_value("Production Order", entry.production_order,
 		"production_item")
 	voucher_detail_entries_map = {}
@@ -87,9 +84,8 @@
 
 		uncancelled.append(se.doc.name)
 		
-def send_email():
+def send_email(cancelled, uncancelled):
 	from webnotes.utils.email_lib import sendmail_to_system_managers
-	global cancelled, uncancelled
 	uncancelled = "we have undone the cancellation of the following Stock Entries through a patch:\n" + \
 		"\n".join(uncancelled) if uncancelled else ""
 	cancelled = "and cancelled the following Stock Entries:\n" + "\n".join(cancelled) \
diff --git a/patches/october_2013/p04_wsgi_migration.py b/patches/october_2013/p04_wsgi_migration.py
new file mode 100644
index 0000000..ca73516
--- /dev/null
+++ b/patches/october_2013/p04_wsgi_migration.py
@@ -0,0 +1,30 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import webnotes
+import webnotes.utils
+import os
+
+def execute():
+	base_path = webnotes.utils.get_base_path()
+	
+	# Remove symlinks from public folder:
+	# 	- server.py
+	# 	- web.py
+	# 	- unsupported.html
+	# 	- blank.html
+	# 	- rss.xml
+	# 	- sitemap.xml
+	for file in ("server.py", "web.py", "unsupported.html", "blank.html", "rss.xml", "sitemap.xml"):
+		file_path = os.path.join(base_path, "public", file)
+		if os.path.exists(file_path):
+			os.remove(file_path)
+			
+	# Remove wn-web files
+	# 	- js/wn-web.js
+	# 	- css/wn-web.css
+	for file_path in (("js", "wn-web.js"), ("css", "wn-web.css")):
+		file_path = os.path.join(base_path, "public", *file_path)
+		if os.path.exists(file_path):
+			os.remove(file_path)	
\ No newline at end of file
diff --git a/patches/patch_list.py b/patches/patch_list.py
index a569385..92dd527 100644
--- a/patches/patch_list.py
+++ b/patches/patch_list.py
@@ -224,4 +224,5 @@
 	"patches.october_2013.p02_set_communication_status",
 	"patches.october_2013.p03_crm_update_status",
 	"execute:webnotes.delete_doc('DocType', 'Setup Control')",
+	"patches.october_2013.p04_wsgi_migration",
 ]
\ No newline at end of file
diff --git a/utilities/demo/make_demo.py b/utilities/demo/make_demo.py
index d335528..219ce86 100644
--- a/utilities/demo/make_demo.py
+++ b/utilities/demo/make_demo.py
@@ -75,7 +75,7 @@
 	
 	for i in xrange(runs_for):		
 		print current_date.strftime("%Y-%m-%d")
-		webnotes.utils.current_date = current_date
+		webnotes.local.current_date = current_date
 		
 		if current_date.weekday() in (5, 6):
 			current_date = webnotes.utils.add_days(current_date, 1)
diff --git a/utilities/demo/make_erpnext_demo.py b/utilities/demo/make_erpnext_demo.py
index d67fb5e..bc25d5e 100644
--- a/utilities/demo/make_erpnext_demo.py
+++ b/utilities/demo/make_erpnext_demo.py
@@ -6,8 +6,8 @@
 import utilities.demo.make_demo
 
 def make_demo_app(site=None):
-	webnotes.flags.mute_emails = 1
 	webnotes.init(site=site)
+	webnotes.flags.mute_emails = 1
 
 	utilities.demo.make_demo.make(reset=True, simulate=False)
 	# setup demo user etc so that the site it up faster, while the data loads