Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CodiMD export script
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stgroup
misc
CodiMD export script
Commits
4166a64e
Commit
4166a64e
authored
2 years ago
by
Andreas Domanowski
Browse files
Options
Downloads
Patches
Plain Diff
Move import and export scripts to explicit locations
parent
49102d4b
No related branches found
No related tags found
1 merge request
!1
Hedgedoc import
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
export_md/codimd_export.py
+1
-1
1 addition, 1 deletion
export_md/codimd_export.py
import_md/hedgedoc_import.py
+8
-38
8 additions, 38 deletions
import_md/hedgedoc_import.py
md-import-export.py
+4
-4
4 additions, 4 deletions
md-import-export.py
with
13 additions
and
43 deletions
codimd_export.py
→
export_md/
codimd_export.py
+
1
−
1
View file @
4166a64e
...
...
@@ -59,4 +59,4 @@ def export_from_codimd(instance_url, session_id, export_to):
if
__name__
==
"
__main__
"
:
export_from_codimd
(
"
https://md.inf.tu-dresden.de
"
,
get_sessionid
(
"
connect.sid
"
),
"
codimd-documents
"
)
export_from_codimd
(
"
https://md.inf.tu-dresden.de
"
,
get_sessionid
(
"
CodiMD
"
,
"
connect.sid
"
),
"
codimd-documents
"
)
This diff is collapsed.
Click to expand it.
hedgedoc_import.py
→
import_md/
hedgedoc_import.py
+
8
−
38
View file @
4166a64e
...
...
@@ -41,11 +41,9 @@ def check_archive_exists(archive_file):
def
import_into_hedgedoc
(
instance_url
,
session_id
,
export_folder
,
archive_file
):
print
(
"
Beginning import
"
)
print
(
"
Beginning import
_md
"
)
check_archive_exists
(
archive_file
)
check_accessibility
(
instance_url
,
session_id
)
# let user select browser
browser
=
select_browser
()
# get exported history map
with
open
(
os
.
path
.
join
(
export_folder
,
"
history.json
"
))
as
map_file
:
history_dictionary
=
json
.
load
(
map_file
)
...
...
@@ -59,8 +57,7 @@ def import_into_hedgedoc(instance_url, session_id, export_folder, archive_file):
urls_to_visit
=
[]
iterate_over_archive
(
archive_file
,
instance_url
,
lookup_map
,
session_id
,
urls_to_visit
)
visit_urls_in_browser
(
browser
,
urls_to_visit
)
create_urls_to_visit_file
(
"
hedgedoc_documents_to_visit.url
"
,
urls_to_visit
)
create_urls_to_visit_file
(
"
../hedgedoc_documents_to_visit.url
"
,
urls_to_visit
)
def
iterate_over_archive
(
archive_file
,
instance_url
,
lookup_map
,
session_id
,
urls_to_visit
):
...
...
@@ -104,43 +101,16 @@ def iterate_over_archive(archive_file, instance_url, lookup_map, session_id, url
urls_to_visit
.
append
(
generated_url
)
def
visit_urls_in_browser
(
browser
,
urls_to_visit
):
print
(
"
Your specified browser now needs to visit every newly created document to ensure that it
'
s available in
"
"
your history in HedgeDoc
"
)
subprocess
.
run
([
browser
]
+
urls_to_visit
)
def
create_urls_to_visit_file
(
filename
,
urls_to_visit
):
print
(
f
"
A new file
{
filename
}
will be created. It contains all URLs you need to visit in order to make the
"
f
"
migrated documents appear in your HedgeDoc history.
"
)
print
(
"
This can be automated by running the scripts in the directory
\"
history_scripts
\"
"
)
print
(
"
BE AWARE: Opening a lot of tabs might be quite resource-intensive.
"
)
with
open
(
filename
,
'
w
'
)
as
f
:
for
url
in
urls_to_visit
:
f
.
write
(
url
+
"
\n
"
)
print
(
"
In preparation for the case that this did not work, all URLs are saved in the file
\"
hedgedoc_documents_to_visit.url
\"
"
)
def
select_browser
():
print
(
"
Once you
'
ve uploaded all your documents, they unfortunately do not appear in your HedgeDoc history.
"
)
print
(
"
To make sure that they are available to you, this script automatically visits all your newly uploaded
"
"
documents in your browser.
"
)
print
(
"
Therefore, you need to specify your browser. It needs to be on your path with the same name as
"
"
specified here
"
)
print
(
"
ATTENTION - this needs to be a browser where you have an active and logged-in HedgeDoc session
"
)
supported_browsers
=
[
"
firefox
"
,
"
opera
"
,
"
safari
"
,
"
google-chrome
"
,
"
chromium
"
]
user_input
=
''
input_message
=
"
Specify a browser which holds an active and logged-in HedgeDoc session:
\n
"
for
i
,
browser_suggestion
in
enumerate
(
supported_browsers
):
input_message
+=
f
'
{
i
+
1
}
)
{
browser_suggestion
}
\n
'
# input_message += 'Your choice: '
while
user_input
not
in
map
(
str
,
range
(
1
,
len
(
supported_browsers
)
+
1
)):
user_input
=
input
(
input_message
)
print
(
'
You chose:
'
+
supported_browsers
[
int
(
user_input
)
-
1
])
return
supported_browsers
[
int
(
user_input
)
-
1
]
if
__name__
==
"
__main__
"
:
import_into_hedgedoc
(
"
https://md.inf.tu-dresden.de/notes
"
,
get_sessionid
(
"
connect.hedgeDoc.sid
"
),
"
codimd-documents
"
,
"
archive.zip
"
)
import_into_hedgedoc
(
"
https://md.inf.tu-dresden.de/notes
"
,
get_sessionid
(
"
HedgeDoc
"
,
"
connect.hedgeDoc.sid
"
),
"
codimd-documents
"
,
"
../
archive.zip
"
)
This diff is collapsed.
Click to expand it.
md-import-export.py
+
4
−
4
View file @
4166a64e
from
codimd_export
import
export_from_codimd
from
export_md.codimd_export
import
export_from_codimd
from
import_md.hedgedoc_import
import
import_into_hedgedoc
from
common
import
get_sessionid
from
hedgedoc_import
import
import_into_hedgedoc
if
__name__
==
"
__main__
"
:
export_folder
=
"
codimd-documents
"
export_archive
=
"
archive.zip
"
export_from_codimd
(
"
http
s
://
md.inf.tu-dresden.de/
"
,
get_sessionid
(
"
CodiMD
"
,
"
connect.sid
"
),
export_folder
)
import_into_hedgedoc
(
"
http
s
://
md.inf.tu-dresden.de/notes
"
,
get_sessionid
(
"
HedgeDoc
"
,
"
connect.hedgeDoc.sid
"
),
export_from_codimd
(
"
http://
localhost:3001
"
,
get_sessionid
(
"
CodiMD
"
,
"
connect.sid
"
),
export_folder
)
import_into_hedgedoc
(
"
http://
hedgedoc:3000
"
,
get_sessionid
(
"
HedgeDoc
"
,
"
connect.hedgeDoc.sid
"
),
export_folder
,
export_archive
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment