File size: 2,036 Bytes
1e3b872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# see also https://api.eagle.cool/folder/list
#
import requests
import sys

from . import api_util


def create(
    newfoldername,
    server_url="http://localhost",
    port=41595,
    allow_duplicate_name=True,
    timeout_connect=3,
    timeout_read=10,
):
    """EAGLE API:/api/folder/list

    Method: POST

    Returns:
        list(response dict): return list of response.json()
    """
    API_URL = f"{server_url}:{port}/api/folder/create"

    def _init_data(newfoldername):
        _data = {}
        if newfoldername and newfoldername != "":
            _data.update({"folderName": newfoldername})
        return _data

    data = _init_data(newfoldername)

    # check duplicate if needed
    if not allow_duplicate_name:
        r_post = list()
        _ret = api_util.findFolderByName(r_post, newfoldername)
        if _ret != None or len(_ret) > 0:
            print(
                f'ERROR: create folder with same name is forbidden by option. [eagleapi.folder.create] foldername="{newfoldername}"',
                file=sys.stderr,
            )
            return

    r_post = requests.post(API_URL, json=data, timeout=(timeout_connect, timeout_read))
    return r_post


def rename(
    folderId,
    newName,
    server_url="http://localhost",
    port=41595,
    timeout_connect=3,
    timeout_read=10,
):
    """EAGLE API:/api/folder/rename

    Method: POST

    Returns:
        list(response dict): return list of response.json()
    """
    data = {"folderId": folderId, "newName": newName}
    API_URL = f"{server_url}:{port}/api/folder/rename"
    r_post = requests.post(API_URL, json=data, timeout=(timeout_connect, timeout_read))
    return r_post


def list(server_url="http://localhost", port=41595, timeout_connect=3, timeout_read=10):
    """EAGLE API:/api/folder/list

    Method: GET

    Returns:
        Response: return of requests.post
    """

    API_URL = f"{server_url}:{port}/api/folder/list"

    r_get = requests.get(API_URL, timeout=(timeout_connect, timeout_read))

    return r_get