Exemplo n.º 1
0
def main():
    if len(sys.argv) < 3:
        print('You have to specify the target and source product.')
        sys.exit(1)

    target = sys.argv[1]
    source = sys.argv[2]

    os.chdir('..')
    os.chdir('i18n')

    targetPoFiles = getPoFiles(target)
    sourcePoFiles = getPoFiles(source)

    if targetPoFiles == [] or sourcePoFiles == []:
        print('No po-files were found for one of the given products.')
        sys.exit(3)

    for t in targetPoFiles:
        targetLanguage = getLanguage(target, t)
        for s in sourcePoFiles:
            sourceLanguage = getLanguage(source, s)
            if targetLanguage and sourceLanguage and targetLanguage == sourceLanguage:
                print('%s %s <- %s' % (getLanguage(target, t), t, s))
                os.system(__I18NDUDE + (' admix %s %s > %s-new') % (t, s, t))
                targetpath = os.path.join(os.curdir, t)
                os.remove(targetpath)
                if not os.path.exists(targetpath):
                    shutil.copy(t + '-new', t)
                    os.remove(targetpath + '-new')
Exemplo n.º 2
0
def convertArchive(archiveFile, tokTarFile, langcode=None, encoding=None, 
                   alwaysSplit=False, rawTarFile=None, nbPartitions=1, part=1):
    
    if not langcode:
        langcode = re.search(r'([^/]+)\.tar',archiveFile).group(1) 
    if langcode == "zhe":
        return convertBilingualArchive(archiveFile,tokTarFile,langcode,encoding,
                                       alwaysSplit,rawTarFile,nbPartitions,part)
    
    langcode=utils.getLanguage(langcode).codes[0] if langcode !="pob" else "pb"
    subset = selectSubtitles(archiveFile, langcode, nbPartitions, part)
    
    language = utils.getLanguage(langcode)  
    
    tokTarFile = tarfile.open(tokTarFile, mode='w')
    if rawTarFile:
        rawTarFile = tarfile.open(rawTarFile, mode='w')
            
    for sub in subset.values():             
        try:  
            addSubtitle(sub, tokTarFile, rawTarFile, language, encoding, alwaysSplit)          
        except KeyboardInterrupt:
            break

    tokTarFile.close() 
    if rawTarFile:
        rawTarFile.close() 
Exemplo n.º 3
0
def main():
    if len(sys.argv) < 3:
        print 'You have to specify the target and source product.'
        sys.exit(1)

    target = sys.argv[1]
    source = sys.argv[2]

    os.chdir('..')
    os.chdir('i18n')

    targetPoFiles = getPoFiles(target)
    sourcePoFiles = getPoFiles(source)

    if targetPoFiles == [] or sourcePoFiles == []:
        print 'No po-files were found for one of the given products.'
        sys.exit(3)

    for t in targetPoFiles:
        targetLanguage = getLanguage(target,t)
        for s in sourcePoFiles:
            sourceLanguage = getLanguage(source,s)
            if targetLanguage and sourceLanguage and targetLanguage == sourceLanguage:
                print '%s %s <- %s' % (getLanguage(target, t), t, s)
                os.system(__I18NDUDE + (' admix %s %s > %s-new') % (t, s, t))
                targetpath = os.path.join(os.curdir, t)
                os.remove(targetpath)
                if not os.path.exists(targetpath):
                    shutil.copy(t+'-new', t)
                    os.remove(targetpath+'-new')
Exemplo n.º 4
0
def convertBilingualArchive(archiveFile, tokTarFile, langcode=None, encoding=None, 
                   alwaysSplit=False, rawTarFile=None, nbPartitions=1, part=1):
           

    language = utils.getLanguage("zht") 
    language2 = utils.getLanguage("eng")         
    subset = selectSubtitles(archiveFile, "ze", nbPartitions, part)
    
    incrementPath = lambda p : re.sub("(\w+)(?=\.|$|\-raw\.)", "\g<1>2", p, 1)
    tokTarFile = tarfile.open(tokTarFile, mode='w')
    tokTarFile2 = tarfile.open(incrementPath(tokTarFile.name), mode='w')
    if rawTarFile:
        rawTarFile = tarfile.open(rawTarFile, mode='w')
        rawTarFile2 = tarfile.open(incrementPath(rawTarFile.name), mode='w')
    else:
        rawTarFile2 = None
        
    for sub in subset.values():             
        try:  
            addBilingualSubtitle(sub,tokTarFile,tokTarFile2,rawTarFile,rawTarFile2, 
                                 language, language2, encoding, alwaysSplit)                     
        except KeyboardInterrupt:
            break

    tokTarFile.close() 
    tokTarFile2.close() 
    if rawTarFile:
        rawTarFile.close() 
        rawTarFile2.close() 
