|
@@ 374-394 (lines=21) @@
|
| 371 |
|
return socket.gethostname(), getpass.getuser() # pylint: disable=no-member |
| 372 |
|
|
| 373 |
|
|
| 374 |
|
def get_current(root): |
| 375 |
|
"""Get the current user based on this computer's information. |
| 376 |
|
|
| 377 |
|
@param root: path to root of sharing directory |
| 378 |
|
|
| 379 |
|
@return: current User |
| 380 |
|
""" |
| 381 |
|
info = get_info() |
| 382 |
|
logging.debug("looking for {} in {}...".format(info, root)) |
| 383 |
|
for directory in os.listdir(root): |
| 384 |
|
path = os.path.join(root, directory) |
| 385 |
|
try: |
| 386 |
|
user = User(path) |
| 387 |
|
except ValueError as err: |
| 388 |
|
logging.debug("invalid user: {}".format(err)) |
| 389 |
|
else: |
| 390 |
|
if info in user.info: |
| 391 |
|
logging.info("found user: {}".format(user)) |
| 392 |
|
return user |
| 393 |
|
|
| 394 |
|
raise EnvironmentError("{} not found in {}".format(info, root)) |
| 395 |
|
|
|
@@ 239-252 (lines=14) @@
|
| 236 |
|
for friend in self._iter_friends(): |
| 237 |
|
yield friend |
| 238 |
|
|
| 239 |
|
def _iter_friends(self, clean=False): |
| 240 |
|
"""Iterate through the user's friends with optional cleanup.""" |
| 241 |
|
for directory in os.listdir(self.root): |
| 242 |
|
path = os.path.join(self.root, directory) |
| 243 |
|
try: |
| 244 |
|
user = User(path) |
| 245 |
|
except ValueError as err: |
| 246 |
|
logging.debug("invalid user: {}".format(err)) |
| 247 |
|
if clean and os.path.isdir(path): |
| 248 |
|
logging.warning("deleting invalid user: {}".format(path)) |
| 249 |
|
self._delete(path) |
| 250 |
|
else: |
| 251 |
|
if user.name != self.name: |
| 252 |
|
yield user |
| 253 |
|
|
| 254 |
|
@property |
| 255 |
|
def incoming(self): |