Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

2.0 ~> 2.1 Migrator #921

Closed
wants to merge 27 commits into from

2 participants

@parkr
Collaborator

This migrator:

  1. Creates local copies of imathis/octopress (branch 2.1, or updated master)
  2. Copies the appropriate files and directories from the current directory to the new clone ( HANDLE OVERWRITE CONFLICTS? )
    • .git
    • Plugins which are not present in 2.1
    • source
    • sass
    • .themes/* - .themes/classic
  3. Collect configs and write to new config structure
  4. Removes the local Octopress installation and replaces it with the new clone and modified files
  5. Moves the new clone with the modified files to the location of the old Octopress installation

This should ensure the migration of the current Octopress installation to v2.1.

@parkr parkr referenced this pull request
Closed

Beginnings of the migrator #889

parkr added some commits
@parkr parkr Added old migrator with some tweaks. Needs to be flipped. 10f3a46
@parkr parkr Migrator: reworking the tmp directories. 9020c24
@parkr parkr Migrator: fixed variable name for OCTO_GIT and OCTO_CONFIG_DEST 522f733
@parkr parkr Migrator: cloning the default configs into the current octopress inst…
…allation directly
8c40723
@parkr parkr Migrator: removing extraneous "}" e29c368
@parkr parkr New name for new octopress directory b866218
@parkr parkr Using new new octopress dir name 227c796
@parkr parkr Renaming of the directories for understanding of the direction 03b5e79
@parkr parkr Renaming helper functions in usage 7076cb0
@parkr parkr Ensuring that the 2.1 stuff is being used (REMOVE ONCE 2.1 HAS BEEN M…
…ERGED INTO MASTER)
4e3b561
@parkr parkr Copying .git directory from old to new 29515ac
@parkr parkr Removing unnecessary files and directory in the new _config folder eeb4443
@parkr parkr Moving new to old directory a5647e9
@parkr parkr Added colon to error output f3486d5
@parkr parkr read_yaml helper function a58827c
@parkr parkr No longer necessary to copy over new .themes/classic to old 62d1924
@parkr parkr Reflecting change of migration direction in Rakefile, Gemfile and con…
…fig migration
e71ef2a
@parkr parkr Using read_yaml helper method 69ea9a0
@parkr parkr Fixed syntax error d178a7a
@parkr parkr migrate custom themes 7fd48b9
@parkr parkr migrate plugins comment 7ffb9ed
@parkr parkr Ensuring that the new_octo_dir will not exist by appending date 9ec32e8
@parkr parkr Migrating configs 0809a8e
@parkr parkr The new config layout will be merged into 2.1 23a72ab
@parkr parkr Migrating plugins not in 2.1 d5e43b5
@parkr parkr migrating 'source' and 'sass' 9b59940
@parkr
Collaborator

@imathis This seems to be just about it!

@robdodson

What's the word on this? I've been using Octopress 2.0 for about 2 years now. I'm not sure if I should wait to migrate to 2.1 or 3.0 or ...? Maybe some updates to the Octopress site that just let us know what you guys are thinking would be helpful?

@parkr
Collaborator

@imathis is working on a document for the future of Octopress.

@parkr
Collaborator

I'd recommend sticking with 2.0 for now until we have an official release of release candidate.

@parkr parkr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 5, 2013
  1. @parkr

    Ignoring dev droppings.

    parkr authored
Commits on Jan 6, 2013
  1. @parkr
  2. @parkr
  3. @parkr
  4. @parkr
  5. @parkr
  6. @parkr
  7. @parkr
  8. @parkr
  9. @parkr
  10. @parkr
  11. @parkr
  12. @parkr
  13. @parkr

    Moving new to old directory

    parkr authored
  14. @parkr

    Added colon to error output

    parkr authored
  15. @parkr

    read_yaml helper function

    parkr authored
  16. @parkr
  17. @parkr
  18. @parkr

    Using read_yaml helper method

    parkr authored
  19. @parkr

    Fixed syntax error

    parkr authored
  20. @parkr

    migrate custom themes

    parkr authored
  21. @parkr

    migrate plugins comment

    parkr authored
  22. @parkr
  23. @parkr

    Migrating configs

    parkr authored
  24. @parkr
  25. @parkr

    Migrating plugins not in 2.1

    parkr authored
  26. @parkr

    migrating 'source' and 'sass'

    parkr authored
This page is out of date. Refresh to see the latest.
Showing with 122 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +121 −0 source/downloads/code/migrator.rb
View
1  .gitignore
@@ -13,3 +13,4 @@ source/javascripts/octopress.min.js
source/images/icon-*.png
vendor
node_modules
+*~
View
121 source/downloads/code/migrator.rb
@@ -0,0 +1,121 @@
+#!/usr/bin/env ruby -wKU
+
+raise "Git is required for the migration." if `which git`.empty?
+raise "You must run this script from the root of your Octopress blog directory" unless File.exist? File.join(Dir.pwd, '_config.yml') and \
+ File.exist? File.join(Dir.pwd, 'Rakefile')
+
+require "fileutils"
+require "yaml"
+
+LOCAL_OCTOPRESS_INSTALLATION = Dir.pwd
+
+OCTO_GIT = "https://github.com/imathis/octopress.git"
+NEW_OCTO = File.join(File.dirname(LOCAL_OCTOPRESS_INSTALLATION), ["octopress", Time.now.year, Time.now.month, Time.now.day].join('-'))
+
+def old_octo_dir(*subdirs)
+ File.join(LOCAL_OCTOPRESS_INSTALLATION, *subdirs)
+end
+
+def new_octo_dir(*subdirs)
+ File.join(NEW_OCTO, *subdirs)
+end
+
+def read_yaml(path)
+ YAML.load(File.read(path))
+end
+
+begin
+ # Make local copy of imathis/octopress
+ FileUtils.rm_rf new_octo_dir
+ system "git clone #{OCTO_GIT} #{new_octo_dir}; cd #{new_octo_dir}; git checkout 2.1"
+
+ # Copy .git from old to new
+ FileUtils.rm_rf new_octo_dir('.git')
+ FileUtils.cp_r old_octo_dir('.git'), new_octo_dir
+
+ #
+ # migrate configuration
+ #
+ local_config = read_yaml(old_octo_dir("_config.yml"))
+ rakefile_contents = File.read(old_octo_dir('Rakefile'))
+
+ # grab configs
+ %w(public_dir source_dir blog_index_dir stash_dir posts_dir themes_dir new_post_ext new_page_ext server_port).each do |var|
+ matched = rakefile_contents.match(/#{var}\s*=\s*["']([^"']*)["']/)
+ begin
+ local_configs[var] = matched[1]
+ rescue
+ puts "No value could be found for '#{var}' in the old Rakefile."
+ end
+ end
+
+ # build site configs
+ site_config = {}
+ %w(classic.yml disqus.yml gauges_analytics.yml github_repos_sidebar.yml google_analytics.yml
+ google_plus.yml jekyll.yml share_posts.yml tweets_sidebar.yml).each do |yaml_file|
+ this_yaml = read_yaml(new_octo_dir('_config', 'defaults', yaml_file))
+ this_yaml.each_key do |key|
+ if local_config.has_key?(key) and this_yaml[key] != local_config[key]
+ site_config[key] = local_config[key]
+ end
+ end
+ end
+
+ # build deploy configs
+ deploy_configs = {}
+ deploy_default = rakefile_contents.match(/deploy_default\s*=\s*["']([\w-]*)["']/)[1]
+ deploy_default_file = new_octo_dir('_config', 'defaults', 'deploy', (deploy_default == 'push' ? 'gh_pages.yml' : 'rsync.yml'))
+ deploy_default_configs = read_yaml(deploy_default_file)
+
+ # read in deploy configs from rakefile
+ %w(deploy_dir deploy_branch ssh_user document_root ssh_port deploy_default).each do |var|
+ matched = rakefile_contents.match(/#{var}\s*=\s*["']([^"']*)["']/)
+ begin
+ deploy_configs[var] = matched[1] if deploy_default_configs.has_key?(var) && deploy_default_configs[var] != matched[1]
+ rescue
+ puts "No value could be found for '#{var}' in the old Rakefile."
+ end
+ end
+ deploy_configs["rsync_delete"] = rakefile_contents.match(/rsync_delete\s*=\s*(true|false)/)[1] == "true"
+
+ # write configs
+ File.open(new_octo_dir('_config', 'site.yml'), 'w') do |f|
+ f.write(site_config.to_yaml)
+ end
+ File.open(new_octo_dir('_config', 'deploy.yml'), 'w') do |f|
+ f.write(deploy_configs.to_yaml)
+ end
+
+ # migrate old source to new
+ FileUtils.mv old_octo_dir("source"), new_octo_dir
+
+ # migrate old sass to new
+ FileUtils.mv old_octo_dir("sass"), new_octo_dir
+
+ # migrate custom themes
+ custom_themes = Dir.glob(old_octo_dir('.themes', '*')).delete_if { |theme| theme =~ /\.themes\/classic/ }
+ FileUtils.cp_r custom_themes, new_octo_dir('.themes')
+
+ # migrate Rakefile
+ FileUtils.mv old_octo_dir("Rakefile"), new_octo_dir("Rakefile-old")
+
+ # migrate updated plugins (but leave deprecated ones)
+ octopress_plugins = Dir.glob(new_octo_dir('plugins', '*')).map { |path| path.match(/([\w]*\/[\w]*.rb)$/)[1] }
+ custom_plugins = Dir.glob(old_octo_dir('plugins', '*')).map { |path| path.match(/([\w]*\/[\w]*.rb)$/)[1] } - octopress_plugins
+ FileUtils.cp_r custom_plugins.map { |rel_path| old_octo_dir(rel_path) }, new_octo_dir('plugins')
+
+ # move new to old's location
+ FileUtils.rm_rf old_octo_dir
+ FileUtils.mv new_octo_dir, old_octo_dir
+
+ # cleanup
+ FileUtils.rm_rf new_octo_dir
+
+ puts "Your Octopress site has been successfully upgraded."
+ puts "Happy blogging!"
+
+rescue => e
+ puts "An error occurred: #{e}."
+ exit 1
+end
+
Something went wrong with that request. Please try again.