Exemplo n.º 5
0
def main():
    os.chdir('..')
    os.chdir('i18n')

    poFilesPlone = getPoFiles('plone')
    if not poFilesPlone:
        print 'No po-files were found for Plone.'
        sys.exit(2)

    poFilesATCT = getPoFiles('atcontenttypes')
    if not poFilesATCT:
        print 'No po-files were found for ATContentTypes.'
        sys.exit(3)

    # format: 'old-domain' : ['msgid1', 'msgid2', ...]
    relocated = {'plone' :
                  ['Changes saved.', 'Please correct the indicated errors.',
                   'Rotate 180', 'help_boolean_criteria_bool',
                   'help_criteria_field_name', 'help_custom_view',
                   'help_custom_view_fields', 'help_date_range_criteria_end',
                   'help_date_range_criteria_start', 'help_exclude_from_nav',
                   'help_limit_number', 'help_news_image', 'help_shortname',
                   'help_path_criteria_value', 'help_string_criteria_value',
                   'help_portal_type_criteria_value', 'help_url',
                   'label_body_text', 'label_boolean_criteria_bool',
                   'label_contact_email', 'label_contact_name',
                   'label_contact_phone', 'label_criteria_field_name',
                   'label_custom_view', 'label_custom_view_fields',
                   'label_date_range_criteria_end', 'label_event_announcement',
                   'label_date_range_criteria_start', 'label_event_attendees',
                   'label_event_end', 'label_event_location',
                   'label_event_start', 'label_event_type',
                   'label_exclude_from_nav', 'label_file', 'label_image',
                   'label_image_caption', 'label_inherit_criteria',
                   'label_item_count', 'label_limit_number', 'label_news_image',
                   'label_path_criteria_recurse', 'label_path_criteria_value',
                   'label_related_items', 'label_short_name',
                   'label_string_criteria_value', 'label_url',
                  ]
                }

    # make sure we only try on languages for which both po files exist
    ploneLanguages = [getLanguage('plone', p) for p in poFilesPlone]
    atctLanguages = [getLanguage('atcontenttypes', p) for p in poFilesATCT]

    languages = [l for l in ploneLanguages if l in atctLanguages and l != 'en']
    changes = {'plone' : False, 'atcontenttypes' : False}

    for lang in languages:
        po_ctl = {}
        try:
            po_ctl['plone'] = catalog.MessageCatalog(filename='plone-%s.po' % lang)
        except IOError, e:
            print >> sys.stderr, 'I/O Error: %s' % e
        try:
            po_ctl['atcontenttypes'] = catalog.MessageCatalog(filename='atcontenttypes-%s.po' % lang)
        except IOError, e:
            print >> sys.stderr, 'I/O Error: %s' % e
