-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into label-unittest
* master: Upgrade p4python to 2020.1 (#179) ENG-3659 Disable tmp cleanup for P4Python connections (#178) Add example workspace cleanup script (#174) Revert "Force in case the client has files open (#176)" (#177) Force in case the client has files open (#176) ENG-3523 Create virtual env once for unique requirements.txt (#167)
- Loading branch information
Showing
8 changed files
with
71 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
pytest==4.5.0; | ||
pylint==2.3.1; | ||
pytest==4.5.0 | ||
pylint==2.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import sys | ||
import logging | ||
|
||
# Recommended reference: https://www.perforce.com/manuals/p4python/p4python.pdf | ||
from P4 import P4 | ||
from datetime import datetime, timedelta | ||
from pprint import pprint | ||
|
||
# delete workspaces where last access time > N days ago | ||
__days_unused__ = 30 | ||
|
||
p4 = P4() | ||
logger = logging.getLogger("p4python") | ||
logger.setLevel(logging.INFO) | ||
handler = logging.StreamHandler(sys.stdout) | ||
formatter = logging.Formatter( | ||
'%(asctime)s %(name)s %(levelname)s: %(message)s', | ||
'%H:%M:%S', | ||
) | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
p4.logger = logger | ||
|
||
p4.connect() | ||
|
||
clients = p4.run_clients() | ||
|
||
# Filter by basic prefix matching. | ||
# May want to include filtering by user and other fields to avoid false positives. | ||
bk_clients = [client for client in clients | ||
if client.get('client', '').startswith('bk-p4-')] | ||
|
||
now = datetime.now() | ||
n_days_ago = (now - timedelta(days=__days_unused__)).timestamp() | ||
unused_clients = [client for client in bk_clients | ||
if int(client.get('Access')) < n_days_ago] | ||
|
||
pprint(unused_clients) | ||
proceed = input("Will delete %d/%d Buildkite clients. Continue? (y/n) " % (len(unused_clients),len(bk_clients))).lower() == 'y' | ||
|
||
if proceed: | ||
for client in unused_clients: | ||
clientname = client.get('client') | ||
try: | ||
p4.run_client('-d', clientname) | ||
except: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
p4python==2018.2.1743033 | ||
p4python==2020.1.1983437 |