diff --git a/j2o/__main__.py b/j2o/__main__.py index 758d258..d2dd758 100644 --- a/j2o/__main__.py +++ b/j2o/__main__.py @@ -173,19 +173,23 @@ def j2p_main(source_file_jupyter: str, target_file_org = str | None, overwrite: bool = False): "Prepare target file and directory for conversion." # print(source_file_jupyter, target_file_org, overwrite) - source_file_name = os.path.splitext(source_file_jupyter)[0] - image_dir = source_file_name[:3] + '-' + source_file_name[-3:] + '-imgs' + if target_file_org: - s_path = os.path.dirname(target_file_org) - target_images_dir = os.path.normpath(os.path.join(s_path, image_dir)) - else: - target_images_dir = "./" + image_dir + t_path, file_name = os.path.split(target_file_org) # "/var/va.org" - > ('/var', 'va.org') + else: # use source file + t_path, file_name = os.path.split(source_file_jupyter) # "/var/va.org" - > ('/var', 'va.org') + + file_name_short = os.path.splitext(file_name)[0] # # "va.org" -> ('va', '.org') + image_dir = file_name_short[:3] + '-' + file_name_short[-3:] + '-imgs' + target_images_dir = os.path.normpath(os.path.join(t_path, image_dir)) + + if target_file_org is None: + target_file_org = os.path.join(t_path, file_name_short) + '.org' + # - create directory for images: if not os.path.exists(target_images_dir): os.makedirs(target_images_dir) - # - create target_file_org - if target_file_org is None: - target_file_org = source_file_name + '.org' + # - overwrite? if not overwrite: if os.path.isfile(target_file_org): diff --git a/pyproject.toml b/pyproject.toml index a91729a..a1f2019 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "j2o" readme = "README.md" -version = "0.0.5" +version = "0.0.6" authors = [ { name="Anoncheg1" } ] diff --git a/tests/draw-samples.org b/tests/draw-samples.org index 63312a9..0937175 100644 --- a/tests/draw-samples.org +++ b/tests/draw-samples.org @@ -69,7 +69,7 @@ reflectivity[reflectivity == -1e6] = -1 #+end_src ** Погодные события -#+begin_src python :results file graphics :file ./autoimgs/8_0.png :exports both :session s1 +#+begin_src python :results file graphics :file /tmp/a-a-imgs/8_0.png :exports both :session s1 _, axs = plt.subplots(1, len(events), figsize=(20, 2)) for index in range(len(events)): axs[index].imshow(events[index]) @@ -77,10 +77,10 @@ for index in range(len(events)): #+end_src #+RESULTS: -[[file:./autoimgs/8_0.png]]
+[[file:/tmp/a-a-imgs/8_0.png]]
** Интенсивность осадков -#+begin_src python :results file graphics :file ./autoimgs/10_0.png :exports both :session s1 +#+begin_src python :results file graphics :file /tmp/a-a-imgs/10_0.png :exports both :session s1 _, axs = plt.subplots(1, len(intensity), figsize=(20, 2)) for index in range(len(intensity)): axs[index].imshow(intensity[index]) @@ -88,10 +88,10 @@ for index in range(len(intensity)): #+end_src #+RESULTS: -[[file:./autoimgs/10_0.png]]
+[[file:/tmp/a-a-imgs/10_0.png]]
** Радиальная скорость по высотам -#+begin_src python :results file graphics :file ./autoimgs/12_0.png :exports both :session s1 +#+begin_src python :results file graphics :file /tmp/a-a-imgs/12_0.png :exports both :session s1 _, axs = plt.subplots(10, len(radial_velocity), figsize=(20, 20)) for index in range(len(radial_velocity)): for row in range(10): @@ -102,10 +102,10 @@ for index in range(len(radial_velocity)): #+end_src #+RESULTS: -[[file:./autoimgs/12_0.png]]
+[[file:/tmp/a-a-imgs/12_0.png]]
** Отражаемость по высотам -#+begin_src python :results file graphics :file ./autoimgs/14_0.png :exports both :session s1 +#+begin_src python :results file graphics :file /tmp/a-a-imgs/14_0.png :exports both :session s1 _, axs = plt.subplots(10, len(reflectivity), figsize=(20, 20)) for index in range(len(reflectivity)): for row in range(10): @@ -116,5 +116,5 @@ for index in range(len(reflectivity)): #+end_src #+RESULTS: -[[file:./autoimgs/14_0.png]]
+[[file:/tmp/a-a-imgs/14_0.png]]
diff --git a/tests/test_main.py b/tests/test_main.py index a774665..bbce39d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,7 +2,7 @@ import os # -from j2o.__main__ import jupyter2org, DIR_AUTOIMGS, markdown_to_org +from j2o.__main__ import jupyter2org, markdown_to_org jupyter_4_2 = "./tests/draw-samples.ipynb" jupyter_4_2_saved = "./tests/draw-samples.org" @@ -15,24 +15,24 @@ def test_converter(): target_file_org = '/tmp/a.org' - s_path = os.path.dirname(target_file_org) - target_images_dir = os.path.normpath(os.path.join(s_path, DIR_AUTOIMGS)) + t_path, file_name = os.path.split(target_file_org) # "/var/va.org" - > ('/var', 'va.org') + file_name_short = os.path.splitext(file_name)[0] # # "va.org" -> ('va', '.org') + image_dir = '/tmp/' + file_name_short[:3] + '-' + file_name_short[-3:] + '-imgs' # - create directory for images: - if not os.path.exists(target_images_dir): - os.makedirs(target_images_dir) + if not os.path.exists(image_dir): + os.makedirs(image_dir) with open(target_file_org, "w") as f: jupyter2org(f, source_file_jupyter=jupyter_4_2, - target_images_dir=target_images_dir) + target_images_dir=image_dir) # - compare output file with our saved one assert cmp(target_file_org, jupyter_4_2_saved, shallow=False) # - check output files names and sizes in autoimgs directory - onlyfiles = [f for f in os.listdir(target_images_dir) if os.path.isfile(os.path.join(target_images_dir, f))] + onlyfiles = [f for f in os.listdir(image_dir) if os.path.isfile(os.path.join(image_dir, f))] assert len(onlyfiles) == len(jupyter_4_2_images_sizes.keys()) assert all([x in onlyfiles for x in jupyter_4_2_images_sizes.keys()]) for x in onlyfiles: - assert jupyter_4_2_images_sizes[x] == os.stat(os.path.join(target_images_dir,x)).st_size - print("success") + assert jupyter_4_2_images_sizes[x] == os.stat(os.path.join(image_dir,x)).st_size def test_markdown(): @@ -56,10 +56,8 @@ def test_markdown(): 'print("Hello, world!")', '#+end_src', 'Even more text'] - print(markdown_to_org(markdown_lines)) for m, o in zip(markdown_to_org(markdown_lines), org_lines): assert (m == o) - # print(org_lines) if __name__ == "__main__":