Exemplo n.º 6
0
def main():
    os.chdir('..')
    os.chdir('i18n')

    poFilesPlone = getPoFiles('plone')
    if not poFilesPlone:
        print 'No po-files were found for Plone.'
        sys.exit(2)

    poFilesATCT = getPoFiles('atcontenttypes')
    if not poFilesATCT:
        print 'No po-files were found for ATContentTypes.'
        sys.exit(3)

    # format: 'old-domain' : ['msgid1', 'msgid2', ...]
    relocated = {'plone' :
                  ['Changes saved.', 'Please correct the indicated errors.',
                   'Rotate 180', 'help_boolean_criteria_bool',
                   'help_criteria_field_name', 'help_custom_view',
                   'help_custom_view_fields', 'help_date_range_criteria_end',
                   'help_date_range_criteria_start', 'help_exclude_from_nav',
                   'help_limit_number', 'help_news_image', 'help_shortname',
                   'help_path_criteria_value', 'help_string_criteria_value',
                   'help_portal_type_criteria_value', 'help_url',
                   'label_body_text', 'label_boolean_criteria_bool',
                   'label_contact_email', 'label_contact_name',
                   'label_contact_phone', 'label_criteria_field_name',
                   'label_custom_view', 'label_custom_view_fields',
                   'label_date_range_criteria_end', 'label_event_announcement',
                   'label_date_range_criteria_start', 'label_event_attendees',
                   'label_event_end', 'label_event_location',
                   'label_event_start', 'label_event_type',
                   'label_exclude_from_nav', 'label_file', 'label_image',
                   'label_image_caption', 'label_inherit_criteria',
                   'label_item_count', 'label_limit_number', 'label_news_image',
                   'label_path_criteria_recurse', 'label_path_criteria_value',
                   'label_related_items', 'label_short_name',
                   'label_string_criteria_value', 'label_url',
                  ]
                }

    # make sure we only try on languages for which both po files exist
    ploneLanguages = [getLanguage('plone', p) for p in poFilesPlone]
    atctLanguages = [getLanguage('atcontenttypes', p) for p in poFilesATCT]

    languages = [l for l in ploneLanguages if l in atctLanguages and l != 'en']
    changes = {'plone' : False, 'atcontenttypes' : False}

    for lang in languages:
        po_ctl = {}
        try:
            po_ctl['plone'] = catalog.MessageCatalog(filename='plone-%s.po' % lang)
        except IOError, e:
            print >> sys.stderr, 'I/O Error: %s' % e
        try:
            po_ctl['atcontenttypes'] = catalog.MessageCatalog(filename='atcontenttypes-%s.po' % lang)
        except IOError, e:
            print >> sys.stderr, 'I/O Error: %s' % e
Exemplo n.º 7
0
    def convertFromSub(self,gzipfile):
        sys.stderr.write("Converting subitle from sub to srt\n")
        binaryContent= gzipfile.read()
        tempfile = "/tmp/" + str(uuid.uuid4()) + ".sub"
        fd = open(tempfile, 'wb')                   
        fd.write(binaryContent)        
        fd.close()

        tempfile2 = "/tmp/" + str(uuid.uuid4()) + ".srt"
        cmd = "%s %s %s"%(sub2srt,tempfile, tempfile2)
        cmd += " --fps=%f"%self.fps if self.fps else ""

        lang = utils.getLanguage(self.langcode)
        encoding = lang.encodings[1] if len(lang.encodings) > 1 else "utf-8"
        cmd += " --fenc=" + encoding 
        
        subprocess.call(cmd, shell=True)
        if not os.path.exists(tempfile2) or os.stat(tempfile2).st_size < 100:
            raise RuntimeError("Conversion of %s to srt failed"%self.subformat)            
        fd = open(tempfile2, 'rb')
        content = fd.read()
        fd.close()
        os.remove(tempfile)
        os.remove(tempfile2)
        
        return BytesIO(content)
Exemplo n.º 8
0
def convertSubtitle(srtFile=None, xmlFile=None, langcode=None,encoding=None, 
                    alwaysSplit=False, rawOutput=None,meta=None):
    """Converts a .srt subtitle to the XML representation.  
    
    Args:
        srtFile(file path or None): path to the srt file. If set to None,
            reads from standard input
        xmlFile(file path or None): path to the XML output file. If set to
            None, write to the standard output
        langcode(str): 2- or 3-letters code for the subtitle language
        encoding(str): file encoding for the subtitle.
        alwaysSplit(bool): whether to systematically consider each block
            to start a new sentence.
        rawOutput(file path or None): path to the XML file for the (untokenised)
            output. Leave to None to avoid generating this output.
        meta(dict): Meta-data about the subtitle to write at the end of the 
            XML file(s).
            
    """
    if srtFile:
        input = io.open(srtFile,mode='rb') 
    else:
        input = io.TextIOWrapper(sys.stdin.buffer,mode='rb')        
        
    output = io.open(xmlFile,'wb') if xmlFile else sys.stdout.buffer
    rawOutput = io.open(rawOutput,'wb') if rawOutput else None
    
    if langcode=="zhe":
        incrementPath = lambda p : re.sub("(\w+)(?=\.|$)", "\g<1>2", p, 1)
        output2 = io.open(incrementPath(xmlFile),'wb') if xmlFile else sys.stdout.buffer
        rawOutput2 = io.open(incrementPath(rawOutput),'wb') if rawOutput else None
        lang = utils.getLanguage("zht")
        lang2 = utils.getLanguage("eng")      
        converter = BilingualConverter([input], output,output2,rawOutput,rawOutput2,
                                       lang,lang2, meta, encoding, alwaysSplit) 
    else:    
        lang = utils.getLanguage(langcode) if langcode else None
        converter = SubtitleConverter([input],output,rawOutput,lang,
                                  meta, encoding,alwaysSplit)
    converter.doConversion()
    converter.closeOutputs()
