Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit 3395a08

Browse files
committed
[PEP8] Utility Functions
1 parent 1c14b2c commit 3395a08

1 file changed

Lines changed: 46 additions & 16 deletions

File tree

utility_functions.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
import collections
22
import logging
33
import os
4+
import errno
45

56
from construct import Container
67
from twisted.python.filepath import FilePath
78

89
import packets
9-
import errno
1010

1111

1212
path = FilePath(os.path.dirname(os.path.abspath(__file__)))
13-
logger = logging.getLogger("starrypy.utility_functions")
13+
logger = logging.getLogger('starrypy.utility_functions')
1414

1515

1616
def give_item_to_player(player_protocol, item, count=1):
17-
logger.debug("Attempting to give item %s (count: %s) to %s", item, count, player_protocol.player.name)
17+
logger.debug(
18+
'Attempting to give item %s (count: %s) to %s',
19+
item,
20+
count,
21+
player_protocol.player.name
22+
)
1823
item_count = int(count)
1924
hard_max = 90000
2025
if item_count > hard_max:
21-
logger.warn("Attempted to give more items than the max allowed (%s). Capping amount.", hard_max)
26+
logger.warn(
27+
'Attempted to give more items than the max allowed (%s). '
28+
'Capping amount.',
29+
hard_max
30+
)
2231
item_count = hard_max
2332
maximum = 1000
2433
given = 0
2534
while item_count > 0:
2635
x = item_count
2736
if x > maximum:
2837
x = maximum
29-
item_packet = build_packet(packets.Packets.GIVE_ITEM, packets.give_item_write(item, x + 1))
38+
item_packet = build_packet(
39+
packets.Packets.GIVE_ITEM, packets.give_item_write(item, x + 1)
40+
)
3041
player_protocol.transport.write(item_packet)
3142
item_count -= x
3243
given += x
@@ -53,7 +64,12 @@ def build_packet(packet_type, data):
5364
"""
5465
length = len(data)
5566
return packets.packet().build(
56-
Container(id=packet_type, payload_size=length, data=data))
67+
Container(
68+
id=packet_type,
69+
payload_size=length,
70+
data=data
71+
)
72+
)
5773

5874

5975
class Planet(object):
@@ -65,16 +81,28 @@ def __init__(self, x, y, z, planet, satellite):
6581
self.satellite = satellite
6682

6783
def __str__(self):
68-
return "%d:%d:%d:%d:%d" % (self.x, self.y, self.z, self.planet, self.satellite)
84+
return '{}:{}:{}:{}:{}'.format(
85+
self.x, self.y, self.z, self.planet, self.satellite
86+
)
6987

7088

7189
def move_ship_to_coords(protocol, x, y, z, planet, satellite):
72-
logger.info("Moving %s's ship to coordinates: %s", protocol.player.name,
73-
":".join((str(x), str(y), str(z), str(planet), str(satellite))))
90+
logger.info(
91+
'Moving %s\'s ship to coordinates: %s',
92+
protocol.player.name,
93+
':'.join(map(str, (x, y, z, planet, satellite)))
94+
)
7495
x, y, z, planet, satellite = map(int, (x, y, z, planet, satellite))
75-
warp_packet = build_packet(packets.Packets.FLY_SHIP,
76-
packets.fly_ship_write(x=x, y=y, z=z, planet=planet,
77-
satellite=satellite))
96+
warp_packet = build_packet(
97+
packets.Packets.FLY_SHIP,
98+
packets.fly_ship_write(
99+
x=x,
100+
y=y,
101+
z=z,
102+
planet=planet,
103+
satellite=satellite
104+
)
105+
)
78106
protocol.client_protocol.transport.write(warp_packet)
79107

80108

@@ -88,13 +116,15 @@ def extract_name(l):
88116
if s[-1] == terminator:
89117
name.append(s[:-1])
90118
if idx + 2 != len(l):
91-
return " ".join(name), l[idx + 2:]
119+
return ' '.join(name), l[idx + 2:]
92120
else:
93-
return " ".join(name), None
121+
return ' '.join(name), None
94122
else:
95123
name.append(s)
96-
raise ValueError("Final terminator character of <%s> not found" %
97-
terminator)
124+
raise ValueError(
125+
'Final terminator character of <%s> not found'.format(terminator)
126+
)
127+
98128

99129
def verify_path(path):
100130
"""

0 commit comments

Comments
 (0)