pythonanywhere-core 0.2.0__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,10 @@
1
+ import os
1
2
  import getpass
3
+ from snakesay import snakesay
4
+ from textwrap import dedent
2
5
 
3
6
  from pythonanywhere_core.base import call_api, get_api_endpoint
4
- from pythonanywhere_core.exceptions import PythonAnywhereApiException
5
-
7
+ from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException
6
8
 
7
9
 
8
10
  class Website:
@@ -27,13 +29,44 @@ class Website:
27
29
  self.websites_base_url = get_api_endpoint(username=getpass.getuser(), flavor="websites")
28
30
  self.domains_base_url = get_api_endpoint(username=getpass.getuser(), flavor="domains")
29
31
 
30
- def create(self, domain_name: str, command: str) -> dict:
32
+ def sanity_check(self, domain_name: str, nuke: bool = False) -> None:
33
+ """Check that we have a token, and that we don't already have a webapp for this domain"""
34
+ print(snakesay("Running API sanity checks"))
35
+ token = os.environ.get("API_TOKEN")
36
+ if not token:
37
+ raise SanityException(
38
+ dedent(
39
+ """
40
+ Could not find your API token.
41
+ You may need to create it on the Accounts page?
42
+ You will also need to close this console and open a new one once you've done that.
43
+ """
44
+ )
45
+ )
46
+
47
+ if nuke:
48
+ return
49
+
50
+ response = call_api(
51
+ f"{self.websites_base_url}{domain_name}/",
52
+ "get"
53
+ )
54
+
55
+ if response.status_code == 200:
56
+ raise SanityException(
57
+ f"You already have a webapp for {domain_name}.\n\nUse the --nuke option if you want to replace it."
58
+ )
59
+
60
+
61
+ def create(self, domain_name: str, command: str, nuke: bool = False) -> dict:
31
62
  """Creates new website with ``domain_name`` and ``command``.
32
63
 
33
64
  :param domain_name: domain name for new website
34
65
  :param command: command for new website
35
66
  :returns: dictionary with created website info"""
36
67
 
68
+ self.sanity_check(domain_name, nuke)
69
+
37
70
  response = call_api(
38
71
  self.websites_base_url,
39
72
  "post",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pythonanywhere-core
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: API wrapper for programmatic management of PythonAnywhere services.
5
5
  License: MIT
6
6
  Keywords: pythonanywhere,api,cloud,web hosting
@@ -5,8 +5,8 @@ pythonanywhere_core/files.py,sha256=qIfbcg472TPeOejpif_i64PtWP_qROlxoz5JbePzX8Q,
5
5
  pythonanywhere_core/schedule.py,sha256=giSO-Gssshkto9de2hSA3VeNKotXYu-lBG-iyqDolIw,3904
6
6
  pythonanywhere_core/students.py,sha256=PeBLUP7AOCRwCDiaH71wURwFx3H3PLQW91f5AjOPQmU,1778
7
7
  pythonanywhere_core/webapp.py,sha256=Oa4DTgFY3iMPsW_PqWGFb6WkMbCQz35q8VuK_-sKBKQ,8969
8
- pythonanywhere_core/website.py,sha256=-UeHDimqaYSsqneFPYM-R3tr020588LrUyCyVKRXonc,3979
9
- pythonanywhere_core-0.2.0.dist-info/LICENSE,sha256=zOJT_E5Fv8crFEKS5ulv0btbjnUiIkdsEBPEBmLHRlQ,1080
10
- pythonanywhere_core-0.2.0.dist-info/METADATA,sha256=4IScPSvVd0NAfYqOwtVKXIceXXEIhe1Ojjubb2DsW94,1529
11
- pythonanywhere_core-0.2.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
- pythonanywhere_core-0.2.0.dist-info/RECORD,,
8
+ pythonanywhere_core/website.py,sha256=II4BZy47DP30P6eVh76iJSUd12HcSBfG0AFqiZ5HYME,5124
9
+ pythonanywhere_core-0.2.2.dist-info/LICENSE,sha256=zOJT_E5Fv8crFEKS5ulv0btbjnUiIkdsEBPEBmLHRlQ,1080
10
+ pythonanywhere_core-0.2.2.dist-info/METADATA,sha256=r0wiK6C4dcApri8TygyHyT2_-RkD-F5J8e1678ii9ps,1529
11
+ pythonanywhere_core-0.2.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
12
+ pythonanywhere_core-0.2.2.dist-info/RECORD,,