Exemplo n.º 9
0
def main():
    if len(sys.argv) < 3:
        print('You have to specify the target and source product.')
        sys.exit(1)

    target = sys.argv[1]
    source = sys.argv[2]

    os.chdir('..')

    sourcePoFiles = getPoFiles(source)

    if sourcePoFiles == []:
        print('No po-files were found for the source product.')
        sys.exit(3)

    for sourcefile in sourcePoFiles:
        sourceLanguage = getLanguage(source,sourcefile)
        if sourceLanguage:
            targetfile = target + '-' + sourceLanguage + '.po'
            targetpath = os.path.join(os.curdir, targetfile)
            if not os.path.exists(targetpath):
                shutil.copy(sourcefile, targetfile)
Exemplo n.º 10
0
def main():
    if len(sys.argv) < 3:
        print 'You have to specify the target and source product.'
        sys.exit(1)

    target = sys.argv[1]
    source = sys.argv[2]

    os.chdir('..')

    sourcePoFiles = getPoFiles(source)

    if sourcePoFiles == []:
        print 'No po-files were found for the source product.'
        sys.exit(3)

    for sourcefile in sourcePoFiles:
        sourceLanguage = getLanguage(source, sourcefile)
        if sourceLanguage:
            targetfile = target + '-' + sourceLanguage + '.po'
            targetpath = os.path.join(os.curdir, targetfile)
            if not os.path.exists(targetpath):
                shutil.copy(sourcefile, targetfile)
Exemplo n.º 11
0
def main():
    os.chdir('..')
    os.chdir('i18n')

    poFilesPlone = getPoFiles('plone')
    if not poFilesPlone:
        print('No po-files were found for Plone.')
        sys.exit(2)

    poFilesATCT = getPoFiles('atcontenttypes')
    if not poFilesATCT:
        print('No po-files were found for ATContentTypes.')
        sys.exit(3)

    # format: 'old-domain' : ['msgid1', 'msgid2', ...]
    relocated = {'plone' :
                  ['Changes saved.', 'Please correct the indicated errors.',
                   'Rotate 180', 'help_boolean_criteria_bool',
                   'help_criteria_field_name', 'help_custom_view',
                   'help_custom_view_fields', 'help_date_range_criteria_end',
                   'help_date_range_criteria_start', 'help_exclude_from_nav',
                   'help_limit_number', 'help_news_image', 'help_shortname',
                   'help_path_criteria_value', 'help_string_criteria_value',
                   'help_portal_type_criteria_value', 'help_url',
                   'label_body_text', 'label_boolean_criteria_bool',
                   'label_contact_email', 'label_contact_name',
                   'label_contact_phone', 'label_criteria_field_name',
                   'label_custom_view', 'label_custom_view_fields',
                   'label_date_range_criteria_end', 'label_event_announcement',
                   'label_date_range_criteria_start', 'label_event_attendees',
                   'label_event_end', 'label_event_location',
                   'label_event_start', 'label_event_type',
                   'label_exclude_from_nav', 'label_file', 'label_image',
                   'label_image_caption', 'label_inherit_criteria',
                   'label_item_count', 'label_limit_number', 'label_news_image',
                   'label_path_criteria_recurse', 'label_path_criteria_value',
                   'label_related_items', 'label_short_name',
                   'label_string_criteria_value', 'label_url',
                  ]
                }

    # make sure we only try on languages for which both po files exist
    ploneLanguages = [getLanguage('plone', p) for p in poFilesPlone]
    atctLanguages = [getLanguage('atcontenttypes', p) for p in poFilesATCT]

    languages = [l for l in ploneLanguages if l in atctLanguages and l != 'en']
    changes = {'plone' : False, 'atcontenttypes' : False}

    for lang in languages:
        po_ctl = {}
        try:
            po_ctl['plone'] = catalog.MessageCatalog(filename='plone-%s.po' % lang)
        except IOError as e:
            print('I/O Error: %s' % e, file=sys.stderr)
        try:
            po_ctl['atcontenttypes'] = catalog.MessageCatalog(filename='atcontenttypes-%s.po' % lang)
        except IOError as e:
            print('I/O Error: %s' % e, file=sys.stderr)

        changes = {'plone' : False, 'atcontenttypes' : False}

        relocate_domain = {'plone' : 'atcontenttypes', 'atcontenttypes' : 'plone'}

        msgids = {}
        msgids['plone'] = list(po_ctl['plone'].keys())
        msgids['atcontenttypes'] = list(po_ctl['atcontenttypes'].keys())

        for old_domain in relocated:
            relocate_msgids = relocated.get(old_domain)
            for relocate_msgid in relocate_msgids:
                if relocate_msgid in msgids[old_domain]:
                    msgstr = po_ctl[old_domain].get(relocate_msgid)
                    # We copy over messages for now
                    # del po_ctl[old_domain][relocate_msgid]
                    changes[old_domain] = True

                    new_domain = relocate_domain.get(old_domain)
                    if relocate_msgid in msgids[new_domain]:
                        old_msgstr = po_ctl[new_domain].get(relocate_msgid)
                        if old_msgstr.msgstr == '' and msgstr:
                            po_ctl[new_domain][relocate_msgid] = msgstr
                            changes[new_domain] = True
                            print('copied msgstr for %s' % relocate_msgid)
                        #else:
                        #    print '%s was already there' % relocate_msgid
                    else:
                        po_ctl[new_domain][relocate_msgid] = msgstr
                        changes[new_domain] = True
                        print('copied %s to %s-%s.po' % (relocate_msgid, new_domain, lang))
                #else:
                #    print '%s was not found anymore' % relocate_msgid

        for domain in changes:
            if changes[domain]:
                file = open('%s-%s.po' % (domain, lang), 'w')
                writer = catalog.POWriter(file, po_ctl[domain])
                writer.write(sort=True)
