Created
September 30, 2013 02:27
-
-
Save fcwu/6758705 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
from lp_fish_tools.SomervilleShare import * | |
from lp_fish_tools.util import * | |
from datetime import date | |
import subprocess | |
import os | |
import ConfigParser | |
# Check configuration file | |
Config_file = os.getenv('HOME') + '/.somerville-digest.conf' | |
def create_config_file(): | |
print 'Please answer 2 questions below:' | |
name = raw_input(' 1. What\'s your nickname (single word, ex: Cyrus): ') | |
save_local_copy = raw_input(' 2. After you finished a digest, do you want to save a local copy? (y/n): ') | |
config = ConfigParser.RawConfigParser() | |
config.add_section('Basic') | |
config.set('Basic', 'NAME', name) | |
config.set('Basic', 'SAVE_LOCAL_COPY', save_local_copy) | |
with open(Config_file, 'wb') as configfile: | |
config.write(configfile) | |
print 'The configuration file has been created.\n' | |
if not os.path.exists(Config_file): | |
print 'There is no %s. I will help you create one.\n' % Config_file | |
create_config_file() | |
# Generate bug lists of working platforms | |
config = ConfigParser.RawConfigParser() | |
config.read(Config_file) | |
Name = config.get('Basic', 'NAME') | |
Save_local_copy = config.get('Basic', 'SAVE_LOCAL_COPY').lower()[0] | |
Buglist = {} | |
Platforms = raw_input('''Please enter platform tag(s) you are enabling (seperated by comma). | |
Example: apple, banana | |
Example: cherry | |
Example: <Enter> | |
If there is no any working platform, press enter directly: ''') | |
print 'Digest template is being generated, it might take several secs...' | |
if len(Platforms) > 0: | |
Platforms = Platforms.replace(' ','').split(',') | |
for p in Platforms: | |
output = subprocess.check_output(['sh', '-c', "lp-searchbugtasks --tag %s --status Confirmed --status Triaged --status 'In Progress' project dell | lp-printbugtasks list | awk -F, '{print $3}' | cut -d ' ' -f3,8-" % p]).strip().split('\n') | |
Buglist[p] = output | |
# Create digest file | |
comment = Name + '\n' | |
if len(Platforms) == 0: | |
comment += ' [What you are working]\n' | |
comment += ' * \n' | |
else: | |
for k in Buglist: | |
comment += ' [%s]\n' % k | |
for bug in Buglist[k]: | |
comment += ' * ' + bug + '\n' | |
comment += ' - \n' | |
comment += '\n' | |
#commentSuffix = \ | |
#""" | |
#~~~~~~~~~~~~~~~~~~~~ Enter comment above this line ~~~~~~~~~~~~~~~~~~~~ | |
# | |
#This text below the separator line will not be included if left unedited. | |
#""" | |
comment = userEditString('', comment, 'daily-digest') | |
today = date.today() | |
Digest_name = 'dell-bugdigest-%04d%02d%02d-%s.txt' % (today.year, today.month, today.day, Name.lower()) | |
Digest = open(Digest_name, 'w') | |
Digest.write(comment) | |
Digest.close() | |
# Upload digest file to oem-share | |
class SomervilleShare2(SomervilleShare): | |
def create_file_url(self, fname): | |
#url = os.path.join(base_url, 'pool', fname[:1], fname) | |
url = os.path.join(self.base_url, 'dell-daily-engineering-digest/%04d/%02d/' % (today.year, today.month), fname) | |
self.conn = CollectionStorer(url, validateResourceNames=False) | |
self.conn.connection.addBasicAuthorization(self.user, self.passwd) | |
def upload_file(self, fname): | |
self.create_file_url(fname) | |
tmpfile = open(fname) | |
fish_share.conn.uploadFile(tmpfile, None) | |
print '\n%s is being uploaded to oem-share...\n' % Digest_name | |
fish_share = SomervilleShare2() | |
fish_share.upload_file(Digest_name) | |
# Save a local copy? | |
if Save_local_copy != 'y': | |
subprocess.call(['rm', Digest_name]) | |
print '\nThanks for your hard working today!' | |
print '\(._.)' | |
print ' ))z' | |
print ' / \\' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment