Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: appengine/gce-backend/agent/agent.py

Issue 2961653003: Replace os.mkdir with os.makedirs (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2015 The LUCI Authors. All rights reserved. 2 # Copyright 2015 The LUCI Authors. All rights reserved.
3 # Use of this source code is governed under the Apache License, Version 2.0 3 # Use of this source code is governed under the Apache License, Version 2.0
4 # that can be found in the LICENSE file. 4 # that can be found in the LICENSE file.
5 5
6 """Sample Machine Provider agent.""" 6 """Sample Machine Provider agent."""
7 7
8 import argparse 8 import argparse
9 import datetime 9 import datetime
10 import httplib2 10 import httplib2
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 datefmt = datefmt or '%Y-%m-%d %H:%M:%S' 180 datefmt = datefmt or '%Y-%m-%d %H:%M:%S'
181 return time.strftime(datefmt, time.localtime(record.created)) 181 return time.strftime(datefmt, time.localtime(record.created))
182 182
183 class SeverityFilter(logging.Filter): 183 class SeverityFilter(logging.Filter):
184 def filter(self, record): 184 def filter(self, record):
185 record.severity = record.levelname[0] 185 record.severity = record.levelname[0]
186 return True 186 return True
187 187
188 path = os.path.join(self.LOGS_DIR, 'agent.%s.log' % time.time()) 188 path = os.path.join(self.LOGS_DIR, 'agent.%s.log' % time.time())
189 if not os.path.exists(self.LOGS_DIR): 189 if not os.path.exists(self.LOGS_DIR):
190 os.mkdir(self.LOGS_DIR) 190 os.makedirs(self.LOGS_DIR)
191 191
192 logger = logging.getLogger() 192 logger = logging.getLogger()
193 logger.setLevel(logging.DEBUG) 193 logger.setLevel(logging.DEBUG)
194 194
195 log = logging.FileHandler(path) 195 log = logging.FileHandler(path)
196 log.addFilter(SeverityFilter()) 196 log.addFilter(SeverityFilter())
197 log.setFormatter(TimeFormatter('%(asctime)s %(severity)s: %(message)s')) 197 log.setFormatter(TimeFormatter('%(asctime)s %(severity)s: %(message)s'))
198 logger.addHandler(log) 198 logger.addHandler(log)
199 199
200 # Log all uncaught exceptions. 200 # Log all uncaught exceptions.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 """Connects to the given Swarming server. Configures auto-connect on reboot. 279 """Connects to the given Swarming server. Configures auto-connect on reboot.
280 280
281 Args: 281 Args:
282 service_account: Service account to authorize requests to Swarming with. 282 service_account: Service account to authorize requests to Swarming with.
283 swarming_server: URL of the Swarming server to connect to. 283 swarming_server: URL of the Swarming server to connect to.
284 284
285 Returns: 285 Returns:
286 True if successful, False otherwise. 286 True if successful, False otherwise.
287 """ 287 """
288 if not os.path.exists(self.SWARMING_BOT_DIR): 288 if not os.path.exists(self.SWARMING_BOT_DIR):
289 os.mkdir(self.SWARMING_BOT_DIR) 289 os.makedirs(self.SWARMING_BOT_DIR)
290 self.chown(self.user, self.SWARMING_BOT_DIR) 290 self.chown(self.user, self.SWARMING_BOT_DIR)
291 291
292 path = os.path.join(self.SWARMING_BOT_DIR, 'swarming_bot.zip') 292 path = os.path.join(self.SWARMING_BOT_DIR, 'swarming_bot.zip')
293 self.download_swarming_bot_code(service_account, swarming_server, path) 293 self.download_swarming_bot_code(service_account, swarming_server, path)
294 294
295 with open(self.SWARMING_AUTOSTART_TEMPLATE) as f: 295 with open(self.SWARMING_AUTOSTART_TEMPLATE) as f:
296 config = f.read() % { 296 config = f.read() % {
297 'user': self.user, 297 'user': self.user,
298 'zip': path, 298 'zip': path,
299 } 299 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 agent.configure_logging() 446 agent.configure_logging()
447 447
448 if args.install: 448 if args.install:
449 return agent.install() 449 return agent.install()
450 450
451 return agent.poll() 451 return agent.poll()
452 452
453 453
454 if __name__ == '__main__': 454 if __name__ == '__main__':
455 sys.exit(main()) 455 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698