def upload_video(oauth, secret, options):

    def get_userinfo():
        str_response = oauth.get(url+"/api/v1/users/me").content.decode('utf-8')
        return json.loads(str_response)
        #return json.loads(oauth.get(url+"/api/v1/users/me").content)

    def get_file(path):
        mimetypes.init()
        return (basename(path), open(abspath(path), 'rb'),
                mimetypes.types_map[splitext(path)[1]])

    path = options['file']
    url = str(secret['peertube_url']).rstrip('/')
    user_info = get_userinfo()

    # We need to transform fields into tuple to deal with tags as
    # MultipartEncoder does not support list refer
    # https://github.com/requests/toolbelt/issues/190 and
    # https://github.com/requests/toolbelt/issues/205
    fields = [
        ("name", options['name'] or splitext(basename(options['file']))[0]),
        ("licence", "1"),
        ("description", "KircheNeuenburg.de"),
        ("nsfw", "0"),
        ("videofile", get_file(path))
    ]


        # if no category, set default to 2 (Films)
    fields.append(("category", "2"))

    if options['language']:
        fields.append(("language", str(utils.getLanguage(options['language'], "peertube"))))
    else:
        # if no language, set default to 1 (English)
        fields.append(("language", "en"))


    fields.append(("commentsEnabled", "1"))

    privacy = None

    
    fields.append(("privacy", str(PEERTUBE_PRIVACY["public"])))

    playlist_id = get_default_playlist(user_info)
    fields.append(("channelId", str(playlist_id)))

    multipart_data = MultipartEncoder(fields)

    headers = {
        'Content-Type': multipart_data.content_type
    }
    response = oauth.post(url + "/api/v1/videos/upload",
                          data=multipart_data,
                          headers=headers)
    if response is not None:
        if response.status_code == 200:
            jresponse = response.json()
            jresponse = jresponse['video']
            uuid = jresponse['uuid']
            idvideo = str(jresponse['id'])
            logging.info('Peertube : Video was successfully uploaded.')
            template = '%s/videos/watch/%s'
            logging.info(template % (url, uuid))
            print(template % (url, uuid))
            return template % (url, uuid)
        else:
            logging.error(('Peertube: The upload failed with an unexpected response: '
                           '%s') % response)
            exit(1)