[MediaWiki-commits] [Gerrit] mediawiki...MinervaNeue[master]: Add migration script

2017-06-30 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/356633 )

Change subject: Add migration script
..


Add migration script

Bug: T166744
Change-Id: I6466a72bc32916a7e3092b24e61961f8d422ed88
---
A scripts/README.txt
A scripts/migrate.py
2 files changed, 241 insertions(+), 0 deletions(-)

Approvals:
  jenkins-bot: Verified
  Jdlrobson: Looks good to me, approved



diff --git a/scripts/README.txt b/scripts/README.txt
new file mode 100644
index 000..04a844b
--- /dev/null
+++ b/scripts/README.txt
@@ -0,0 +1,6 @@
+Porting Minerva code from MobileFrontend to Minerva:
+* Make sure this repository is in your MediaWiki skins directory
+* Make sure MobileFrontend is installed in extensions/MobileFrontend in your 
MediaWiki install
+* Create commits for both MobileFrontend and Minerva to handle the move.
+* Run:
+   > python3 scripts/migrate.python
diff --git a/scripts/migrate.py b/scripts/migrate.py
new file mode 100644
index 000..ca017f8
--- /dev/null
+++ b/scripts/migrate.py
@@ -0,0 +1,235 @@
+mfdir = '../../extensions/MobileFrontend'
+
+import json, shutil, os, subprocess, time
+from collections import OrderedDict
+import sys
+
+DRY_RUN = False
+f = open(mfdir +'/extension.json', 'r')
+mfExtensionData = json.load(f, object_pairs_hook=OrderedDict)
+f.close()
+f = open('skin.json', 'r')
+minervaSkinData = json.load(f, object_pairs_hook=OrderedDict)
+f.close()
+
+messages = [ 'mobile-frontend-placeholder', 'skinname-minerva',
+  'mobile-frontend-talk-back-to-userpage',
+  'mobile-frontend-talk-back-to-projectpage',
+  'mobile-frontend-talk-back-to-filepage',
+  'mobile-frontend-talk-back-to-page',
+  'mobile-frontend-editor-edit',
+  'mobile-frontend-user-newmessages',
+  'mobile-frontend-main-menu-contributions',
+  'mobile-frontend-main-menu-watchlist',
+  'mobile-frontend-main-menu-settings',
+  'mobile-frontend-home-button',
+  'mobile-frontend-random-button',
+  'mobile-frontend-main-menu-nearby',
+  'mobile-frontend-main-menu-logout',
+  'mobile-frontend-main-menu-login',
+  'mobile-frontend-history',
+  'mobile-frontend-user-page-member-since',
+  'mobile-frontend-main-menu-button-tooltip',
+  'mobile-frontend-language-article-heading',
+  'mobile-frontend-pageaction-edit-tooltip',
+  'mobile-frontend-language-article-heading',
+  'mobile-frontend-user-page-talk',
+  'mobile-frontend-user-page-contributions',
+  'mobile-frontend-user-page-uploads'
+]
+
+def reset():
+# Do cleanup in preparation for patchsets it will make.
+subprocess.call(["git clean -fd"], shell=True)
+subprocess.call(["git stash && git clean -fd"], shell=True, cwd=mfdir)
+if not DRY_RUN:
+subprocess.call(["rm -rf includes && rm -rf resources && rm -rf 
minerva.less && rm -rf i18n && rm -rf skinStyles && rm -rf tests/qunit && rm 
-rf tests/phpunit"], shell=True)
+subprocess.call(["mkdir includes && mkdir includes/skins && mkdir 
includes/models && mkdir resources && mkdir minerva.less && mkdir i18n && mkdir 
skinStyles && mkdir tests/qunit && mkdir 
tests/qunit/skins.minerva.notifications.badge && mkdir tests/phpunit/ && mkdir 
tests/phpunit/skins"], shell=True)
+time.sleep(1)
+
+def saveJSON(path, data, sort_keys = False):
+if not DRY_RUN:
+with open(path, 'w') as outfile:
+json.dump(data, outfile, indent = "\t", ensure_ascii=False, 
separators=(',', ': '), sort_keys=sort_keys)
+
+def clean( keys_to_remove, data_key ):
+# Remove the keys we added from MobileFrontend extension.json
+for key in keys_to_remove:
+try:
+del mfExtensionData[data_key][key]
+except KeyError:
+pass
+
+def steal_files_in_directory(dir):
+if not DRY_RUN:
+# steal templates etc from MobileFrontend
+for root, dirs, files in os.walk(mfdir + '/' + dir):
+for file in files:
+steal(root + '/' + file)
+
+def steal( path ):
+dest = path.replace(mfdir + '/', '' )
+origin = mfdir + '/' + path
+print('\tstealing %s from %s'%(dest, origin))
+try:
+if not DRY_RUN:
+shutil.move( origin, dest )
+except ( FileNotFoundError, shutil.Error ) as e:
+print (e)
+# probably done in initial steal steps
+pass
+
+def copy( path ):
+if not DRY_RUN:
+print('copying %s'%path)
+try:
+# ../ because we are in scripts folder
+shutil.copy( mfdir + '/' + path, path )
+except ( FileNotFoundError, shutil.Error ) as e:
+print (e)
+# probably done in initial steal steps
+pass
+
+def isOwnedByMinerva(key, value=""):
+return key.startswith("Minerva") or key.endswith("Minerva") or 
key.startswith( 'skins.minerva' ) or \
+( type(value) == type('string') and "skins/" in value )
+
+# modulename, ResourceModules
+def migrateResourceModuleSkinStyles():
+mf = {}
+minerva

[MediaWiki-commits] [Gerrit] mediawiki...MinervaNeue[master]: Add migration script

2017-06-01 Thread Jdlrobson (Code Review)
Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/356633 )

Change subject: Add migration script
..

Add migration script

Bug: T166744
Change-Id: I6466a72bc32916a7e3092b24e61961f8d422ed88
---
A scripts/README.txt
A scripts/migrate.py
2 files changed, 200 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/skins/MinervaNeue 
refs/changes/33/356633/1

diff --git a/scripts/README.txt b/scripts/README.txt
new file mode 100644
index 000..04a844b
--- /dev/null
+++ b/scripts/README.txt
@@ -0,0 +1,6 @@
+Porting Minerva code from MobileFrontend to Minerva:
+* Make sure this repository is in your MediaWiki skins directory
+* Make sure MobileFrontend is installed in extensions/MobileFrontend in your 
MediaWiki install
+* Create commits for both MobileFrontend and Minerva to handle the move.
+* Run:
+   > python3 scripts/migrate.python
diff --git a/scripts/migrate.py b/scripts/migrate.py
new file mode 100644
index 000..7de5f61
--- /dev/null
+++ b/scripts/migrate.py
@@ -0,0 +1,194 @@
+mfdir = '../../extensions/MobileFrontend'
+
+import json, shutil, os, subprocess, time
+from collections import OrderedDict
+
+messages = [ 'mobile-frontend-placeholder', 'skinname-minerva',
+  'mobile-frontend-talk-back-to-userpage',
+  'mobile-frontend-talk-back-to-projectpage',
+  'mobile-frontend-talk-back-to-filepage',
+  'mobile-frontend-talk-back-to-page',
+  'mobile-frontend-editor-edit',
+  'mobile-frontend-user-newmessages',
+  'mobile-frontend-main-menu-contributions',
+  'mobile-frontend-main-menu-watchlist',
+  'mobile-frontend-main-menu-settings',
+  'mobile-frontend-home-button',
+  'mobile-frontend-random-button',
+  'mobile-frontend-main-menu-nearby',
+  'mobile-frontend-main-menu-logout',
+  'mobile-frontend-main-menu-login',
+  'mobile-frontend-history',
+  'mobile-frontend-user-page-member-since',
+  'mobile-frontend-main-menu-button-tooltip',
+  'mobile-frontend-language-article-heading',
+  'mobile-frontend-pageaction-edit-tooltip',
+  'mobile-frontend-language-article-heading',
+  'mobile-frontend-user-page-talk',
+  'mobile-frontend-user-page-contributions',
+  'mobile-frontend-user-page-uploads'
+]
+
+def reset():
+# Do cleanup in preparation for patchsets it will make.
+subprocess.call(["git clean -fd"], shell=True)
+subprocess.call(["git stash && git clean -fd"], shell=True, cwd=mfdir)
+subprocess.call(["rm -rf includes && rm -rf resources && rm -rf 
minerva.less && rm -rf i18n && rm -rf skinStyles && rm -rf tests"], shell=True)
+subprocess.call(["mkdir includes && mkdir includes/skins && mkdir 
includes/models && mkdir resources && mkdir minerva.less && mkdir i18n && mkdir 
skinStyles && mkdir tests && mkdir tests/browser && mkdir 
tests/browser/features && mkdir tests/browser/features/support && mkdir 
tests/browser/features/support/pages && mkdir 
tests/browser/features/step_definitions"], shell=True)
+time.sleep(1)
+
+def saveJSON(path, data, sort_keys = False):
+with open(path, 'w') as outfile:
+json.dump(data, outfile, indent = "\t", ensure_ascii=False, 
separators=(',', ': '), sort_keys=sort_keys)
+
+def clean( keys_to_remove, data_key ):
+# Remove the keys we added from MobileFrontend extension.json
+for key in keys_to_remove:
+try:
+del mfExtensionData[data_key][key]
+except KeyError:
+pass
+
+def steal_files_in_directory(dir):
+# steal templates etc from MobileFrontend
+for root, dirs, files in os.walk(mfdir + '/' + dir):
+for file in files:
+steal(root + '/' + file)
+
+def steal( path ):
+dest = path.replace(mfdir + '/', '' )
+print('stealing %s from %s'%(dest, path))
+try:
+# ../ because we are in scripts folder
+shutil.move( mfdir + '/' + path, dest )
+except ( FileNotFoundError, shutil.Error ) as e:
+print (e)
+# probably done in initial steal steps
+pass
+
+def copy( path ):
+print('copying %s'%path)
+try:
+# ../ because we are in scripts folder
+shutil.copy( mfdir + '/' + path, path )
+except ( FileNotFoundError, shutil.Error ) as e:
+print (e)
+# probably done in initial steal steps
+pass
+
+def isOwnedByMinerva(key, value):
+return key.startswith("Minerva") or key.startswith( 'skins.minerva' ) or \
+( type(value) == type('string') and "skins/" in value )
+
+def migrateObject(fromObj, toObj, key):
+obj = fromObj[key]
+keys_to_remove = []
+files_to_steal = []
+for subkey in obj:
+val = obj[subkey]
+if isOwnedByMinerva(subkey, val):
+if key == "ResourceModules":
+steal( 'resources/%s'% subkey )
+if "messages" in obj[subkey]:
+for msg in obj[subkey]["messages"]:
+messages.append(msg)
+elif key ==