{"action":"created","comment":{"url":"https://api.github.com/repos/optiflows/pijon/pulls/comments/53750886","id":53750886,"diff_hunk":"@@ -1,2 +1,82 @@\n+import importlib\n+import json\n+import logging\n+import os\n+import re\n+import sys\n+\n+\n+log = logging.getLogger(__name__)\n+\n+\n class Pijon():\n-    pass\n+\n+    def __init__(self, migration_folder, files_format='migration_\\d+_.*'):\n+        sys.path.append(migration_folder)\n+        self.folder = migration_folder\n+        self.files_format = files_format\n+        self.migrations = self.list_migrations()\n+\n+    @classmethod\n+    def list(cls, migrations_folder='./pijon', file_format='migration_\\d+_.*'):\n+        return Pijon(migrations_folder).migrations\n+\n+    def list_migrations(self):\n+        files = os.listdir(self.folder)\n+        regex = re.compile(\"({})\\.py$\".format(self.files_format))\n+        migrations = [\n+            regex.findall(file)[0]\n+            for file in files\n+            if regex.findall(file)\n+        ]\n+        log.debug(\"Migrations steps found {}\".format(migrations))\n+        return migrations\n+\n+    def migrate_step(self, step, data):\n+        \"\"\"\n+        Perform a migration step\n+        \"\"\"\n+        log.debug(\"Migrating step {}\".format(step))\n+        folder = re.findall('[^\\/]+$', self.folder)[0]\n+        module = \"{folder}.{step}\".format(folder=folder, step=step)\n+        importlib.import_module(module)\n+        return sys.modules[module].migrate(data)\n+\n+    def _migrate(self, input_data):\n+        \"\"\"\n+        perform all migrations registered\n+        \"\"\"\n+        data = input_data\n+        for step in self.migrations:\n+            data = self.migrate_step(step, data)\n+        return data\n+\n+    @classmethod\n+    def migrate(cls, in_data, direct_input=False, direct_output=False, output_filename=None,\n+                migrations_folder='./pijon', file_format='migration_\\d+_.*'):","path":"pijon/pijon.py","position":57,"original_position":57,"commit_id":"da5895870039f6a0c6d2af7aa8c913cb260a98de","original_commit_id":"da5895870039f6a0c6d2af7aa8c913cb260a98de","user":{"login":"gdraynz","id":5525902,"avatar_url":"https://avatars.githubusercontent.com/u/5525902?v=3","gravatar_id":"","url":"https://api.github.com/users/gdraynz","html_url":"https://github.com/gdraynz","followers_url":"https://api.github.com/users/gdraynz/followers","following_url":"https://api.github.com/users/gdraynz/following{/other_user}","gists_url":"https://api.github.com/users/gdraynz/gists{/gist_id}","starred_url":"https://api.github.com/users/gdraynz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gdraynz/subscriptions","organizations_url":"https://api.github.com/users/gdraynz/orgs","repos_url":"https://api.github.com/users/gdraynz/repos","events_url":"https://api.github.com/users/gdraynz/events{/privacy}","received_events_url":"https://api.github.com/users/gdraynz/received_events","type":"User","site_admin":false},"body":"Doing `isinstance` check on data to migrate could also be more friendly, automatically resolve the data received and apply the proper migrations if its a dictionary, a filename, a file object...","created_at":"2016-02-23T08:48:56Z","updated_at":"2016-02-23T08:48:56Z","html_url":"https://github.com/optiflows/pijon/pull/1#discussion_r53750886","pull_request_url":"https://api.github.com/repos/optiflows/pijon/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/optiflows/pijon/pulls/comments/53750886"},"html":{"href":"https://github.com/optiflows/pijon/pull/1#discussion_r53750886"},"pull_request":{"href":"https://api.github.com/repos/optiflows/pijon/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/optiflows/pijon/pulls/1","id":59978280,"html_url":"https://github.com/optiflows/pijon/pull/1","diff_url":"https://github.com/optiflows/pijon/pull/1.diff","patch_url":"https://github.com/optiflows/pijon/pull/1.patch","issue_url":"https://api.github.com/repos/optiflows/pijon/issues/1","number":1,"state":"open","locked":false,"title":"Lerignoux/pij 1/pijon json migration","user":{"login":"lerignoux","id":2316399,"avatar_url":"https://avatars.githubusercontent.com/u/2316399?v=3","gravatar_id":"","url":"https://api.github.com/users/lerignoux","html_url":"https://github.com/lerignoux","followers_url":"https://api.github.com/users/lerignoux/followers","following_url":"https://api.github.com/users/lerignoux/following{/other_user}","gists_url":"https://api.github.com/users/lerignoux/gists{/gist_id}","starred_url":"https://api.github.com/users/lerignoux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lerignoux/subscriptions","organizations_url":"https://api.github.com/users/lerignoux/orgs","repos_url":"https://api.github.com/users/lerignoux/repos","events_url":"https://api.github.com/users/lerignoux/events{/privacy}","received_events_url":"https://api.github.com/users/lerignoux/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-19T17:11:46Z","updated_at":"2016-02-23T08:48:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"926f044e25b189e8c600adb5104981434d07eaa6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/optiflows/pijon/pulls/1/commits","review_comments_url":"https://api.github.com/repos/optiflows/pijon/pulls/1/comments","review_comment_url":"https://api.github.com/repos/optiflows/pijon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/optiflows/pijon/issues/1/comments","statuses_url":"https://api.github.com/repos/optiflows/pijon/statuses/da5895870039f6a0c6d2af7aa8c913cb260a98de","head":{"label":"optiflows:lerignoux/PIJ-1/Pijon_json_migration","ref":"lerignoux/PIJ-1/Pijon_json_migration","sha":"da5895870039f6a0c6d2af7aa8c913cb260a98de","user":{"login":"optiflows","id":5174710,"avatar_url":"https://avatars.githubusercontent.com/u/5174710?v=3","gravatar_id":"","url":"https://api.github.com/users/optiflows","html_url":"https://github.com/optiflows","followers_url":"https://api.github.com/users/optiflows/followers","following_url":"https://api.github.com/users/optiflows/following{/other_user}","gists_url":"https://api.github.com/users/optiflows/gists{/gist_id}","starred_url":"https://api.github.com/users/optiflows/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/optiflows/subscriptions","organizations_url":"https://api.github.com/users/optiflows/orgs","repos_url":"https://api.github.com/users/optiflows/repos","events_url":"https://api.github.com/users/optiflows/events{/privacy}","received_events_url":"https://api.github.com/users/optiflows/received_events","type":"Organization","site_admin":false},"repo":{"id":52010400,"name":"pijon","full_name":"optiflows/pijon","owner":{"login":"optiflows","id":5174710,"avatar_url":"https://avatars.githubusercontent.com/u/5174710?v=3","gravatar_id":"","url":"https://api.github.com/users/optiflows","html_url":"https://github.com/optiflows","followers_url":"https://api.github.com/users/optiflows/followers","following_url":"https://api.github.com/users/optiflows/following{/other_user}","gists_url":"https://api.github.com/users/optiflows/gists{/gist_id}","starred_url":"https://api.github.com/users/optiflows/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/optiflows/subscriptions","organizations_url":"https://api.github.com/users/optiflows/orgs","repos_url":"https://api.github.com/users/optiflows/repos","events_url":"https://api.github.com/users/optiflows/events{/privacy}","received_events_url":"https://api.github.com/users/optiflows/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/optiflows/pijon","description":"A json migration tool","fork":false,"url":"https://api.github.com/repos/optiflows/pijon","forks_url":"https://api.github.com/repos/optiflows/pijon/forks","keys_url":"https://api.github.com/repos/optiflows/pijon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/optiflows/pijon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/optiflows/pijon/teams","hooks_url":"https://api.github.com/repos/optiflows/pijon/hooks","issue_events_url":"https://api.github.com/repos/optiflows/pijon/issues/events{/number}","events_url":"https://api.github.com/repos/optiflows/pijon/events","assignees_url":"https://api.github.com/repos/optiflows/pijon/assignees{/user}","branches_url":"https://api.github.com/repos/optiflows/pijon/branches{/branch}","tags_url":"https://api.github.com/repos/optiflows/pijon/tags","blobs_url":"https://api.github.com/repos/optiflows/pijon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/optiflows/pijon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/optiflows/pijon/git/refs{/sha}","trees_url":"https://api.github.com/repos/optiflows/pijon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/optiflows/pijon/statuses/{sha}","languages_url":"https://api.github.com/repos/optiflows/pijon/languages","stargazers_url":"https://api.github.com/repos/optiflows/pijon/stargazers","contributors_url":"https://api.github.com/repos/optiflows/pijon/contributors","subscribers_url":"https://api.github.com/repos/optiflows/pijon/subscribers","subscription_url":"https://api.github.com/repos/optiflows/pijon/subscription","commits_url":"https://api.github.com/repos/optiflows/pijon/commits{/sha}","git_commits_url":"https://api.github.com/repos/optiflows/pijon/git/commits{/sha}","comments_url":"https://api.github.com/repos/optiflows/pijon/comments{/number}","issue_comment_url":"https://api.github.com/repos/optiflows/pijon/issues/comments{/number}","contents_url":"https://api.github.com/repos/optiflows/pijon/contents/{+path}","compare_url":"https://api.github.com/repos/optiflows/pijon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/optiflows/pijon/merges","archive_url":"https://api.github.com/repos/optiflows/pijon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/optiflows/pijon/downloads","issues_url":"https://api.github.com/repos/optiflows/pijon/issues{/number}","pulls_url":"https://api.github.com/repos/optiflows/pijon/pulls{/number}","milestones_url":"https://api.github.com/repos/optiflows/pijon/milestones{/number}","notifications_url":"https://api.github.com/repos/optiflows/pijon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/optiflows/pijon/labels{/name}","releases_url":"https://api.github.com/repos/optiflows/pijon/releases{/id}","deployments_url":"https://api.github.com/repos/optiflows/pijon/deployments","created_at":"2016-02-18T13:51:42Z","updated_at":"2016-02-18T14:08:51Z","pushed_at":"2016-02-19T17:11:46Z","git_url":"git://github.com/optiflows/pijon.git","ssh_url":"git@github.com:optiflows/pijon.git","clone_url":"https://github.com/optiflows/pijon.git","svn_url":"https://github.com/optiflows/pijon","homepage":null,"size":11,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"optiflows:master","ref":"master","sha":"dea8b2784b3d7ebe22071f27b4fea9153f4e7b37","user":{"login":"optiflows","id":5174710,"avatar_url":"https://avatars.githubusercontent.com/u/5174710?v=3","gravatar_id":"","url":"https://api.github.com/users/optiflows","html_url":"https://github.com/optiflows","followers_url":"https://api.github.com/users/optiflows/followers","following_url":"https://api.github.com/users/optiflows/following{/other_user}","gists_url":"https://api.github.com/users/optiflows/gists{/gist_id}","starred_url":"https://api.github.com/users/optiflows/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/optiflows/subscriptions","organizations_url":"https://api.github.com/users/optiflows/orgs","repos_url":"https://api.github.com/users/optiflows/repos","events_url":"https://api.github.com/users/optiflows/events{/privacy}","received_events_url":"https://api.github.com/users/optiflows/received_events","type":"Organization","site_admin":false},"repo":{"id":52010400,"name":"pijon","full_name":"optiflows/pijon","owner":{"login":"optiflows","id":5174710,"avatar_url":"https://avatars.githubusercontent.com/u/5174710?v=3","gravatar_id":"","url":"https://api.github.com/users/optiflows","html_url":"https://github.com/optiflows","followers_url":"https://api.github.com/users/optiflows/followers","following_url":"https://api.github.com/users/optiflows/following{/other_user}","gists_url":"https://api.github.com/users/optiflows/gists{/gist_id}","starred_url":"https://api.github.com/users/optiflows/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/optiflows/subscriptions","organizations_url":"https://api.github.com/users/optiflows/orgs","repos_url":"https://api.github.com/users/optiflows/repos","events_url":"https://api.github.com/users/optiflows/events{/privacy}","received_events_url":"https://api.github.com/users/optiflows/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/optiflows/pijon","description":"A json migration tool","fork":false,"url":"https://api.github.com/repos/optiflows/pijon","forks_url":"https://api.github.com/repos/optiflows/pijon/forks","keys_url":"https://api.github.com/repos/optiflows/pijon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/optiflows/pijon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/optiflows/pijon/teams","hooks_url":"https://api.github.com/repos/optiflows/pijon/hooks","issue_events_url":"https://api.github.com/repos/optiflows/pijon/issues/events{/number}","events_url":"https://api.github.com/repos/optiflows/pijon/events","assignees_url":"https://api.github.com/repos/optiflows/pijon/assignees{/user}","branches_url":"https://api.github.com/repos/optiflows/pijon/branches{/branch}","tags_url":"https://api.github.com/repos/optiflows/pijon/tags","blobs_url":"https://api.github.com/repos/optiflows/pijon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/optiflows/pijon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/optiflows/pijon/git/refs{/sha}","trees_url":"https://api.github.com/repos/optiflows/pijon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/optiflows/pijon/statuses/{sha}","languages_url":"https://api.github.com/repos/optiflows/pijon/languages","stargazers_url":"https://api.github.com/repos/optiflows/pijon/stargazers","contributors_url":"https://api.github.com/repos/optiflows/pijon/contributors","subscribers_url":"https://api.github.com/repos/optiflows/pijon/subscribers","subscription_url":"https://api.github.com/repos/optiflows/pijon/subscription","commits_url":"https://api.github.com/repos/optiflows/pijon/commits{/sha}","git_commits_url":"https://api.github.com/repos/optiflows/pijon/git/commits{/sha}","comments_url":"https://api.github.com/repos/optiflows/pijon/comments{/number}","issue_comment_url":"https://api.github.com/repos/optiflows/pijon/issues/comments{/number}","contents_url":"https://api.github.com/repos/optiflows/pijon/contents/{+path}","compare_url":"https://api.github.com/repos/optiflows/pijon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/optiflows/pijon/merges","archive_url":"https://api.github.com/repos/optiflows/pijon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/optiflows/pijon/downloads","issues_url":"https://api.github.com/repos/optiflows/pijon/issues{/number}","pulls_url":"https://api.github.com/repos/optiflows/pijon/pulls{/number}","milestones_url":"https://api.github.com/repos/optiflows/pijon/milestones{/number}","notifications_url":"https://api.github.com/repos/optiflows/pijon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/optiflows/pijon/labels{/name}","releases_url":"https://api.github.com/repos/optiflows/pijon/releases{/id}","deployments_url":"https://api.github.com/repos/optiflows/pijon/deployments","created_at":"2016-02-18T13:51:42Z","updated_at":"2016-02-18T14:08:51Z","pushed_at":"2016-02-19T17:11:46Z","git_url":"git://github.com/optiflows/pijon.git","ssh_url":"git@github.com:optiflows/pijon.git","clone_url":"https://github.com/optiflows/pijon.git","svn_url":"https://github.com/optiflows/pijon","homepage":null,"size":11,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/optiflows/pijon/pulls/1"},"html":{"href":"https://github.com/optiflows/pijon/pull/1"},"issue":{"href":"https://api.github.com/repos/optiflows/pijon/issues/1"},"comments":{"href":"https://api.github.com/repos/optiflows/pijon/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/optiflows/pijon/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/optiflows/pijon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/optiflows/pijon/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/optiflows/pijon/statuses/da5895870039f6a0c6d2af7aa8c913cb260a98de"}}}}